File tree Expand file tree Collapse file tree 2 files changed +36
-0
lines changed
Expand file tree Collapse file tree 2 files changed +36
-0
lines changed Original file line number Diff line number Diff line change @@ -6,6 +6,10 @@ use std::io::{self, Write};
66#[ derive( FromArgs ) ]
77/// Copy data to clipboard using OSC52 escape sequences
88struct Args {
9+ #[ argh( switch, short = 'v' ) ]
10+ /// show version information
11+ version : bool ,
12+
913 #[ argh( positional) ]
1014 /// file to copy (reads from stdin if not provided)
1115 file : Option < String > ,
@@ -58,6 +62,11 @@ fn stream_to_clipboard_from_file(path: &str) -> io::Result<()> {
5862fn main ( ) -> io:: Result < ( ) > {
5963 let args: Args = argh:: from_env ( ) ;
6064
65+ if args. version {
66+ println ! ( "{} {}" , env!( "CARGO_PKG_NAME" ) , env!( "CARGO_PKG_VERSION" ) ) ;
67+ return Ok ( ( ) ) ;
68+ }
69+
6170 if let Some ( file_path) = & args. file {
6271 stream_to_clipboard_from_file ( file_path) ?;
6372 } else {
Original file line number Diff line number Diff line change 1+ use std:: process:: Command ;
2+
3+ #[ test]
4+ fn test_version_flag ( ) {
5+ let output = Command :: new ( "cargo" )
6+ . args ( & [ "run" , "--" , "--version" ] )
7+ . output ( )
8+ . expect ( "Failed to execute command" ) ;
9+
10+ assert ! ( output. status. success( ) ) ;
11+ let stdout = String :: from_utf8 ( output. stdout ) . expect ( "Invalid UTF-8" ) ;
12+ let expected = format ! ( "{} {}" , env!( "CARGO_PKG_NAME" ) , env!( "CARGO_PKG_VERSION" ) ) ;
13+ assert_eq ! ( stdout. trim( ) , expected) ;
14+ }
15+
16+ #[ test]
17+ fn test_version_flag_short ( ) {
18+ let output = Command :: new ( "cargo" )
19+ . args ( & [ "run" , "--" , "-v" ] )
20+ . output ( )
21+ . expect ( "Failed to execute command" ) ;
22+
23+ assert ! ( output. status. success( ) ) ;
24+ let stdout = String :: from_utf8 ( output. stdout ) . expect ( "Invalid UTF-8" ) ;
25+ let expected = format ! ( "{} {}" , env!( "CARGO_PKG_NAME" ) , env!( "CARGO_PKG_VERSION" ) ) ;
26+ assert_eq ! ( stdout. trim( ) , expected) ;
27+ }
You can’t perform that action at this time.
0 commit comments