generated from tweag/project
-
Notifications
You must be signed in to change notification settings - Fork 39
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Topiary Book #750
Closed
Closed
Topiary Book #750
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
book |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
[book] | ||
authors = ["Tweag I/O"] | ||
language = "en" | ||
multilingual = false | ||
src = "src" | ||
title = "Topiary" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
# Summary | ||
[Introduction](./introduction.md) | ||
|
||
- [Installation](./installation/main.md) | ||
- [Package managers](./installation/package-managers.md) | ||
- [Building from source](./installation/building-from-source.md) | ||
- [Using with Nix](./installation/using-with-nix.md) | ||
- [CLI Usage](./cli-usage.md) | ||
- [Library Usage](./library-usage.md) | ||
- [Language Support](./usage/language-support.md) | ||
- [Configuration](./configuration/main.md) | ||
- [Guides](./guides/main.md) | ||
- [Adding a language](./guides/adding-a-language.md) | ||
- [Writing queries](./guides/writing-queries.md) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,256 @@ | ||
# CLI | ||
### Usage | ||
The Topiary CLI uses a number of subcommands to delineate functionality. | ||
These can be listed with `topiary --help`; each subcommand then has its | ||
own, dedicated help text. | ||
|
||
<!-- DO NOT REMOVE THE "usage" COMMENTS --> | ||
<!-- usage:start:ROOT --> | ||
``` | ||
CLI app for Topiary, the universal code formatter. | ||
|
||
Usage: topiary [OPTIONS] <COMMAND> | ||
|
||
Commands: | ||
format Format inputs | ||
visualise Visualise the input's Tree-sitter parse tree | ||
config Print the current configuration | ||
prefetch Prefetch all languages in the configuration | ||
completion Generate shell completion script | ||
help Print this message or the help of the given subcommand(s) | ||
|
||
Options: | ||
-C, --configuration <CONFIGURATION> Configuration file [env: TOPIARY_CONFIG_FILE] | ||
-v, --verbose... Logging verbosity (increased per occurrence) | ||
-h, --help Print help | ||
-V, --version Print version | ||
``` | ||
<!-- usage:end:ROOT --> | ||
|
||
#### Format | ||
|
||
<!-- DO NOT REMOVE THE "usage" COMMENTS --> | ||
<!-- usage:start:format --> | ||
``` | ||
Format inputs | ||
|
||
Usage: topiary format [OPTIONS] <--language <LANGUAGE>|FILES> | ||
|
||
Arguments: | ||
[FILES]... | ||
Input files and directories (omit to read from stdin) | ||
|
||
Language detection and query selection is automatic, mapped from file extensions defined | ||
in the Topiary configuration. | ||
|
||
Options: | ||
-t, --tolerate-parsing-errors | ||
Consume as much as possible in the presence of parsing errors | ||
|
||
-s, --skip-idempotence | ||
Do not check that formatting twice gives the same output | ||
|
||
-l, --language <LANGUAGE> | ||
Topiary language identifier (for formatting stdin) | ||
|
||
-q, --query <QUERY> | ||
Topiary query file override (when formatting stdin) | ||
Comment on lines
+56
to
+57
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would need help, and perhaps other readers too, to find a description of what a query is, and what is a query file override. The |
||
|
||
-C, --configuration <CONFIGURATION> | ||
Configuration file | ||
|
||
[env: TOPIARY_CONFIG_FILE] | ||
|
||
-v, --verbose... | ||
Logging verbosity (increased per occurrence) | ||
|
||
-h, --help | ||
Print help (see a summary with '-h') | ||
``` | ||
<!-- usage:end:format --> | ||
|
||
When formatting inputs from disk, language selection is detected from | ||
the input files' extensions. To format standard input, you must specify | ||
the `--language` and, optionally, `--query` arguments, omitting any | ||
input files. | ||
|
||
Note: `fmt` is a recognised alias of the `format` subcommand. | ||
|
||
#### Visualise | ||
|
||
<!-- DO NOT REMOVE THE "usage" COMMENTS --> | ||
<!-- usage:start:visualise --> | ||
``` | ||
Visualise the input's Tree-sitter parse tree | ||
|
||
Usage: topiary visualise [OPTIONS] <--language <LANGUAGE>|FILE> | ||
|
||
Arguments: | ||
[FILE] | ||
Input file (omit to read from stdin) | ||
|
||
Language detection and query selection is automatic, mapped from file extensions defined | ||
in the Topiary configuration. | ||
|
||
Options: | ||
-f, --format <FORMAT> | ||
Visualisation format | ||
|
||
[default: dot] | ||
|
||
Possible values: | ||
- dot: GraphViz DOT serialisation | ||
- json: JSON serialisation | ||
|
||
-l, --language <LANGUAGE> | ||
Topiary language identifier (for formatting stdin) | ||
|
||
-q, --query <QUERY> | ||
Topiary query file override (when formatting stdin) | ||
|
||
-C, --configuration <CONFIGURATION> | ||
Configuration file | ||
|
||
[env: TOPIARY_CONFIG_FILE] | ||
|
||
-v, --verbose... | ||
Logging verbosity (increased per occurrence) | ||
|
||
-h, --help | ||
Print help (see a summary with '-h') | ||
``` | ||
<!-- usage:end:visualise --> | ||
|
||
When visualising inputs from disk, language selection is detected from | ||
the input file's extension. To visualise standard input, you must | ||
specify the `--language` and, optionally, `--query` arguments, omitting | ||
the input file. The visualisation output is written to standard out. | ||
|
||
Note: `vis`, `visualize` and `view` are recognised aliases of the | ||
`visualise` subcommand. | ||
|
||
#### Configuration | ||
|
||
<!-- DO NOT REMOVE THE "usage" COMMENTS --> | ||
<!-- usage:start:config --> | ||
``` | ||
Print the current configuration | ||
|
||
Usage: topiary config [OPTIONS] | ||
|
||
Options: | ||
-C, --configuration <CONFIGURATION> Configuration file [env: TOPIARY_CONFIG_FILE] | ||
-v, --verbose... Logging verbosity (increased per occurrence) | ||
-h, --help Print help | ||
``` | ||
<!-- usage:end:config --> | ||
|
||
Note: `cfg` is a recognised alias of the `config` subcommand. | ||
|
||
#### Shell Completion | ||
|
||
Shell completion scripts for Topiary can be generated with the | ||
`completion` subcommand. The output of which can be sourced into your | ||
shell session or profile, as required. | ||
|
||
<!-- DO NOT REMOVE THE "usage" COMMENTS --> | ||
<!-- usage:start:completion --> | ||
``` | ||
Generate shell completion script | ||
|
||
Usage: topiary completion [OPTIONS] [SHELL] | ||
|
||
Arguments: | ||
[SHELL] Shell (omit to detect from the environment) [possible values: bash, elvish, fish, | ||
powershell, zsh] | ||
|
||
Options: | ||
-C, --configuration <CONFIGURATION> Configuration file [env: TOPIARY_CONFIG_FILE] | ||
-v, --verbose... Logging verbosity (increased per occurrence) | ||
-h, --help Print help | ||
``` | ||
<!-- usage:end:completion --> | ||
|
||
For example, in Bash: | ||
|
||
```bash | ||
source <(topiary completion) | ||
``` | ||
|
||
#### Prefetching | ||
|
||
Topiary dynamically downloads, builds, and loads the tree-sitter grammars. In | ||
order to ensure offline availability or speed up startup time, the grammars can | ||
be prefetched and compiled. | ||
|
||
<!-- DO NOT REMOVE THE "usage" COMMENTS --> | ||
<!-- usage:start:prefetch--> | ||
``` | ||
Prefetch all languages in the configuration | ||
|
||
Usage: topiary prefetch [OPTIONS] | ||
|
||
Options: | ||
-C, --configuration <CONFIGURATION> Configuration file [env: TOPIARY_CONFIG_FILE] | ||
-v, --verbose... Logging verbosity (increased per occurrence) | ||
-h, --help Print help | ||
``` | ||
<!-- usage:end:prefetch --> | ||
|
||
#### Logging | ||
|
||
By default, the Topiary CLI will only output error messages. You can | ||
increase the logging verbosity with a respective number of | ||
`-v`/`--verbose` flags: | ||
|
||
| Verbosity Flag | Logging Level | | ||
| :------------- | :---------------------- | | ||
| None | Errors | | ||
| `-v` | ...and warnings | | ||
| `-vv` | ...and information | | ||
| `-vvv` | ...and debugging output | | ||
| `-vvvv` | ...and tracing output | | ||
|
||
#### Exit Codes | ||
|
||
The Topiary process will exit with a zero exit code upon successful | ||
formatting. Otherwise, the following exit codes are defined: | ||
|
||
| Reason | Code | | ||
| :--------------------------- | ---: | | ||
| Unspecified error | 1 | | ||
| CLI argument parsing error | 2 | | ||
| I/O error | 3 | | ||
| Topiary query error | 4 | | ||
| Source parsing error | 5 | | ||
| Language detection error | 6 | | ||
| Idempotency error | 7 | | ||
| Unspecified formatting error | 8 | | ||
| Multiple errors | 9 | | ||
|
||
When given multiple inputs, Topiary will do its best to process them | ||
all, even in the presence of errors. Should _any_ errors occur, Topiary | ||
will return a non-zero exit code. For more details on the nature of | ||
these errors, run Topiary at the `warn` logging level (with `-v`). | ||
|
||
#### Example | ||
|
||
Once built, the program can be run like this: | ||
|
||
```bash | ||
echo '{"foo":"bar"}' | topiary fmt --language json | ||
``` | ||
|
||
`topiary` can also be built and run from source via either Cargo or Nix, | ||
if you have those installed: | ||
|
||
```bash | ||
echo '{"foo":"bar"}' | cargo run -- fmt --language json | ||
echo '{"foo":"bar"}' | nix run . -- fmt --language json | ||
``` | ||
|
||
It will output the following formatted code: | ||
|
||
```json | ||
{ "foo": "bar" } | ||
``` |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm wondering whether the book or the help message should indicate how to learn the list of valid language identifiers.