Skip to content

Commit

Permalink
Fix some fallout from clap 4 port (#1153)
Browse files Browse the repository at this point in the history
Enum-valued args should not use `value_parser`, it's both redundant and
wrong, and a `ValueEnum` derive should be used instead.

Another issue is that `trailing_var_arg` now requires `num_args` to be
set explicitly, which is also an improvement as `\e 10 12` would now get
rejected properly.

Fixes: #1152
  • Loading branch information
elprans authored Oct 19, 2023
1 parent 59f8064 commit be3c7a7
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 12 deletions.
6 changes: 3 additions & 3 deletions src/cli/install.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@ pub struct CliInstall {
}

#[derive(Debug, Clone, Copy)]
#[derive(clap::ValueEnum)]
#[value(rename_all="kebab-case")]
pub enum Shell {
Bash,
Elvish,
Expand All @@ -71,9 +73,7 @@ pub enum Shell {
#[derive(clap::Args, Clone, Debug)]
pub struct GenCompletions {
/// Shell to print out completions for
#[arg(long, value_parser=[
"bash", "elvish", "fish", "powershell", "zsh",
])]
#[arg(long)]
pub shell: Option<Shell>,

/// Install all completions into the prefix
Expand Down
11 changes: 3 additions & 8 deletions src/commands/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ pub enum Setting {

#[derive(clap::Args, Clone, Debug, Default)]
pub struct InputMode {
#[arg(value_name="mode", value_parser=["vi", "emacs"])]
#[arg(value_name="mode")]
pub value: Option<repl::InputMode>,
}

Expand Down Expand Up @@ -239,23 +239,18 @@ pub struct SettingUsize {

#[derive(clap::Args, Clone, Debug)]
pub struct Edit {
#[arg(trailing_var_arg=true, allow_hyphen_values=true)]
#[arg(trailing_var_arg=true, allow_hyphen_values=true, num_args=..2)]
pub entry: Option<isize>,
}

#[derive(clap::Args, Clone, Debug, Default)]
pub struct OutputFormat {
#[arg(value_name="mode", value_parser=
["default", "json-pretty", "json", "json-lines", "tab-separated"]
)]
#[arg(value_name="mode")]
pub value: Option<repl::OutputFormat>,
}

#[derive(clap::Args, Clone, Debug, Default)]
pub struct PrintStats {
#[arg(value_parser=
["off", "query", "detailed"]
)]
pub value: Option<repl::PrintStats>,
}

Expand Down
4 changes: 3 additions & 1 deletion src/portable/options.rs
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,8 @@ pub struct ListVersions {
}

#[derive(Debug, Clone, Copy, PartialEq, Serialize, Deserialize)]
#[derive(clap::ValueEnum)]
#[value(rename_all="kebab-case")]
pub enum StartConf {
Auto,
Manual,
Expand Down Expand Up @@ -170,7 +172,7 @@ pub struct Create {
pub region: Option<String>,

/// Deprecated parameter, unused.
#[arg(long, hide=true, value_parser=["auto", "manual"])]
#[arg(long, hide=true)]
pub start_conf: Option<StartConf>,

/// Default database name (created during initialization and saved in
Expand Down
6 changes: 6 additions & 0 deletions src/repl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ pub const FAILURE_MARKER: &str = "[tx:failed]";


#[derive(Debug, Clone, Copy, PartialEq, Eq)]
#[derive(clap::ValueEnum)]
#[value(rename_all="kebab-case")]
pub enum OutputFormat {
Default,
Json,
Expand All @@ -40,12 +42,16 @@ pub enum OutputFormat {
}

#[derive(Debug, Clone, Copy, PartialEq, Eq)]
#[derive(clap::ValueEnum)]
#[value(rename_all="kebab-case")]
pub enum InputMode {
Vi,
Emacs,
}

#[derive(Debug, Clone, Copy, PartialEq, Eq)]
#[derive(clap::ValueEnum)]
#[value(rename_all="kebab-case")]
pub enum PrintStats {
Off,
Query,
Expand Down

0 comments on commit be3c7a7

Please sign in to comment.