Skip to content

Commit

Permalink
Prepend program name to prompts, help text
Browse files Browse the repository at this point in the history
Before asking the user anything,
remind them which program is asking.
This is most helpful in pipelines.

Also, the --help text now uses the actual program name
instead of always `trash`.

This mimics GNU rm -- including the space *before* the colon.
  • Loading branch information
ninedotnine committed May 24, 2022
1 parent b5d9bfa commit 7547703
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
4 changes: 3 additions & 1 deletion source/trash/opts.d
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,9 @@ int parseOpts(ref string[] args) {
// This includes when no arguments are given
if (helpInfo.helpWanted || arglen < 2) {
// trash-d changes the formatting of the help text to be much nicer
string text = "Usage: \033[1mtrash [OPTIONS...] [FILES...]\033[0m\n";
string text = "Usage: \033[1m"
~ OPTS.prog_name
~ " [OPTIONS...] [FILES...]\033[0m\n";
OutBuffer buf = new OutBuffer();
defaultGetoptFormatter(buf, text, helpInfo.options, "\t%*s %*s\t%*s%s\x0a");
writefln("%s\n\n%s\n%s", VER_TEXT, buf, COPY_TEXT);
Expand Down
2 changes: 1 addition & 1 deletion source/trash/util.d
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ int ferr(Char, A...)(in Char[] fmt, A args) {
Prompts the user for a yes or no input, defaulting to no.
*/
bool prompt(Char, A...)(in Char[] fmt, A args) {
writef("Are you sure you want to %s? [y/N] ", format(fmt, args));
writef(OPTS.prog_name ~ " : Are you sure you want to %s? [y/N] ", format(fmt, args));
string input = stdin.readln().strip().toLower();
return input == "y" || input == "yes";
}
Expand Down

0 comments on commit 7547703

Please sign in to comment.