diff --git a/Cargo.toml b/Cargo.toml index b3ef3dee6..4df853001 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -60,6 +60,9 @@ features = [ "error-context", ] +[dependencies.clap_complete] +version = "4.2.1" + [dev-dependencies] approx = "0.5" assert_cmd = "2.0" diff --git a/src/cli.rs b/src/cli.rs index b12f6d34c..4607ec5fa 100644 --- a/src/cli.rs +++ b/src/cli.rs @@ -1,10 +1,12 @@ use std::ffi::OsString; use clap::{ - builder::NonEmptyStringValueParser, crate_version, Arg, ArgAction, ArgMatches, Command, - ValueHint, + builder::{NonEmptyStringValueParser, PossibleValuesParser}, + crate_version, Arg, ArgAction, ArgMatches, Command, ValueHint, }; +const SHELLS: [&str; 5] = ["bash", "zsh", "fish", "powershell", "elvish"]; + pub fn get_cli_arguments<'a, I, T>(args: I) -> ArgMatches where I: IntoIterator, @@ -15,7 +17,7 @@ where } /// Build the clap command for parsing command line arguments -fn build_command() -> Command { +pub fn build_command() -> Command { Command::new("hyperfine") .version(crate_version!()) .next_line_help(true) @@ -30,7 +32,7 @@ fn build_command() -> Command { The latter is only available if the shell is not explicitly disabled via \ '--shell=none'. If multiple commands are given, hyperfine will show a \ comparison of the respective runtimes.") - .required(true) + .required_unless_present("generate-completions") .action(ArgAction::Append) .value_hint(ValueHint::CommandString) .value_parser(NonEmptyStringValueParser::new()), @@ -406,6 +408,15 @@ fn build_command() -> Command { .hide(true) .help("Enable debug mode which does not actually run commands, but returns fake times when the command is 'sleep