Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

re-add --version and -V #183

Merged
merged 1 commit into from
Oct 31, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 28 additions & 7 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,29 +29,33 @@ static HTML_FILES: &[&str] = &["htm", "html"];
#[derive(FromArgs, PartialEq, Debug)]
/// A command-line tool to find broken links in your static site.
struct Cli {
/// the static file path to check.
/// the static file path to check
///
/// This will be assumed to be the root path of your server as well, so
/// href="/foo" will resolve to that folder's subfolder foo.
/// href="/foo" will resolve to that folder's subfolder foo
#[argh(positional)]
base_path: Option<PathBuf>,

/// how many threads to use, default is to try and saturate CPU.
/// how many threads to use, default is to try and saturate CPU
#[argh(option, short = 'j', long = "jobs")]
threads: Option<usize>,

/// whether to check for valid anchor references.
/// whether to check for valid anchor references
#[argh(switch)]
check_anchors: bool,

/// path to directory of markdown files to use for reporting errors.
/// path to directory of markdown files to use for reporting errors
#[argh(option, long = "sources")]
sources_path: Option<PathBuf>,

/// enable specialized output for GitHub actions.
/// enable specialized output for GitHub actions
#[argh(switch)]
github_actions: bool,

/// print version information and exit
#[argh(switch, short = 'V')]
version: bool,

#[argh(subcommand)]
subcommand: Option<Subcommand>,
}
Expand Down Expand Up @@ -125,8 +129,14 @@ fn main() -> Result<(), Error> {
sources_path,
github_actions,
subcommand,
version,
} = argh::from_env();

if version {
println!("hyperlink {}", env!("CARGO_PKG_VERSION"));
return Ok(());
}

rayon::ThreadPoolBuilder::new()
// most of the work we do is kind of I/O bound. rayon assumes CPU-heavy workload. we could
// look into tokio-uring at some point, but it seems like a hassle wrt ownership
Expand Down Expand Up @@ -658,6 +668,17 @@ $"#,
site.close().unwrap();
}

#[test]
fn test_version() {
let mut cmd = Command::cargo_bin("hyperlink").unwrap();
cmd.arg("--version");

cmd.assert()
.success()
.code(0)
.stdout(predicate::str::contains("hyperlink "));
}

#[test]
fn test_no_args() {
let mut cmd = Command::cargo_bin("hyperlink").unwrap();
Expand All @@ -667,7 +688,7 @@ $"#,
.code(1)
.stdout(predicate::str::contains(
"\
Usage: hyperlink [<base_path>] [-j <jobs>] [--check-anchors] [--sources <sources>] [--github-actions] [<command>] [<args>]\
Usage: hyperlink [<base_path>] [-j <jobs>] [--check-anchors] [--sources <sources>] [--github-actions] [-V] [<command>] [<args>]\
",
));
}
Expand Down