Improve help text and error handling
This commit is contained in:
parent
175899001a
commit
1dffe5f98a
1
shout-rs/.gitignore
vendored
Normal file
1
shout-rs/.gitignore
vendored
Normal file
|
|
@ -0,0 +1 @@
|
||||||
|
target/
|
||||||
|
|
@ -37,18 +37,55 @@ struct TestOpts {
|
||||||
parallel: bool,
|
parallel: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn print_usage() {
|
||||||
|
eprintln!("Usage: shout [options] [command]");
|
||||||
|
eprintln!();
|
||||||
|
eprintln!("$ shell output tester");
|
||||||
|
eprintln!();
|
||||||
|
eprintln!("Options:");
|
||||||
|
eprintln!(" -V, --version output the version number");
|
||||||
|
eprintln!(" -h, --help display help for command");
|
||||||
|
eprintln!();
|
||||||
|
eprintln!("Commands:");
|
||||||
|
eprintln!(" test [options] [files...] Run .shout test files");
|
||||||
|
eprintln!(" version Print the version");
|
||||||
|
eprintln!(" example Print an example .shout file");
|
||||||
|
eprintln!(" help [command] display help for command");
|
||||||
|
}
|
||||||
|
|
||||||
|
fn print_test_help() {
|
||||||
|
eprintln!("Usage: shout test [options] [files...]");
|
||||||
|
eprintln!();
|
||||||
|
eprintln!("Run .shout test files");
|
||||||
|
eprintln!();
|
||||||
|
eprintln!("Arguments:");
|
||||||
|
eprintln!(" files Files or directories to test");
|
||||||
|
eprintln!();
|
||||||
|
eprintln!("Options:");
|
||||||
|
eprintln!(" -u, --update Rewrite expected output in-place with actual output");
|
||||||
|
eprintln!(" -k, --keep Keep temp directories after run");
|
||||||
|
eprintln!(" --clean-env Start with empty environment");
|
||||||
|
eprintln!(" --path <path> Prepend <path> to PATH (repeatable)");
|
||||||
|
eprintln!(" --timeout <dur> Per-command timeout (default: 10s)");
|
||||||
|
eprintln!(" -v, --verbose Print each command as it runs");
|
||||||
|
eprintln!(" --port-from <n> Auto-assign $PORT starting from <n> (default: 5400)");
|
||||||
|
eprintln!(" -t, --filter <pattern> Only run files matching <pattern> (substring match)");
|
||||||
|
eprintln!(" --parallel Run files in parallel");
|
||||||
|
eprintln!(" -h, --help display help for command");
|
||||||
|
}
|
||||||
|
|
||||||
fn parse_args() -> Option<(&'static str, TestOpts)> {
|
fn parse_args() -> Option<(&'static str, TestOpts)> {
|
||||||
let args: Vec<String> = std::env::args().skip(1).collect();
|
let args: Vec<String> = std::env::args().skip(1).collect();
|
||||||
|
|
||||||
if args.is_empty() {
|
if args.is_empty() || args[0] == "-h" || args[0] == "--help" || args[0] == "help" {
|
||||||
eprintln!("Usage: shout <test|example|version> [options]");
|
print_usage();
|
||||||
process::exit(1);
|
process::exit(if args.is_empty() { 1 } else { 0 });
|
||||||
}
|
}
|
||||||
|
|
||||||
let subcommand = args[0].as_str();
|
let subcommand = args[0].as_str();
|
||||||
|
|
||||||
match subcommand {
|
match subcommand {
|
||||||
"version" => {
|
"-V" | "--version" | "version" => {
|
||||||
println!("{VERSION}");
|
println!("{VERSION}");
|
||||||
process::exit(0);
|
process::exit(0);
|
||||||
}
|
}
|
||||||
|
|
@ -59,6 +96,7 @@ fn parse_args() -> Option<(&'static str, TestOpts)> {
|
||||||
"test" => {}
|
"test" => {}
|
||||||
other => {
|
other => {
|
||||||
eprintln!("Unknown command: {other}");
|
eprintln!("Unknown command: {other}");
|
||||||
|
eprintln!("Run 'shout --help' for usage");
|
||||||
process::exit(1);
|
process::exit(1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -79,6 +117,10 @@ fn parse_args() -> Option<(&'static str, TestOpts)> {
|
||||||
let mut i = 1;
|
let mut i = 1;
|
||||||
while i < args.len() {
|
while i < args.len() {
|
||||||
match args[i].as_str() {
|
match args[i].as_str() {
|
||||||
|
"-h" | "--help" => {
|
||||||
|
print_test_help();
|
||||||
|
process::exit(0);
|
||||||
|
}
|
||||||
"-u" | "--update" => opts.update = true,
|
"-u" | "--update" => opts.update = true,
|
||||||
"-k" | "--keep" => opts.keep = true,
|
"-k" | "--keep" => opts.keep = true,
|
||||||
"--clean-env" => opts.clean_env = true,
|
"--clean-env" => opts.clean_env = true,
|
||||||
|
|
|
||||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue
Block a user