@@ -29,29 +29,33 @@ static HTML_FILES: &[&str] = &["htm", "html"];
2929#[ derive( FromArgs , PartialEq , Debug ) ]
3030/// A command-line tool to find broken links in your static site.
3131struct Cli {
32- /// the static file path to check.
32+ /// the static file path to check
3333 ///
3434 /// This will be assumed to be the root path of your server as well, so
35- /// href="/foo" will resolve to that folder's subfolder foo.
35+ /// href="/foo" will resolve to that folder's subfolder foo
3636 #[ argh( positional) ]
3737 base_path : Option < PathBuf > ,
3838
39- /// how many threads to use, default is to try and saturate CPU.
39+ /// how many threads to use, default is to try and saturate CPU
4040 #[ argh( option, short = 'j' , long = "jobs" ) ]
4141 threads : Option < usize > ,
4242
43- /// whether to check for valid anchor references.
43+ /// whether to check for valid anchor references
4444 #[ argh( switch) ]
4545 check_anchors : bool ,
4646
47- /// path to directory of markdown files to use for reporting errors.
47+ /// path to directory of markdown files to use for reporting errors
4848 #[ argh( option, long = "sources" ) ]
4949 sources_path : Option < PathBuf > ,
5050
51- /// enable specialized output for GitHub actions.
51+ /// enable specialized output for GitHub actions
5252 #[ argh( switch) ]
5353 github_actions : bool ,
5454
55+ /// print version information and exit
56+ #[ argh( switch, short = 'V' ) ]
57+ version : bool ,
58+
5559 #[ argh( subcommand) ]
5660 subcommand : Option < Subcommand > ,
5761}
@@ -125,8 +129,14 @@ fn main() -> Result<(), Error> {
125129 sources_path,
126130 github_actions,
127131 subcommand,
132+ version,
128133 } = argh:: from_env ( ) ;
129134
135+ if version {
136+ println ! ( "hyperlink {}" , env!( "CARGO_PKG_VERSION" ) ) ;
137+ return Ok ( ( ) ) ;
138+ }
139+
130140 rayon:: ThreadPoolBuilder :: new ( )
131141 // most of the work we do is kind of I/O bound. rayon assumes CPU-heavy workload. we could
132142 // look into tokio-uring at some point, but it seems like a hassle wrt ownership
@@ -658,6 +668,17 @@ $"#,
658668 site. close ( ) . unwrap ( ) ;
659669 }
660670
671+ #[ test]
672+ fn test_version ( ) {
673+ let mut cmd = Command :: cargo_bin ( "hyperlink" ) . unwrap ( ) ;
674+ cmd. arg ( "--version" ) ;
675+
676+ cmd. assert ( )
677+ . success ( )
678+ . code ( 0 )
679+ . stdout ( predicate:: str:: contains ( "hyperlink " ) ) ;
680+ }
681+
661682 #[ test]
662683 fn test_no_args ( ) {
663684 let mut cmd = Command :: cargo_bin ( "hyperlink" ) . unwrap ( ) ;
667688 . code ( 1 )
668689 . stdout ( predicate:: str:: contains (
669690 "\
670- Usage: hyperlink [<base_path>] [-j <jobs>] [--check-anchors] [--sources <sources>] [--github-actions] [<command>] [<args>]\
691+ Usage: hyperlink [<base_path>] [-j <jobs>] [--check-anchors] [--sources <sources>] [--github-actions] [-V] [ <command>] [<args>]\
671692 ",
672693 ) ) ;
673694 }
0 commit comments