@@ -11,7 +11,7 @@ import (
1111 "go.bbkane.com/warg/value"
1212)
1313
14- func main () {
14+ func app () * warg. App {
1515 appFooter := `Examples (assuming BASH-like shell):
1616
1717 # Grab from passed flags
@@ -28,29 +28,29 @@ func main() {
2828 grabbit grab
2929`
3030 grabCmd := command .New (
31- command . HelpShort ( "Grab images. Optionally use `config edit` first to create a config" ) ,
31+ "Grab images. Optionally use `config edit` first to create a config" ,
3232 grab ,
3333 command .Flag (
34- flag . Name ( "--subreddit-name" ) ,
35- flag . HelpShort ( "subreddit to grab" ) ,
34+ "--subreddit-name" ,
35+ "subreddit to grab" ,
3636 value .StringSlice ,
3737 flag .Alias ("-sn" ),
3838 flag .Default ("earthporn" , "wallpapers" ),
3939 flag .ConfigPath ("subreddits[].name" ),
4040 flag .Required (),
4141 ),
4242 command .Flag (
43- flag . Name ( "--subreddit-destination" ) ,
44- flag . HelpShort ( "Where to store the subreddit" ) ,
43+ "--subreddit-destination" ,
44+ "Where to store the subreddit" ,
4545 value .PathSlice ,
4646 flag .Alias ("-sd" ),
4747 flag .Default ("." , "." ),
4848 flag .ConfigPath ("subreddits[].destination" ),
4949 flag .Required (),
5050 ),
5151 command .Flag (
52- flag . Name ( "--subreddit-timeframe" ) ,
53- flag . HelpShort ( "Take the top subreddits from this timeframe" ) ,
52+ "--subreddit-timeframe" ,
53+ "Take the top subreddits from this timeframe" ,
5454 // TODO: this should be a StringEnumSlice once that's implemented
5555 value .StringSlice ,
5656 flag .Alias ("-st" ),
@@ -59,8 +59,8 @@ func main() {
5959 flag .Required (),
6060 ),
6161 command .Flag (
62- flag . Name ( "--subreddit-limit" ) ,
63- flag . HelpShort ( "max number of links to try to download" ) ,
62+ "--subreddit-limit" ,
63+ "max number of links to try to download" ,
6464 value .IntSlice ,
6565 flag .Alias ("-sl" ),
6666 flag .Default ("2" , "3" ),
@@ -70,67 +70,66 @@ func main() {
7070 )
7171
7272 app := warg .New (
73- "grabbit" ,
7473 section .New (
75- section . HelpShort ( "Get top images from subreddits" ) ,
74+ "Get top images from subreddits" ,
7675 section .ExistingCommand (
77- command . Name ( "grab" ) ,
76+ "grab" ,
7877 grabCmd ,
7978 ),
8079 section .Footer (appFooter ),
8180 section .Command (
82- command . Name ( "version" ) ,
83- command . HelpShort ( "Print version" ) ,
81+ "version" ,
82+ "Print version" ,
8483 printVersion ,
8584 ),
8685 section .Flag (
87- flag . Name ( "--color" ) ,
88- flag . HelpShort ( "Use colorized output" ) ,
86+ "--color" ,
87+ "Use colorized output" ,
8988 value .StringEnum ("true" , "false" , "auto" ),
9089 flag .Default ("auto" ),
9190 ),
9291 section .Flag (
93- flag . Name ( "--log-filename" ) ,
94- flag . HelpShort ( "log filename" ) ,
92+ "--log-filename" ,
93+ "log filename" ,
9594 value .Path ,
9695 flag .Default ("~/.config/grabbit.jsonl" ),
9796 flag .ConfigPath ("lumberjacklogger.filename" ),
9897 flag .Required (),
9998 ),
10099 section .Flag (
101- flag . Name ( "--log-maxage" ) ,
102- flag . HelpShort ( "max age before log rotation in days" ) ,
100+ "--log-maxage" ,
101+ "max age before log rotation in days" ,
103102 value .Int ,
104103 flag .Default ("30" ),
105104 flag .ConfigPath ("lumberjacklogger.maxage" ),
106105 flag .Required (),
107106 ),
108107 section .Flag (
109- flag . Name ( "--log-maxbackups" ) ,
110- flag . HelpShort ( "num backups for the log" ) ,
108+ "--log-maxbackups" ,
109+ "num backups for the log" ,
111110 value .Int ,
112111 flag .Default ("0" ),
113112 flag .ConfigPath ("lumberjacklogger.maxbackups" ),
114113 flag .Required (),
115114 ),
116115 section .Flag (
117- flag . Name ( "--log-maxsize" ) ,
118- flag . HelpShort ( "max size of log in megabytes" ) ,
116+ "--log-maxsize" ,
117+ "max size of log in megabytes" ,
119118 value .Int ,
120119 flag .Default ("5" ),
121120 flag .ConfigPath ("lumberjacklogger.maxsize" ),
122121 flag .Required (),
123122 ),
124123 section .Section (
125- section . Name ( "config" ) ,
126- section . HelpShort ( "Config commands" ) ,
124+ "config" ,
125+ "Config commands" ,
127126 section .Command (
128- command . Name ( "edit" ) ,
129- command . HelpShort ( "Edit or create configuration file." ) ,
127+ "edit" ,
128+ "Edit or create configuration file." ,
130129 editConfig ,
131130 command .Flag (
132- flag . Name ( "--editor" ) ,
133- flag . HelpShort ( "path to editor" ) ,
131+ "--editor" ,
132+ "path to editor" ,
134133 value .String ,
135134 flag .Alias ("-e" ),
136135 flag .Default ("vi" ),
@@ -141,12 +140,17 @@ func main() {
141140 ),
142141 ),
143142 warg .ConfigFlag (
144- flag . Name ( "--config" ) ,
143+ "--config" ,
145144 yamlreader .New ,
146145 "config filepath" ,
147146 flag .Alias ("-c" ),
148147 flag .Default ("~/.config/grabbit.yaml" ),
149148 ),
149+ warg .SkipValidation (),
150150 )
151- app .MustRun (os .Args , os .LookupEnv )
151+ return & app
152+ }
153+
154+ func main () {
155+ app ().MustRun (os .Args , os .LookupEnv )
152156}
0 commit comments