preserves-tools: deps: Update to clap 3 release.

This was previously using a beta release. This helps move towards
updating to the current v4 release.
This commit is contained in:
Bruce Mitchener 2023-07-17 11:46:48 +07:00
parent 6f085a7192
commit acfacd636b
2 changed files with 20 additions and 33 deletions

View File

@ -14,9 +14,8 @@ preserves-path = { path = "../preserves-path", version = "4.1.0"}
preserves-schema = { path = "../preserves-schema", version = "3.1.0"} preserves-schema = { path = "../preserves-schema", version = "3.1.0"}
bytes = "1.0" bytes = "1.0"
clap = "=3.0.0-beta.2" clap = { version = "3", features = ["derive"] }
clap_generate = "=3.0.0-beta.2" clap_complete = "3"
clap_derive = "=3.0.0-beta.2"
[package.metadata.workspaces] [package.metadata.workspaces]
independent = true independent = true

View File

@ -2,10 +2,8 @@ use bytes::Buf;
use bytes::BufMut; use bytes::BufMut;
use bytes::BytesMut; use bytes::BytesMut;
use clap::ArgEnum; use clap:: {ArgEnum, Command, IntoApp, Parser, value_parser};
use clap::Clap; use clap_complete::{generate, Generator, Shell};
use clap::IntoApp;
use clap_generate::{generate, generators};
use preserves::value::IOBinarySource; use preserves::value::IOBinarySource;
use preserves::value::IOValue; use preserves::value::IOValue;
@ -55,15 +53,6 @@ enum CommasFormat {
Terminating, Terminating,
} }
#[derive(ArgEnum, Clone, Debug)]
enum CompletionDialect {
Bash,
Zsh,
PowerShell,
Fish,
Elvish,
}
#[derive(ArgEnum, Clone, Copy, Debug)] #[derive(ArgEnum, Clone, Copy, Debug)]
enum Boolish { enum Boolish {
#[clap(alias = "no", alias = "n", alias = "off", alias = "0", alias = "false")] #[clap(alias = "no", alias = "n", alias = "off", alias = "0", alias = "false")]
@ -94,7 +83,7 @@ enum SelectOutput {
Set, Set,
} }
#[derive(Clap, Clone, Debug)] #[derive(Clone, Debug, Parser)]
struct Convert { struct Convert {
// #[clap(long, arg_enum, default_value = "none")] // #[clap(long, arg_enum, default_value = "none")]
// input_encoding: Encoding, // input_encoding: Encoding,
@ -149,7 +138,7 @@ enum StringInputTerminator {
Nul, Nul,
} }
#[derive(Clap, Clone, Debug)] #[derive(Clone, Debug, Parser)]
struct StringQuotation { struct StringQuotation {
#[clap(long, arg_enum, default_value = "eof")] #[clap(long, arg_enum, default_value = "eof")]
input_terminator: StringInputTerminator, input_terminator: StringInputTerminator,
@ -161,14 +150,14 @@ struct StringQuotation {
escape_spaces: bool, escape_spaces: bool,
} }
#[derive(Clap, Clone, Debug)] #[derive(Clone, Debug, Parser)]
enum QuotationOutput { enum QuotationOutput {
String(StringQuotation), String(StringQuotation),
ByteString, ByteString,
Symbol(StringQuotation), Symbol(StringQuotation),
} }
#[derive(Clap, Clone, Debug)] #[derive(Clone, Debug, Parser)]
struct Quote { struct Quote {
#[clap(long, short, arg_enum, default_value = "text")] #[clap(long, short, arg_enum, default_value = "text")]
output_format: OutputFormat, output_format: OutputFormat,
@ -177,35 +166,34 @@ struct Quote {
output: QuotationOutput, output: QuotationOutput,
} }
#[derive(Clap, Clone, Debug)] #[derive(Clone, Debug, Parser)]
enum Subcommand { enum Subcommand {
Completions { Completions {
#[clap(arg_enum, value_name = "dialect")] #[clap(value_parser=value_parser!(Shell))]
dialect: CompletionDialect, shell: Shell,
}, },
Convert(Convert), Convert(Convert),
Quote(Quote), Quote(Quote),
} }
#[derive(Clap, Clone, Debug)] #[derive(Clone, Debug, Parser)]
#[clap(name="preserves-tool")]
#[clap(version)] #[clap(version)]
struct CommandLine { struct CommandLine {
#[clap(subcommand)] #[clap(subcommand)]
command: Subcommand, command: Subcommand,
} }
fn print_completions<G: Generator>(gen: G, cmd: &mut Command) {
generate(gen, cmd, cmd.get_name().to_string(), &mut io::stdout());
}
fn main() -> io::Result<()> { fn main() -> io::Result<()> {
let args = CommandLine::parse(); let args = CommandLine::parse();
Ok(match args.command { Ok(match args.command {
Subcommand::Completions { dialect } => { Subcommand::Completions { shell } => {
let mut app = CommandLine::into_app(); let mut cmd = CommandLine::into_app();
match dialect { print_completions(shell, &mut cmd);
CompletionDialect::Bash => generate::<generators::Bash, _>(&mut app, "preserves-tool", &mut io::stdout()),
CompletionDialect::Zsh => generate::<generators::Zsh, _>(&mut app, "preserves-tool", &mut io::stdout()),
CompletionDialect::PowerShell => generate::<generators::PowerShell, _>(&mut app, "preserves-tool", &mut io::stdout()),
CompletionDialect::Fish => generate::<generators::Fish, _>(&mut app, "preserves-tool", &mut io::stdout()),
CompletionDialect::Elvish => generate::<generators::Elvish, _>(&mut app, "preserves-tool", &mut io::stdout()),
}
}, },
Subcommand::Convert(c) => convert(c)?, Subcommand::Convert(c) => convert(c)?,
Subcommand::Quote(q) => quote(q)?, Subcommand::Quote(q) => quote(q)?,