diff --git a/CHANGELOG.md b/CHANGELOG.md index cbf49b4f..ae7e7442 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -95,7 +95,7 @@ After (use IO redirection): ``` topiary [--skip-idempotence] \ [--tolerate-parsing-errors] \ - (--langauge LANGUAGE | --query QUERY) \ + (--langauge LANGUAGE [--query QUERY]) \ < INPUT_FILE \ > OUTPUT_FILE ``` @@ -106,7 +106,7 @@ Before: ``` topariy [--skip-idempotence] \ [--tolerate-parsing-errors] \ - (--langauge LANGUAGE | --query QUERY) \ + (--langauge LANGUAGE [--query QUERY]) \ (--input-files - | < INPUT_FILE) \ [--output-file -] ``` @@ -115,7 +115,7 @@ After (use IO redirection): ``` topiary [--skip-idempotence] \ [--tolerate-parsing-errors] \ - (--langauge LANGUAGE | --query QUERY) \ + (--langauge LANGUAGE [--query QUERY]) \ < INPUT_FILE ``` @@ -142,7 +142,7 @@ topiary vis [--format FORMAT] \ Before: ``` topiary --visualise[=FORMAT] \ - (--langauge LANGUAGE | --query QUERY) \ + (--langauge LANGUAGE [--query QUERY]) \ < INPUT_FILE \ [--output-file OUTPUT_FILE | > OUTPUT_FILE] ``` @@ -150,7 +150,7 @@ topiary --visualise[=FORMAT] \ After (use IO redirection): ``` topiary vis [--format FORMAT] \ - (--langauge LANGUAGE | --query QUERY) \ + (--langauge LANGUAGE [--query QUERY]) \ < INPUT_FILE \ [> OUTPUT_FILE] ``` @@ -184,12 +184,13 @@ topiary --configuration CONFIG_FILE \ ###### Examining Computed Configuration -Before (to standard error, then proceeding with other functions): +Before (to standard error, as debug output, then proceeding with other +functions): ``` topiary --output-configuration ... ``` -After (to standard output, as a dedicated function): +After (to standard output, in TOML format, as a dedicated function): ``` topiary cfg ``` diff --git a/Cargo.lock b/Cargo.lock index 0f86423f..7c9e3fbe 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -230,9 +230,9 @@ dependencies = [ [[package]] name = "clap" -version = "4.3.16" +version = "4.3.21" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "74bb1b4028935821b2d6b439bba2e970bdcf740832732437ead910c632e30d7d" +checksum = "c27cdf28c0f604ba3f512b0c9a409f8de8513e4816705deb0498b627e7c3a3fd" dependencies = [ "clap_builder", "clap_derive", @@ -241,9 +241,9 @@ dependencies = [ [[package]] name = "clap_builder" -version = "4.3.16" +version = "4.3.21" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5ae467cbb0111869b765e13882a1dbbd6cb52f58203d8b80c44f667d4dd19843" +checksum = "08a9f1ab5e9f01a9b81f202e8562eb9a10de70abf9eaeac1be465c28b75aa4aa" dependencies = [ "anstream", "anstyle", diff --git a/README.md b/README.md index 4917a679..fd6bb0b6 100644 --- a/README.md +++ b/README.md @@ -189,12 +189,12 @@ Options: [default: merge] Possible values: - - merge: When multiple sources of configuration are available, matching items are updated from - the higher priority source, with collections merged as the union of sets - - revise: When multiple sources of configuration are available, matching items (including - collections) are superseded from the higher priority source - - override: When multiple sources of configuration are available, the highest priority source is - taken. All values from lower priority sources are discarded + - merge: When multiple sources of configuration are available, matching items are + updated from the higher priority source, with collections merged as the union of sets + - revise: When multiple sources of configuration are available, matching items + (including collections) are superseded from the higher priority source + - override: When multiple sources of configuration are available, the highest priority + source is taken. All values from lower priority sources are discarded -h, --help Print help (see a summary with '-h') @@ -211,12 +211,15 @@ Options: ``` Format inputs -Usage: topiary fmt [OPTIONS] <--language |--query |FILES> +Usage: topiary fmt [OPTIONS] <--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 @@ -230,7 +233,7 @@ Options: [possible values: json, nickel, ocaml, ocaml-interface, ocamllex, toml] -q, --query - Topiary query file (for formatting stdin) + Topiary query file override (when formatting stdin) -C, --configuration Configuration file @@ -244,12 +247,12 @@ Options: [default: merge] Possible values: - - merge: When multiple sources of configuration are available, matching items are updated from - the higher priority source, with collections merged as the union of sets - - revise: When multiple sources of configuration are available, matching items (including - collections) are superseded from the higher priority source - - override: When multiple sources of configuration are available, the highest priority source is - taken. All values from lower priority sources are discarded + - merge: When multiple sources of configuration are available, matching items are + updated from the higher priority source, with collections merged as the union of sets + - revise: When multiple sources of configuration are available, matching items + (including collections) are superseded from the higher priority source + - override: When multiple sources of configuration are available, the highest priority + source is taken. All values from lower priority sources are discarded -h, --help Print help (see a summary with '-h') @@ -267,12 +270,15 @@ either `--language` or `--query` arguments, omitting any input files. ``` Visualise the input's Tree-sitter parse tree -Usage: topiary vis [OPTIONS] <--language |--query |FILE> +Usage: topiary vis [OPTIONS] <--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 Visualisation format @@ -289,7 +295,7 @@ Options: [possible values: json, nickel, ocaml, ocaml-interface, ocamllex, toml] -q, --query - Topiary query file (for formatting stdin) + Topiary query file override (when formatting stdin) -C, --configuration Configuration file @@ -303,12 +309,12 @@ Options: [default: merge] Possible values: - - merge: When multiple sources of configuration are available, matching items are updated from - the higher priority source, with collections merged as the union of sets - - revise: When multiple sources of configuration are available, matching items (including - collections) are superseded from the higher priority source - - override: When multiple sources of configuration are available, the highest priority source is - taken. All values from lower priority sources are discarded + - merge: When multiple sources of configuration are available, matching items are + updated from the higher priority source, with collections merged as the union of sets + - revise: When multiple sources of configuration are available, matching items + (including collections) are superseded from the higher priority source + - override: When multiple sources of configuration are available, the highest priority + source is taken. All values from lower priority sources are discarded -h, --help Print help (see a summary with '-h') @@ -342,12 +348,12 @@ Options: [default: merge] Possible values: - - merge: When multiple sources of configuration are available, matching items are updated from - the higher priority source, with collections merged as the union of sets - - revise: When multiple sources of configuration are available, matching items (including - collections) are superseded from the higher priority source - - override: When multiple sources of configuration are available, the highest priority source is - taken. All values from lower priority sources are discarded + - merge: When multiple sources of configuration are available, matching items are + updated from the higher priority source, with collections merged as the union of sets + - revise: When multiple sources of configuration are available, matching items + (including collections) are superseded from the higher priority source + - override: When multiple sources of configuration are available, the highest priority + source is taken. All values from lower priority sources are discarded -h, --help Print help (see a summary with '-h') @@ -405,7 +411,7 @@ sources where Topiary checks for such a file. ### Configuration Sources -At buildtime the [languages.toml](./languages.toml) in the root of +At build time the [languages.toml](./languages.toml) in the root of this repository is embedded into Topiary. This file is parsed at runtime. The purpose of this `languages.toml` file is to provide sane defaults for users of Topiary (both the library and the binary). diff --git a/topiary-cli/Cargo.toml b/topiary-cli/Cargo.toml index d0241535..9264c879 100644 --- a/topiary-cli/Cargo.toml +++ b/topiary-cli/Cargo.toml @@ -26,7 +26,6 @@ path = "src/main.rs" [dependencies] # For now we just load the tree-sitter language parsers statically. # Eventually we will want to dynamically load them, like Helix does. -# NOTE clap/wrap_help isn't perfect (see clap-rs/clap#5022) clap = { workspace = true, features = ["derive", "env", "wrap_help"] } directories = { workspace = true } env_logger = { workspace = true } diff --git a/topiary-cli/src/cli.rs b/topiary-cli/src/cli.rs index 0dc0ab03..f25648a8 100644 --- a/topiary-cli/src/cli.rs +++ b/topiary-cli/src/cli.rs @@ -51,52 +51,59 @@ pub struct GlobalArgs { pub configuration_collation: Option, } +#[derive(Args, Debug)] +pub struct Stdin { + /// Topiary supported language (for formatting stdin) + #[arg(short, long)] + pub language: SupportedLanguage, + + /// Topiary query file override (when formatting stdin) + #[arg(short, long, requires = "language")] + pub query: Option, +} + // Subtype for exactly one input: -// * FILE => Read input from disk, visualisation output to stdout -// * --language | --query => Read input from stdin, visualisation output to stdout +// * FILE => Read input from disk, visualisation output to stdout +// * --language => Read input from stdin, visualisation output to stdout #[derive(Args, Debug)] #[command( - // Require exactly one of --language, --query, or FILES... + // Require exactly one of --language, or FILES... group = ArgGroup::new("source") .multiple(false) .required(true) - .args(&["language", "query", "file"]) + .args(&["language", "file"]) )] pub struct ExactlyOneInput { - /// Topiary supported language (for formatting stdin) - #[arg(short, long)] - language: Option, - - /// Topiary query file (for formatting stdin) - #[arg(short, long)] - query: Option, + #[command(flatten)] + pub stdin: Option, /// Input file (omit to read from stdin) - file: Option, + /// + /// Language detection and query selection is automatic, mapped from file extensions defined in + /// the Topiary configuration. + pub file: Option, } // Subtype for at least one input -// * FILES... => Read input(s) from disk, format in place -// * --language | --query => Read input from stdin, output to stdout +// * FILES... => Read input(s) from disk, format in place +// * --language => Read input from stdin, output to stdout #[derive(Args, Debug)] #[command( // Require exactly one of --language, --query, or FILES... group = ArgGroup::new("source") .multiple(false) .required(true) - .args(&["language", "query", "files"]) + .args(&["language", "files"]) )] pub struct AtLeastOneInput { - /// Topiary supported language (for formatting stdin) - #[arg(short, long)] - language: Option, - - /// Topiary query file (for formatting stdin) - #[arg(short, long)] - query: Option, + #[command(flatten)] + pub stdin: Option, /// Input files and directories (omit to read from stdin) - files: Vec, + /// + /// Language detection and query selection is automatic, mapped from file extensions defined in + /// the Topiary configuration. + pub files: Vec, } #[derive(Debug, Subcommand)]