uutils / uutils/coreutils

UError: Output of Try --help for more information uses full path for util name

Open
#11,366 7 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Rust
Stars
24.1k
Forks
2k
Avg merge
1d 5h
Merged PRs (30d)
365

Description

When one sets the UError usage flag, the error message is appended by:
Try 'util --help' for more information.

But this looks very odd when one starts the utility from somewhere else:

cmp: missing operand after 'cmp'
Try 'Development/diffutils_fork/target/debug/diffutils cmp --help' for more information.

Would it not be better to just output the util name, like:

cmp: missing operand after 'cmp'
Try 'cmp --help' for more information.

This is part of the main macro and could easily be changed:

            // disable rust signal handlers (otherwise processes don't dump core after e.g. one SIGSEGV)
            #[cfg(all(#signals, unix))]
            uucore::disable_rust_signal_handlers().expect("Disabling rust signal handlers failed");
            let result = uumain(args);
            match result {
                Ok(()) => uucore::error::get_exit_code(),
                Err(e) => {
                    let s = format!("{e}");
                    if s != "" {
                        uucore::show_error!("{s}");
                    }
                    if e.usage() {
                        use std::io::{stderr, Write as _};
                        let _ = writeln!(stderr(),"Try '{} --help' for more information.", uucore::execution_phrase());
              -->       // change: let _ = writeln!(stderr(),"Try '{} --help' for more information.", uucore::util_name());
                        // or even better to use translate, this makes it also consistent with errors clap returns
              -->       // let msg_try = uucore::translate!("clap-error-help-suggestion", "command" => uucore::util_name());
                        // let _ = writeln!(stderr(),"{msg_try}");
                    }
                    e.code()
                }
            }

If it is fine with you I would create the PR to use uucore::util_name() and translate!.

This would result in:

cmp: missing operand after 'cmp'
For more information, try 'cmp --help'.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start at the main error-handling macro shown in the issue and inspect the existing uucore::execution_phrase(), uucore::util_name(), and translate! helpers. Change the usage suggestion to use the utility name and the translated wording, then verify that an invocation from another directory reports only the command name in the help hint.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
cli
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
55/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.