cli: add a `version` command
Closes
@@ -1095,6 +1095,7 @@ struct GlobalArgs {
#[derive(Subcommand, Clone, Debug)]
enum Commands {
+ Version(VersionArgs),
Init(InitArgs),
Checkout(CheckoutArgs),
Untrack(UntrackArgs),
@@ -1152,6 +1153,10 @@ enum Commands {
Alias(Vec<String>),
}
+/// Display version information
+#[derive(clap::Args, Clone, Debug)]
+struct VersionArgs {}
+
/// Create a new repo in the given directory
///
/// If the given directory does not exist, it will be created. If no directory
@@ -2069,6 +2074,15 @@ fn add_to_git_exclude(ui: &mut Ui, git_repo: &git2::Repository) -> Result<(), Co
Ok(())
}
+fn cmd_version(
+ ui: &mut Ui,
+ command: &CommandHelper,
+ _args: &VersionArgs,
+) -> Result<(), CommandError> {
+ ui.write(&command.app.render_version())?;
+ Ok(())
+}
+
fn cmd_init(ui: &mut Ui, command: &CommandHelper, args: &InitArgs) -> Result<(), CommandError> {
if command.global_args().repository.is_some() {
return Err(CommandError::UserError(
@@ -5537,6 +5551,7 @@ where
let app = Args::command();
let command_helper = CommandHelper::new(app, string_args, args.global_args.clone());
match &args.command {
+ Commands::Version(sub_args) => cmd_version(ui, &command_helper, sub_args),
Commands::Init(sub_args) => cmd_init(ui, &command_helper, sub_args),
Commands::Checkout(sub_args) => cmd_checkout(ui, &command_helper, sub_args),
Commands::Untrack(sub_args) => cmd_untrack(ui, &command_helper, sub_args),
