diff --git a/Cargo.lock b/Cargo.lock index 85935d0..8f4d5fd 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -32,56 +32,12 @@ version = "0.1.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4b46cbb362ab8752921c97e041f5e366ee6297bd428a31275b9fcf1e380f7299" -[[package]] -name = "anstream" -version = "1.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "824a212faf96e9acacdbd09febd34438f8f711fb84e09a8916013cd7815ca28d" -dependencies = [ - "anstyle", - "anstyle-parse", - "anstyle-query", - "anstyle-wincon", - "colorchoice", - "is_terminal_polyfill", - "utf8parse", -] - [[package]] name = "anstyle" version = "1.0.14" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "940b3a0ca603d1eade50a4846a2afffd5ef57a9feac2c0e2ec2e14f9ead76000" -[[package]] -name = "anstyle-parse" -version = "1.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "52ce7f38b242319f7cabaa6813055467063ecdc9d355bbb4ce0c68908cd8130e" -dependencies = [ - "utf8parse", -] - -[[package]] -name = "anstyle-query" -version = "1.1.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "40c48f72fd53cd289104fc64099abca73db4166ad86ea0b4341abe65af83dadc" -dependencies = [ - "windows-sys 0.61.2", -] - -[[package]] -name = "anstyle-wincon" -version = "3.0.11" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "291e6a250ff86cd4a820112fb8898808a366d8f9f58ce16d1f538353ad55747d" -dependencies = [ - "anstyle", - "once_cell_polyfill", - "windows-sys 0.61.2", -] - [[package]] name = "arc-swap" version = "1.9.2" @@ -293,7 +249,6 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "aa8876b300ab35ba921adea3dfd70157a46249b33f95c9084ae5709785478946" dependencies = [ "clap_builder", - "clap_derive", ] [[package]] @@ -302,22 +257,8 @@ version = "4.6.7" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ec0797fb7aeb1406c84efac526901f7ec3ead2124f946b494e72879d4b54704d" dependencies = [ - "anstream", "anstyle", "clap_lex", - "strsim", -] - -[[package]] -name = "clap_derive" -version = "4.6.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f9c751b79415d4e559e3d1fcf128e09e720eb673a06d26cf6f392d37d75b66e0" -dependencies = [ - "heck", - "proc-macro2", - "quote", - "syn 3.0.5", ] [[package]] @@ -365,12 +306,6 @@ dependencies = [ "unicode-width", ] -[[package]] -name = "colorchoice" -version = "1.0.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1d07550c9036bf2ae0c684c4297d503f838287c83c53686d05370d0e139ae570" - [[package]] name = "colored" version = "2.2.0" @@ -1740,12 +1675,6 @@ dependencies = [ "stable_deref_trait", ] -[[package]] -name = "heck" -version = "0.5.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2304e00983f87ffb38b55b444b5e3b60a884b5d30c0fca7d82fe33449bbe55ea" - [[package]] name = "hex" version = "0.4.3" @@ -1989,12 +1918,6 @@ version = "2.12.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6a756c3fac73139e83f14c2d742155dd2b78d3ee56597b419a0579b7bdd6dd78" -[[package]] -name = "is_terminal_polyfill" -version = "1.70.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a6cb138bb79a146c1bd460005623e142ef0181e3d0219cb493e02f7d08a35695" - [[package]] name = "itertools" version = "0.13.0" @@ -2246,12 +2169,6 @@ version = "1.21.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9f7c3e4beb33f85d45ae3e3a1792185706c8e16d043238c593331cc7cd313b50" -[[package]] -name = "once_cell_polyfill" -version = "1.70.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "384b8ab6d37215f3c5301a95a4accb5d64aa607f1fcb26a11b5303878451b4fe" - [[package]] name = "oorandom" version = "11.1.5" @@ -2686,13 +2603,13 @@ dependencies = [ name = "rix-cli" version = "0.1.0" dependencies = [ - "clap", "colored", "rix-eval", "rix-parser", "rootcause", "serde_json", "thiserror", + "usage-rs", ] [[package]] @@ -3092,12 +3009,6 @@ version = "1.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6ce2be8dc25455e1f91df71bfa12ad37d7af1092ae736f3a6cd0e37bc7810596" -[[package]] -name = "strsim" -version = "0.11.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7da8b5736845d9f2fcb837ea5d9e2628564b3b043a70948a3f0b778838c5fb4f" - [[package]] name = "subtle" version = "2.6.1" @@ -3460,16 +3371,37 @@ dependencies = [ ] [[package]] -name = "utf8_iter" -version = "1.0.4" +name = "usage-argv" +version = "6.9.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b6c140620e7ffbb22c2dee59cafe6084a59b5ffc27a8859a5f0d494b5d52b6be" +checksum = "95aa4f80e25dd1d89e59972a37c7ce6701b6c60429808723ad960bef266ac184" [[package]] -name = "utf8parse" -version = "0.2.2" +name = "usage-derive" +version = "6.9.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "376556a35b1cd6eb7b66a189a7d99f062c15d1fbc67e17e7d220a1ae7d4bbe40" +dependencies = [ + "proc-macro2", + "quote", + "syn 3.0.5", +] + +[[package]] +name = "usage-rs" +version = "6.9.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "06abde3611657adf66d383f00b093d7faecc7fa57071cce2578660c9f1010821" +checksum = "03345178d8c95694630971f121d7cf9c885f150a52abf202eca694cfa697e7ef" +dependencies = [ + "usage-argv", + "usage-derive", +] + +[[package]] +name = "utf8_iter" +version = "1.0.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b6c140620e7ffbb22c2dee59cafe6084a59b5ffc27a8859a5f0d494b5d52b6be" [[package]] name = "version_check" diff --git a/Cargo.toml b/Cargo.toml index 07ebcce..0e3775f 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -11,8 +11,7 @@ repository = "https://github.com/Sunrise-OS/rix" [workspace.dependencies] rix-parser = { path = "rix-parser" } rix-eval = { path = "rix-eval" } - -clap = { version = "4.6.7", features = ["derive"] } +usage = { package = "usage-rs", version = "6.9.1" } thiserror = "2.0.20" rootcause = "0.13.0" rowan = "0.17.0" diff --git a/rix-cli/Cargo.toml b/rix-cli/Cargo.toml index 0a204b8..7cb9a5d 100644 --- a/rix-cli/Cargo.toml +++ b/rix-cli/Cargo.toml @@ -7,7 +7,7 @@ repository.workspace = true keywords = ["nix", "cli"] [dependencies] -clap.workspace = true +usage.workspace = true thiserror.workspace = true rix-parser.workspace = true rix-eval.workspace = true diff --git a/rix-cli/src/main.rs b/rix-cli/src/main.rs index e651d0d..5fbc9a0 100644 --- a/rix-cli/src/main.rs +++ b/rix-cli/src/main.rs @@ -1,98 +1,102 @@ -use clap::{Parser, Subcommand}; use nix_eval::{BuildOptions, Builder, Evaluator, NixValue}; use rootcause::{Report, report}; use std::collections::HashMap; use std::io::{self, Read}; use std::path::{Path, PathBuf}; +use usage::{Cli, Subcommands}; /// Pure Rust Nix expression evaluator and package manager -#[derive(Parser, Debug, Clone)] -#[command(name = "rix", author, version, about = "Nix-compatible package manager", long_about = None)] +#[derive(Cli, Debug, Clone)] +#[usage( + name = "rix", + bin = "rix", + version, + about = "Nix-compatible package manager" +)] struct Cli { - #[command(subcommand)] + #[usage(subcommand)] command: Option, /// File to evaluate or build - #[arg(short = 'f', long = "file", global = true)] + #[usage(short = 'f', long = "file", global)] file: Option, /// Attribute path to select - #[arg(short = 'A', long = "attr", global = true)] + #[usage(short = 'A', long = "attr", global)] attr: Option, /// Output symlink path (default: result) - #[arg(short = 'o', long = "out-link", global = true)] + #[usage(short = 'o', long = "out-link", global)] out_link: Option, /// Nix expression to evaluate - #[arg(short = 'e', long = "expr", global = true)] + #[usage(short = 'e', long = "expr", global)] expression: Option, /// Produce output in JSON format - #[arg(long, global = true)] + #[usage(long, global)] json: bool, /// Verbose output - #[arg(short = 'v', long = "verbose", global = true)] + #[usage(short = 'v', long = "verbose", global)] verbose: bool, /// Keep failed build temporary directory - #[arg(long = "keep-failed", global = true)] + #[usage(long = "keep-failed", global)] keep_failed: bool, /// Dry run (do not execute build commands) - #[arg(long = "dry-run", global = true)] + #[usage(long = "dry-run", global)] dry_run: bool, } -#[derive(Subcommand, Debug, Clone)] +#[derive(Subcommands, Debug, Clone)] enum Commands { /// Build a derivation from a Nix expression or file Build { /// File to build (default: default.nix) - #[arg(short = 'f', long = "file")] + #[usage(short = 'f', long = "file")] file: Option, /// Attribute path to build - #[arg(short = 'A', long = "attr")] + #[usage(short = 'A', long = "attr")] attr: Option, /// Output symlink path (default: result) - #[arg(short = 'o', long = "out-link")] + #[usage(short = 'o', long = "out-link")] out_link: Option, /// Nix expression to evaluate and build - #[arg(short = 'e', long = "expr")] + #[usage(short = 'e', long = "expr")] expr: Option, }, /// Evaluate a Nix expression Eval { /// Nix expression to evaluate - #[arg(short = 'e', long = "expr")] + #[usage(short = 'e', long = "expr")] expr: Option, /// File to evaluate - #[arg(short = 'f', long = "file")] + #[usage(short = 'f', long = "file")] file: Option, /// Attribute path to select - #[arg(short = 'A', long = "attr")] + #[usage(short = 'A', long = "attr")] attr: Option, }, /// Show derivation plan (ATerm or JSON) ShowDerivation { /// File to evaluate (default: default.nix) - #[arg(short = 'f', long = "file")] + #[usage(short = 'f', long = "file")] file: Option, /// Attribute path to show - #[arg(short = 'A', long = "attr")] + #[usage(short = 'A', long = "attr")] attr: Option, }, } - fn main() -> Result<(), Report> { let cli = Cli::parse(); let evaluator = Evaluator::new();