diff --git a/cli/src/args.rs b/cli/src/args.rs index ec50307..8ec696a 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::{ArgAction, Parser, Subcommand}; // @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, } diff --git a/cli/tests/integration_test.rs b/cli/tests/integration_test.rs index 4187bea..6a899f6 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<()> {