@@ -20,82 +20,27 @@ use std::fs;
20
20
use std:: os:: unix:: fs:: MetadataExt ;
21
21
use uucore:: display:: Quotable ;
22
22
use uucore:: error:: { UResult , USimpleError } ;
23
- use uucore:: format_usage;
23
+ use uucore:: { format_usage, help_about , help_section } ;
24
24
25
+ const ABOUT : & str = help_about ! ( "test.md" ) ;
26
+
27
+ // The help_usage method replaces util name (the first word) with {}.
28
+ // And, The format_usage method replaces {} with execution_phrase ( e.g. test or [ ).
29
+ // However, This test command has two util names.
30
+ // So, we use test or [ instead of {} so that the usage string is correct.
25
31
const USAGE : & str = "\
26
- {} EXPRESSION
27
- {}
28
- [ EXPRESSION ]
29
- [ ]
30
- [ OPTION";
32
+ test EXPRESSION
33
+ test
34
+ [ EXPRESSION ]
35
+ [ ]
36
+ [ OPTION" ;
31
37
32
38
// We use after_help so that this comes after the usage string (it would come before if we used about)
33
- const AFTER_HELP : & str = "
34
- Exit with the status determined by EXPRESSION.
35
-
36
- An omitted EXPRESSION defaults to false. Otherwise,
37
- EXPRESSION is true or false and sets exit status. It is one of:
38
-
39
- ( EXPRESSION ) EXPRESSION is true
40
- ! EXPRESSION EXPRESSION is false
41
- EXPRESSION1 -a EXPRESSION2 both EXPRESSION1 and EXPRESSION2 are true
42
- EXPRESSION1 -o EXPRESSION2 either EXPRESSION1 or EXPRESSION2 is true
43
-
44
- -n STRING the length of STRING is nonzero
45
- STRING equivalent to -n STRING
46
- -z STRING the length of STRING is zero
47
- STRING1 = STRING2 the strings are equal
48
- STRING1 != STRING2 the strings are not equal
49
-
50
- INTEGER1 -eq INTEGER2 INTEGER1 is equal to INTEGER2
51
- INTEGER1 -ge INTEGER2 INTEGER1 is greater than or equal to INTEGER2
52
- INTEGER1 -gt INTEGER2 INTEGER1 is greater than INTEGER2
53
- INTEGER1 -le INTEGER2 INTEGER1 is less than or equal to INTEGER2
54
- INTEGER1 -lt INTEGER2 INTEGER1 is less than INTEGER2
55
- INTEGER1 -ne INTEGER2 INTEGER1 is not equal to INTEGER2
56
-
57
- FILE1 -ef FILE2 FILE1 and FILE2 have the same device and inode numbers
58
- FILE1 -nt FILE2 FILE1 is newer (modification date) than FILE2
59
- FILE1 -ot FILE2 FILE1 is older than FILE2
60
-
61
- -b FILE FILE exists and is block special
62
- -c FILE FILE exists and is character special
63
- -d FILE FILE exists and is a directory
64
- -e FILE FILE exists
65
- -f FILE FILE exists and is a regular file
66
- -g FILE FILE exists and is set-group-ID
67
- -G FILE FILE exists and is owned by the effective group ID
68
- -h FILE FILE exists and is a symbolic link (same as -L)
69
- -k FILE FILE exists and has its sticky bit set
70
- -L FILE FILE exists and is a symbolic link (same as -h)
71
- -N FILE FILE exists and has been modified since it was last read
72
- -O FILE FILE exists and is owned by the effective user ID
73
- -p FILE FILE exists and is a named pipe
74
- -r FILE FILE exists and read permission is granted
75
- -s FILE FILE exists and has a size greater than zero
76
- -S FILE FILE exists and is a socket
77
- -t FD file descriptor FD is opened on a terminal
78
- -u FILE FILE exists and its set-user-ID bit is set
79
- -w FILE FILE exists and write permission is granted
80
- -x FILE FILE exists and execute (or search) permission is granted
81
-
82
- Except for -h and -L, all FILE-related tests dereference symbolic links.
83
- Beware that parentheses need to be escaped (e.g., by backslashes) for shells.
84
- INTEGER may also be -l STRING, which evaluates to the length of STRING.
85
-
86
- NOTE: Binary -a and -o are inherently ambiguous. Use 'test EXPR1 && test
87
- EXPR2' or 'test EXPR1 || test EXPR2' instead.
88
-
89
- NOTE: [ honors the --help and --version options, but test does not.
90
- test treats each of those as it treats any other nonempty STRING.
91
-
92
- NOTE: your shell may have its own version of test and/or [, which usually supersedes
93
- the version described here. Please refer to your shell's documentation
94
- for details about the options it supports." ;
95
-
96
- const ABOUT : & str = "Check file types and compare values." ;
39
+ const AFTER_HELP : & str = help_section ! ( "after help" , "test.md" ) ;
97
40
98
41
pub fn uu_app ( ) -> Command {
42
+ // Disable printing of -h and -v as valid alternatives for --help and --version,
43
+ // since we don't recognize -h and -v as help/version flags.
99
44
Command :: new ( uucore:: util_name ( ) )
100
45
. version ( crate_version ! ( ) )
101
46
. about ( ABOUT )
@@ -112,15 +57,7 @@ pub fn uumain(mut args: impl uucore::Args) -> UResult<()> {
112
57
if binary_name. ends_with ( '[' ) {
113
58
// If invoked as [ we should recognize --help and --version (but not -h or -v)
114
59
if args. len ( ) == 1 && ( args[ 0 ] == "--help" || args[ 0 ] == "--version" ) {
115
- // Let clap pretty-print help and version
116
- Command :: new ( binary_name)
117
- . version ( crate_version ! ( ) )
118
- . about ( ABOUT )
119
- . override_usage ( format_usage ( USAGE ) )
120
- . after_help ( AFTER_HELP )
121
- // Disable printing of -h and -v as valid alternatives for --help and --version,
122
- // since we don't recognize -h and -v as help/version flags.
123
- . get_matches_from ( std:: iter:: once ( program) . chain ( args. into_iter ( ) ) ) ;
60
+ uu_app ( ) . get_matches_from ( std:: iter:: once ( program) . chain ( args. into_iter ( ) ) ) ;
124
61
return Ok ( ( ) ) ;
125
62
}
126
63
// If invoked via name '[', matching ']' must be in the last arg
0 commit comments