diff --git a/src/main.rs b/src/main.rs index 5633e80..4c5ba85 100644 --- a/src/main.rs +++ b/src/main.rs @@ -30,7 +30,7 @@ use crate::opts::Coloring::*; use crate::opts::{Coloring, Expand, Subcommand}; use crate::unparse::unparse_maximal; use bat::{PagingMode, PrettyPrinter}; -use clap::{Parser, ValueEnum}; +use clap::{CommandFactory, Parser, ValueEnum}; use quote::quote; use std::env; use std::ffi::OsString; @@ -62,6 +62,13 @@ fn cargo_binary() -> OsString { fn cargo_expand() -> Result { let Subcommand::Expand(args) = Subcommand::parse(); + + if args.version { + let mut stdout = io::stdout(); + let _ = stdout.write_all(Subcommand::command().render_version().as_bytes()); + return Ok(0); + } + let config = config::deserialize(); if args.themes { diff --git a/src/opts.rs b/src/opts.rs index 9371fde..8be9350 100644 --- a/src/opts.rs +++ b/src/opts.rs @@ -9,7 +9,7 @@ const VERSION: &str = include_str!(concat!(env!("OUT_DIR"), "/version")); #[command(bin_name = "cargo", version = VERSION, author, disable_help_subcommand = true)] pub enum Subcommand { /// Show the result of macro expansion. - #[command(name = "expand", version = VERSION, author)] + #[command(name = "expand", version = VERSION, author, disable_version_flag = true)] Expand(Expand), } @@ -118,6 +118,10 @@ pub struct Expand { /// Local path to module or other named item to expand, e.g. os::unix::ffi #[arg(value_name = "ITEM", value_parser = parse_selector)] pub item: Option, + + /// Print version + #[arg(long)] + pub version: bool, } #[derive(ValueEnum, Debug, Clone, Copy)]