@@ -36,39 +36,45 @@ impl Options {
36
36
#[ allow( unused_results) ]
37
37
pub fn getopts ( args : & [ String ] ) -> Result < ( Options , Vec < String > ) , Misfire > {
38
38
let mut opts = getopts:: Options :: new ( ) ;
39
+
40
+ opts. optflag ( "v" , "version" , "display version of exa" ) ;
41
+ opts. optflag ( "?" , "help" , "show list of command-line options" ) ;
42
+
43
+ // Display options
39
44
opts. optflag ( "1" , "oneline" , "display one entry per line" ) ;
45
+ opts. optflag ( "G" , "grid" , "display entries in a grid view (default)" ) ;
46
+ opts. optflag ( "l" , "long" , "display extended details and attributes" ) ;
47
+ opts. optflag ( "R" , "recurse" , "recurse into directories" ) ;
48
+ opts. optflag ( "T" , "tree" , "recurse into subdirectories in a tree view" ) ;
49
+ opts. optflag ( "x" , "across" , "sort multi-column view entries across" ) ;
50
+
51
+ // Filtering and sorting options
52
+ opts. optflag ( "" , "group-directories-first" , "list directories before other files" ) ;
40
53
opts. optflag ( "a" , "all" , "show dot-files" ) ;
54
+ opts. optflag ( "d" , "list-dirs" , "list directories as regular files" ) ;
55
+ opts. optflag ( "r" , "reverse" , "reverse order of files" ) ;
56
+ opts. optopt ( "s" , "sort" , "field to sort by" , "WORD" ) ;
57
+
58
+ // Long view options
41
59
opts. optflag ( "b" , "binary" , "use binary prefixes in file sizes" ) ;
42
60
opts. optflag ( "B" , "bytes" , "list file sizes in bytes, without prefixes" ) ;
43
- opts. optflag ( "d" , "list-dirs" , "list directories as regular files" ) ;
44
61
opts. optflag ( "g" , "group" , "show group as well as user" ) ;
45
- opts. optflag ( "G" , "grid" , "display entries in a grid view (default)" ) ;
46
- opts. optflag ( "" , "group-directories-first" , "list directories before other files" ) ;
47
62
opts. optflag ( "h" , "header" , "show a header row at the top" ) ;
48
63
opts. optflag ( "H" , "links" , "show number of hard links" ) ;
49
64
opts. optflag ( "i" , "inode" , "show each file's inode number" ) ;
50
- opts. optflag ( "l" , "long" , "display extended details and attributes" ) ;
51
65
opts. optopt ( "L" , "level" , "maximum depth of recursion" , "DEPTH" ) ;
52
66
opts. optflag ( "m" , "modified" , "display timestamp of most recent modification" ) ;
53
- opts. optflag ( "r" , "reverse" , "reverse order of files" ) ;
54
- opts. optflag ( "R" , "recurse" , "recurse into directories" ) ;
55
- opts. optopt ( "s" , "sort" , "field to sort by" , "WORD" ) ;
56
67
opts. optflag ( "S" , "blocks" , "show number of file system blocks" ) ;
57
68
opts. optopt ( "t" , "time" , "which timestamp to show for a file" , "WORD" ) ;
58
- opts. optflag ( "T" , "tree" , "recurse into subdirectories in a tree view" ) ;
59
69
opts. optflag ( "u" , "accessed" , "display timestamp of last access for a file" ) ;
60
70
opts. optflag ( "U" , "created" , "display timestamp of creation for a file" ) ;
61
- opts. optflag ( "x" , "across" , "sort multi-column view entries across" ) ;
62
-
63
- opts. optflag ( "" , "version" , "display version of exa" ) ;
64
- opts. optflag ( "?" , "help" , "show list of command-line options" ) ;
65
71
66
72
if cfg ! ( feature="git" ) {
67
73
opts. optflag ( "" , "git" , "show git status" ) ;
68
74
}
69
75
70
76
if xattr:: ENABLED {
71
- opts. optflag ( "@" , "extended" , "display extended attribute keys and sizes in long (-l) output " ) ;
77
+ opts. optflag ( "@" , "extended" , "display extended attribute keys and sizes" ) ;
72
78
}
73
79
74
80
let matches = match opts. parse ( args) {
@@ -77,7 +83,25 @@ impl Options {
77
83
} ;
78
84
79
85
if matches. opt_present ( "help" ) {
80
- return Err ( Misfire :: Help ( opts. usage ( "Usage:\n exa [options] [files...]" ) ) ) ;
86
+ let mut help_string = "Usage:\n exa [options] [files...]\n " . to_owned ( ) ;
87
+
88
+ if !matches. opt_present ( "long" ) {
89
+ help_string. push_str ( OPTIONS ) ;
90
+ }
91
+
92
+ help_string. push_str ( LONG_OPTIONS ) ;
93
+
94
+ if cfg ! ( feature="git" ) {
95
+ help_string. push_str ( GIT_HELP ) ;
96
+ help_string. push ( '\n' ) ;
97
+ }
98
+
99
+ if xattr:: ENABLED {
100
+ help_string. push_str ( EXTENDED_HELP ) ;
101
+ help_string. push ( '\n' ) ;
102
+ }
103
+
104
+ return Err ( Misfire :: Help ( help_string) ) ;
81
105
}
82
106
else if matches. opt_present ( "version" ) {
83
107
return Err ( Misfire :: Version ) ;
@@ -569,6 +593,42 @@ impl fmt::Display for Misfire {
569
593
}
570
594
}
571
595
596
+ static OPTIONS : & ' static str = r##"
597
+ DISPLAY OPTIONS
598
+ -1, --oneline display one entry per line
599
+ -G, --grid display entries in a grid view (default)
600
+ -l, --long display extended details and attributes
601
+ -R, --recurse recurse into directories
602
+ -T, --tree recurse into subdirectories in a tree view
603
+ -x, --across sort multi-column view entries across
604
+
605
+ FILTERING AND SORTING OPTIONS
606
+ -a, --all show dot-files
607
+ -d, --list-dirs list directories as regular files
608
+ -r, --reverse reverse order of files
609
+ -s, --sort WORD field to sort by
610
+ --group-directories-first list directories before other files
611
+ "## ;
612
+
613
+ static LONG_OPTIONS : & ' static str = r##"
614
+ LONG VIEW OPTIONS
615
+ -b, --binary use binary prefixes in file sizes
616
+ -B, --bytes list file sizes in bytes, without prefixes
617
+ -g, --group show group as well as user
618
+ -h, --header show a header row at the top
619
+ -H, --links show number of hard links
620
+ -i, --inode show each file's inode number
621
+ -L, --level DEPTH maximum depth of recursion
622
+ -m, --modified display timestamp of most recent modification
623
+ -S, --blocks show number of file system blocks
624
+ -t, --time WORD which timestamp to show for a file
625
+ -u, --accessed display timestamp of last access for a file
626
+ -U, --created display timestamp of creation for a file
627
+ "## ;
628
+
629
+ static GIT_HELP : & ' static str = r##" -@, --extended display extended attribute keys and sizes"## ;
630
+ static EXTENDED_HELP : & ' static str = r##" --git show git status for files"## ;
631
+
572
632
573
633
#[ cfg( test) ]
574
634
mod test {
0 commit comments