cli: consistently use clap::Command, and avoid unnecessary qualification

This commit is contained in:
Martin von Zweigbergk 2023-01-26 14:23:19 -08:00 committed by Martin von Zweigbergk
parent 4a4aebd3bc
commit 8af38f0d75
2 changed files with 11 additions and 11 deletions

View file

@ -275,7 +275,7 @@ impl TracingSubscription {
} }
pub struct CommandHelper { pub struct CommandHelper {
app: clap::Command, app: Command,
cwd: PathBuf, cwd: PathBuf,
string_args: Vec<String>, string_args: Vec<String>,
global_args: GlobalArgs, global_args: GlobalArgs,
@ -286,7 +286,7 @@ pub struct CommandHelper {
impl CommandHelper { impl CommandHelper {
pub fn new( pub fn new(
app: clap::Command, app: Command,
cwd: PathBuf, cwd: PathBuf,
string_args: Vec<String>, string_args: Vec<String>,
global_args: GlobalArgs, global_args: GlobalArgs,
@ -305,7 +305,7 @@ impl CommandHelper {
} }
} }
pub fn app(&self) -> &clap::Command { pub fn app(&self) -> &Command {
&self.app &self.app
} }
@ -1715,7 +1715,7 @@ impl ValueParserFactory for RevisionArg {
fn resolve_aliases( fn resolve_aliases(
config: &config::Config, config: &config::Config,
app: &clap::Command, app: &Command,
string_args: &[String], string_args: &[String],
) -> Result<Vec<String>, CommandError> { ) -> Result<Vec<String>, CommandError> {
let mut aliases_map = config.get_table("alias")?; let mut aliases_map = config.get_table("alias")?;
@ -1771,7 +1771,7 @@ fn resolve_aliases(
/// Parse args that must be interpreted early, e.g. before printing help. /// Parse args that must be interpreted early, e.g. before printing help.
fn handle_early_args( fn handle_early_args(
ui: &mut Ui, ui: &mut Ui,
app: &clap::Command, app: &Command,
args: &[String], args: &[String],
layered_configs: &mut LayeredConfigs, layered_configs: &mut LayeredConfigs,
) -> Result<(), CommandError> { ) -> Result<(), CommandError> {
@ -1793,7 +1793,7 @@ fn handle_early_args(
} }
pub fn expand_args( pub fn expand_args(
app: &clap::Command, app: &Command,
args_os: ArgsOs, args_os: ArgsOs,
config: &config::Config, config: &config::Config,
) -> Result<Vec<String>, CommandError> { ) -> Result<Vec<String>, CommandError> {
@ -1811,7 +1811,7 @@ pub fn expand_args(
pub fn parse_args( pub fn parse_args(
ui: &mut Ui, ui: &mut Ui,
app: &clap::Command, app: &Command,
tracing_subscription: &TracingSubscription, tracing_subscription: &TracingSubscription,
string_args: &[String], string_args: &[String],
layered_configs: &mut LayeredConfigs, layered_configs: &mut LayeredConfigs,
@ -1886,7 +1886,7 @@ pub fn handle_command_result(ui: &mut Ui, result: Result<(), CommandError>) -> E
#[must_use] #[must_use]
pub struct CliRunner { pub struct CliRunner {
tracing_subscription: TracingSubscription, tracing_subscription: TracingSubscription,
app: clap::Command, app: Command,
store_factories: Option<StoreFactories>, store_factories: Option<StoreFactories>,
dispatch_fn: CliDispatchFn, dispatch_fn: CliDispatchFn,
} }

View file

@ -23,7 +23,7 @@ use std::path::PathBuf;
use std::{fs, io}; use std::{fs, io};
use clap::builder::NonEmptyStringValueParser; use clap::builder::NonEmptyStringValueParser;
use clap::{ArgGroup, ArgMatches, CommandFactory, FromArgMatches, Subcommand}; use clap::{ArgGroup, ArgMatches, Command, CommandFactory, FromArgMatches, Subcommand};
use config::Source; use config::Source;
use indexmap::{IndexMap, IndexSet}; use indexmap::{IndexMap, IndexSet};
use itertools::Itertools; use itertools::Itertools;
@ -3195,8 +3195,8 @@ fn cmd_sparse(ui: &mut Ui, command: &CommandHelper, args: &SparseArgs) -> Result
Ok(()) Ok(())
} }
pub fn default_app() -> clap::Command { pub fn default_app() -> Command {
let app: clap::Command = Commands::augment_subcommands(Args::command()); let app: Command = Commands::augment_subcommands(Args::command());
app.arg_required_else_help(true).subcommand_required(true) app.arg_required_else_help(true).subcommand_required(true)
} }