From 661bfc8734416069810ead32b5b3c261422feb50 Mon Sep 17 00:00:00 2001 From: h1alexbel Date: Wed, 9 Oct 2024 12:10:52 +0300 Subject: [PATCH 1/3] feat(#197): --version, -v, old puzzle --- cli/src/args.rs | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/cli/src/args.rs b/cli/src/args.rs index ec503074..498c07b1 100644 --- a/cli/src/args.rs +++ b/cli/src/args.rs @@ -19,18 +19,17 @@ // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE // SOFTWARE. -use clap::{Parser, Subcommand}; +use clap::{Parser, Subcommand, ArgAction}; // @todo #41:15min Add --report argument. // Let's add --report option for generating reports in desired formats: // We should support following formats: xml, tex, and txt. User should have // ability to generate report in multiple formats as well: --report tex,xml,txt. -// @todo #79:25min Add --v option for verbose output. -// Let's add --v option for verbose output and debug logs. When this option is -// passed, we should show debug logs too. #[derive(Parser, Debug)] -#[command(name = "fakehub")] +#[command(name = "fakehub", version = env!("CARGO_PKG_VERSION"))] pub(crate) struct Args { + #[arg(short = 'v', action = ArgAction::Version)] + v: Option, #[command(subcommand)] pub(crate) command: Command, } From 270b8ca547d5265fc9b70fc910204866ae7eb5f2 Mon Sep 17 00:00:00 2001 From: h1alexbel Date: Wed, 9 Oct 2024 12:16:46 +0300 Subject: [PATCH 2/3] feat(#197): tests --- cli/tests/integration_test.rs | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/cli/tests/integration_test.rs b/cli/tests/integration_test.rs index 4187beac..a658c5be 100644 --- a/cli/tests/integration_test.rs +++ b/cli/tests/integration_test.rs @@ -45,6 +45,25 @@ mod tests { Ok(()) } + #[tag("deep")] + #[test] + fn outputs_version() -> Result<()> { + let assertion = Command::cargo_bin("fakehub")?.arg("--version").assert(); + let bytes = assertion.get_output().stdout.as_slice(); + let output = str::from_utf8(bytes)?; + assert!(output.contains(env!("CARGO_PKG_VERSION"))); + Ok(()) + } + + #[test] + fn outputs_version_from_short() -> Result<()> { + let assertion = Command::cargo_bin("fakehub")?.arg("-v").assert(); + let bytes = assertion.get_output().stdout.as_slice(); + let output = str::from_utf8(bytes)?; + assert!(output.contains(env!("CARGO_PKG_VERSION"))); + Ok(()) + } + #[tag("deep")] #[test] fn outputs_start_opts() -> Result<()> { From d75e4153f2b9e1c7df581a1f96e6eb147c26fd17 Mon Sep 17 00:00:00 2001 From: h1alexbel Date: Wed, 9 Oct 2024 12:22:11 +0300 Subject: [PATCH 3/3] feat(#197): clean for check --- cli/src/args.rs | 2 +- cli/tests/integration_test.rs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/cli/src/args.rs b/cli/src/args.rs index 498c07b1..8ec696aa 100644 --- a/cli/src/args.rs +++ b/cli/src/args.rs @@ -19,7 +19,7 @@ // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE // SOFTWARE. -use clap::{Parser, Subcommand, ArgAction}; +use clap::{ArgAction, Parser, Subcommand}; // @todo #41:15min Add --report argument. // Let's add --report option for generating reports in desired formats: diff --git a/cli/tests/integration_test.rs b/cli/tests/integration_test.rs index a658c5be..6a899f69 100644 --- a/cli/tests/integration_test.rs +++ b/cli/tests/integration_test.rs @@ -54,7 +54,7 @@ mod tests { assert!(output.contains(env!("CARGO_PKG_VERSION"))); Ok(()) } - + #[test] fn outputs_version_from_short() -> Result<()> { let assertion = Command::cargo_bin("fakehub")?.arg("-v").assert();