The command line
Novis is one program, nvs. You give it a command, then the options of that command, and usually one
file:
nvs run app.nvsnvs check app.nvsnvs test tests/nvs --help lists every command. nvs <command> --help prints the options of one command, for example
nvs check --help. Every command also takes --config <PATH> and --data <PATH>. --data sets the
data folder, where Novis keeps its own files.
Check a program
Section titled “Check a program”nvs check finds the errors in a program and runs nothing. It also checks every file that the
program loads with require and autoload.
nvs check cart.nvsno errorsnvs check order.nvserror[E0401]: expected `int`, found `string` --> order.nvs:8:17 |8 | $order->total = 'seven'; | ^^^^^^^ this is `string`error: aborting due to 1 errorTo read what a code means and how to fix it, run `nvs agent show <code>`.exit 1When there is no error, nvs check prints no errors and the exit code is 0. Otherwise it prints
every error and the exit code is 1. Each error has a code, a message, and the file, line and column.
An error code is E and four digits, and a warning code starts with W. A code never changes, so you
can search for it. nvs agent show E0401 prints what the error E0401 means and how to fix it.
Nothing runs, so you can use nvs check in an editor, a commit hook or a build server. You can also
give it a folder. It then checks all the .nvs files in that folder as one program.
You can also check one class file that a program loads with autoload. nvs check then searches the
current folder for that program and uses its autoload lines. The class file can be in a smaller project
inside that folder, with its own nvs.toml or package.toml. Then the search uses that project’s
folder. If it finds no such program, the first
“not declared” error has a note with the folder it searched. --root <folder> searches another folder.
The search skips the folders that .gitignore names, except the folder of the class file.
Which files the editor reads has the details.
Diagnostics as JSON
Section titled “Diagnostics as JSON”--json prints the same errors as one JSON document. Use it when a program reads the result, such as
an editor, a script or a build server:
nvs check --json order.nvs{ "diagnostics": [ { "code": "E0401", "help": [], "labels": [ { "end": { "column": 24, "line": 8 }, "file": "order.nvs", "message": "this is `string`", "span": [ 94, 101 ], "start": { "column": 17, "line": 8 }, "style": "primary" } ], "message": "expected `int`, found `string`", "notes": [], "severity": "error", "suggestions": [] } ], "schemaVersion": 1, "todos": []}exit 1Each entry in diagnostics has the code, the message and the severity. labels gives the
file, and the line and column where the error starts and ends. span is the same place as byte
offsets in the file. The exit code is the same as without --json.
Questions about your code
Section titled “Questions about your code”nvs code prints information about the code of your project. It can also change the code, with the
same refactorings as the editor. The project is the folder of the nearest nvs.toml.
These commands only read:
| Command | What it prints |
|---|---|
nvs code show <name> |
where a name is declared, its signature and its doc comment |
nvs code refs <name> |
the declaration and every use of a name |
nvs code impls <name> |
the classes and methods above and below a type or a method |
nvs code outline <file> |
what a file declares |
nvs code types <file> |
the type of each variable declared with var |
nvs code find <text> |
each declaration whose name contains the text |
nvs code calls <method> |
the methods that call a method, and the methods it calls |
nvs code reach <method> |
the routes and the tests that reach a method |
nvs code unused |
each declaration that nothing uses |
These commands change files:
| Command | What it changes |
|---|---|
nvs code rename |
renames a name everywhere, or moves a class to another namespace |
nvs code move |
moves a file or a folder, or a member to another class |
nvs code delete |
deletes a declaration that nothing uses |
nvs code extract |
moves code into a new variable or method, or writes an interface |
nvs code implement |
writes the methods that a class still needs |
nvs code inline |
replaces a variable or a method call with its value |
nvs code signature |
changes the parameters of a method and of every call |
nvs code order |
puts the members of each class in one fixed order |
A name has the full namespace, such as Shop\Cart::addItem. Put each name in single quotes, so the
shell keeps the backslashes:
nvs code refs 'Shop\Cart::addItem'nvs code rename 'Shop\Cart' 'Shop\Billing\Cart' --dry-runnvs code signature 'Shop\Cart::addItem' 'int $count, bool $gift = false'The second line shows what a move of Cart to the namespace Shop\Billing would change. Without
--dry-run, it changes the files. The third line adds the parameter $gift to the method
addItem. The calls do not change, because $gift has a default value.
Each command that changes files takes --dry-run and --json. --dry-run prints each change and
saves nothing. --json prints the changes as one JSON document.
Before it saves, the command checks the new code. If the new code would not compile, it prints the error and changes nothing. If a file changes while the command runs, the command changes nothing and names that file. Run the command again.
When files of the project have errors, nvs code prints a warning that names the first five of them.
A use inside such a file may be missing from the result.
Reference: nvs code has every command and its options.
The compile cache
Section titled “The compile cache”Novis stores compiled code on disk. A program is compiled at its first start. Later starts load the compiled code, so the program starts faster. The output does not change:
nvs --data data run job.nvssent: welcome mailsent: invoice 1042sent: password reset3 jobs donenvs --data data run job.nvssent: welcome mailsent: invoice 1042sent: password reset3 jobs donenvs --data data cache gcremoved 0 entries, freed 0 bytes, skipped 0nvs run and nvs serve both read and write the cache. It has one entry for each source file. The
name of each entry is a hash of the code of the functions in it and of the build. A changed function
gives a new name, so an entry is never out of date. After an edit inside one function, only that function is
compiled again.
The cache is the cache folder in the data folder. The default data folder is .nvsdata, next to
the nvs program. You can set another folder in nvs.toml:
[opcache]file_cache_dir = "/var/cache/novis" # where compiled programs are stored# file_cache = false # compile on every start insteadThe folder and its parent folder must belong to the account that runs nvs. No other ordinary account
may write to them. If a folder that you set fails this check, nvs prints one warning. It then
compiles the program at every start.
Two commands change how much disk space the cache uses. nvs cache gc removes the entries that no
compiled program uses. Then it removes the oldest entries when the cache is larger than
[opcache] file_cache_max_size. The default limit is 256 MB. In the
example above, the cache is smaller, so nothing is removed. nvs cache clear removes every entry:
nvs cache clearThe next run of a removed program compiles it again. Reference: nvs cache
shows the output of both commands, and their --json option.
Check for a new version
Section titled “Check for a new version”nvs update-check checks whether a newer version of Novis is released. It reads the latest release
from GitHub, so it needs a network connection:
nvs update-checknvs update-check --jsonIt prints one line for each step: whether telemetry is on, the version you run and the latest
version. The exit code is always 0, also when the release cannot be read. A script uses --json
and reads two fields. update_available is true when a newer version exists. error says why the
release could not be read, and is null when it was read. The environment variable NVS_UPDATE_URL
replaces the GitHub address.
Telemetry
Section titled “Telemetry”Telemetry counts how often each nvs command runs. It is off until you turn it on:
nvs telemetry onnvs telemetry statusnvs telemetry showWhen telemetry is on, each nvs command adds 1 to a counter for that command. The counters are in a
plain text file in the data folder. They contain no paths, no arguments and no text from your
programs. nvs telemetry status prints whether telemetry is on and where the file is.
nvs telemetry show prints the exact JSON document that an upload sends.
Nothing is uploaded unless the environment variable NVS_TELEMETRY_URL is set. Only
nvs update-check and nvs telemetry upload send an upload. If DO_NOT_TRACK or CI has a value,
nvs records nothing and uploads nothing. Most build servers set CI.
nvs telemetry off stops recording. The counters that are already recorded stay in the file.
nvs telemetry reset deletes them:
nvs --data data telemetry offtelemetry: offThe counters already recorded are still in ~/project/data/telemetry/counters. Run `nvs telemetry reset` to delete them.nvs --data data telemetry resetdeleted ~/project/data/telemetrytelemetry: offRead more in Reference: the nvs command, with every command and its options.
