From 7f804cedd6082eea37b5ed41785bc8cc88865031 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ale=C5=A1=20Katona?= Date: Thu, 14 Jul 2022 17:54:14 -0700 Subject: [PATCH] handle extra subcommand name from cargo --- src/main.rs | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/src/main.rs b/src/main.rs index b8becf8..7a43f23 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,3 +1,5 @@ +use std::ffi::OsString; + use clap::Parser; mod vcs; @@ -5,7 +7,9 @@ mod vcs; use vcs::cli::*; fn main() { - let args = Cli::parse(); + // running with cargo vcs causes the vcs arg to be sent along + // we need to unhack this for Clap + let args = parse_args(); let work_dir = args .path @@ -40,3 +44,15 @@ fn main() { } } } + +fn parse_args() -> Cli { + // running with cargo vcs causes the vcs arg to be sent along + // we need to unhack this for Clap + let mut all_args: Vec = std::env::args_os().collect(); + let vcsstr = String::from("vcs"); + let osvcsstr = OsString::from(vcsstr); + if all_args.get(1) == Some(&osvcsstr) { + all_args.remove(1); + } + Cli::parse_from(all_args) +}