mirror of
https://github.com/uutils/sed.git
synced 2026-06-10 16:14:15 -07:00
Show usage when invoked without argments
* exit with code 1 when no arguments * add a test for no arguments. * Update test_sed.rs * cargo fmt * pass -n for missing script arguments test Issue: #274 PR: #409
This commit is contained in:
@@ -36,6 +36,15 @@ const USAGE: &str = "sed [OPTION]... [script] [file]...";
|
||||
#[uucore::main]
|
||||
pub fn uumain(args: impl uucore::Args) -> UResult<()> {
|
||||
let matches = uu_app().try_get_matches_from(args)?;
|
||||
|
||||
// Don't use arg_required_else_help when declaring command
|
||||
// as it exits with code 2 and we use it to check
|
||||
// default matches in tests.
|
||||
if !matches.args_present() {
|
||||
let _ = uu_app().print_help();
|
||||
std::process::exit(1);
|
||||
}
|
||||
|
||||
let (scripts, files) = get_scripts_files(&matches)?;
|
||||
let mut context = build_context(&matches);
|
||||
|
||||
|
||||
@@ -54,11 +54,20 @@ fn test_silent_alias() {
|
||||
#[test]
|
||||
fn test_missing_script_argument() {
|
||||
new_ucmd!()
|
||||
.args(&["-n"])
|
||||
.fails()
|
||||
.code_is(1)
|
||||
.stderr_contains("missing script");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_no_arguments() {
|
||||
new_ucmd!()
|
||||
.fails()
|
||||
.code_is(1)
|
||||
.stdout_contains("Stream editor for filtering and transforming text");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_positional_script_ok() {
|
||||
new_ucmd!().arg("l").succeeds().code_is(0);
|
||||
|
||||
Reference in New Issue
Block a user