cli: Add --version flag

This commit is contained in:
rhysd authored and Dzmitry Malyshau committed 2022-01-28 12:16:00 -05:00
1 parent 6842db4432
commit 0afa8fcb4f
1 file changed
+8
+8
View File
@@ -64,6 +64,10 @@ struct Args {
#[argh(option)]
stdin_file_path: Option<String>,
/// show version
#[argh(switch)]
version: bool,
/// the input and output files.
///
/// First positional argument is the input file. If not specified, the
@@ -209,6 +213,10 @@ fn run() -> Result<(), Box<dyn std::error::Error>> {
// Parse commandline arguments
let args: Args = argh::from_env();
if args.version {
println!("{}", env!("CARGO_PKG_VERSION"));
return Ok(());
}
let (input_path, input) = if let Some(path) = args.files.first() {
let path = Path::new(path);
(path, fs::read(path)?)