Skip to content

Commit ceafa99

Browse files
committed
bump warg
1 parent f56ec73 commit ceafa99

File tree

4 files changed

+51
-34
lines changed

4 files changed

+51
-34
lines changed

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ require (
1212
github.com/pkg/errors v0.9.1
1313
github.com/vartanbeno/go-reddit/v2 v2.0.1
1414
go.bbkane.com/logos v0.3.0
15-
go.bbkane.com/warg v0.0.12
15+
go.bbkane.com/warg v0.0.13
1616
go.uber.org/atomic v1.9.0 // indirect
1717
go.uber.org/multierr v1.7.0 // indirect
1818
go.uber.org/zap v1.20.0

go.sum

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,8 @@ go.bbkane.com/logos v0.3.0 h1:NJZAoUp0dYW5Kl5A2Zxw+uGKGwiG/t7CgxGaM167+28=
148148
go.bbkane.com/logos v0.3.0/go.mod h1:IqUA0K5saG+eDGkY9LQOfJYO1nJOF3nnq8AWeHuViIU=
149149
go.bbkane.com/warg v0.0.12 h1:+Jwf70ey/dlPCDmEREJSd045p1eGTX7r482bT2v3Cwc=
150150
go.bbkane.com/warg v0.0.12/go.mod h1:kfv+iD8YFvnpqv9bUR2zp1PYTHHJWesIikcRcuJTgIc=
151+
go.bbkane.com/warg v0.0.13 h1:BlnLM/gvELYqMpgAlAZCHLDJXKq1/uXKx1tLa+NtqXA=
152+
go.bbkane.com/warg v0.0.13/go.mod h1:kfv+iD8YFvnpqv9bUR2zp1PYTHHJWesIikcRcuJTgIc=
151153
go.opencensus.io v0.21.0/go.mod h1:mSImk1erAIZhrmZN+AvHh14ztQfjbGwt4TtuofqLduU=
152154
go.opencensus.io v0.22.0/go.mod h1:+kGneAE2xo2IficOXnaByMWTGM9T73dGwxeWcUqIpI8=
153155
go.opencensus.io v0.22.2/go.mod h1:yxeiOL68Rb0Xd1ddK5vPZ/oVn4vY4Ynel7k9FzqtOIw=

main.go

Lines changed: 37 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -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
}

main_test.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
package main
2+
3+
import (
4+
"testing"
5+
)
6+
7+
func TestBuildApp(t *testing.T) {
8+
if err := app().Validate(); err != nil {
9+
t.Fatal(err)
10+
}
11+
}

0 commit comments

Comments
 (0)