Skip to content

Commit

Permalink
use warg 0.0.2
Browse files Browse the repository at this point in the history
  • Loading branch information
bbkane committed Oct 26, 2021
1 parent af848c9 commit b66d532
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 12 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ dist/
grabbit
grabbit.exe
tmp*
tags
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Grabbit

Grab subreddit images!! Very useful for getting nice wallpapers automatically - grabbit automatically skips images tagged NSFW. Designed to be easy to install/uninstall.
Grab subreddit images!! Very useful for getting nice wallpapers automatically - grabbit automatically skips images tagged NSFW. Designed to be easy to install/uninstall and [MIT licensed](./LICENSE).

## @bbkane's Setup

Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ go 1.16
require (
github.com/bbkane/glib v0.1.0
github.com/bbkane/logos v0.2.0
github.com/bbkane/warg v0.0.1
github.com/bbkane/warg v0.0.2
github.com/pkg/errors v0.9.1
github.com/vartanbeno/go-reddit/v2 v2.0.1
go.uber.org/multierr v1.6.0 // indirect
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ github.com/bbkane/logos v0.2.0 h1:gyXEBH4U/BVMcJKZy9YPXR/j4isanIL/2uZIlK+M6FU=
github.com/bbkane/logos v0.2.0/go.mod h1:GQ3XgWAmHzzMwZocaY6nDLHcYZmnL5yiOCfb5+R+pNk=
github.com/bbkane/warg v0.0.1 h1:dvlSse7vyqYLgx3aMlhtUz5Y3HjFyFTE61DMiXRJ3do=
github.com/bbkane/warg v0.0.1/go.mod h1:Nfm/5S1jKMY2nBT8Qr7TV/m1J0B4lCOtHhdgC1uvano=
github.com/bbkane/warg v0.0.2 h1:DCPkdWznr6q07U9F5/Gkf1XSw9YdU368bGSgQt2JSvE=
github.com/bbkane/warg v0.0.2/go.mod h1:Nfm/5S1jKMY2nBT8Qr7TV/m1J0B4lCOtHhdgC1uvano=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
Expand Down
31 changes: 21 additions & 10 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import (
c "github.com/bbkane/warg/command"
"github.com/bbkane/warg/configreader/yamlreader"
f "github.com/bbkane/warg/flag"
"github.com/bbkane/warg/help"
s "github.com/bbkane/warg/section"
v "github.com/bbkane/warg/value"
)
Expand Down Expand Up @@ -240,7 +241,7 @@ func grabSubreddit(ctx context.Context, logger *logos.Logger, client *reddit.Cli
}
}

func editConfig(passedFlags f.FlagValues) error {
func editConfig(passedFlags f.PassedFlags) error {
// retrieve types:
lumberJackLogger := &lumberjack.Logger{
Filename: passedFlags["--log-filename"].(string),
Expand Down Expand Up @@ -273,7 +274,7 @@ func editConfig(passedFlags f.FlagValues) error {
return nil
}

func grab(passedFlags f.FlagValues) error {
func grab(passedFlags f.PassedFlags) error {

// retrieve types:
lumberJackLogger := &lumberjack.Logger{
Expand Down Expand Up @@ -370,13 +371,13 @@ func getVersion() string {
return info.Main.Version
}

func printVersion(_ f.FlagValues) error {
func printVersion(_ f.PassedFlags) error {
fmt.Println(getVersion())
return nil
}

func main() {
grabCmd := c.NewCommand(
grabCmd := c.New(
"Grab images. Optionally use `config edit` first to create a config",
grab,
c.WithFlag(
Expand All @@ -385,27 +386,31 @@ func main() {
v.StringSlice,
f.Default("wallpapers"),
f.ConfigPath("subreddits[].name"),
f.Required(),
),
c.WithFlag(
"--subreddit-destination",
"Where to store the subreddit",
v.PathSlice,
f.Default("~/Pictures/grabbit"),
f.ConfigPath("subreddits[].destination"),
f.Required(),
),
c.WithFlag(
"--subreddit-timeframe",
"Take the top subreddits from this timeframe",
v.StringSlice,
f.Default("week"),
f.ConfigPath("subreddits[].timeframe"),
f.Required(),
),
c.WithFlag(
"--subreddit-limit",
"max number of links to try to download",
v.IntSlice,
f.Default("5"),
f.ConfigPath("subreddits[].limit"),
f.Required(),
),
)

Expand Down Expand Up @@ -440,7 +445,7 @@ grabbit grab --config-path ./grabbit.yaml

app := w.New(
"grabbit",
s.NewSection(
s.New(
"Get top images from subreddits",
s.AddCommand(
"grab",
Expand All @@ -458,40 +463,46 @@ grabbit grab --config-path ./grabbit.yaml
v.Path,
f.Default("~/.config/grabbit.jsonl"),
f.ConfigPath("lumberjacklogger.filename"),
f.Required(),
),
s.WithFlag(
"--log-maxage",
"max age before log rotation in days",
v.Int,
f.Default("30"),
f.ConfigPath("lumberjacklogger.maxage"),
f.Required(),
),
s.WithFlag(
"--log-maxbackups",
"num backups for the log",
v.Int,
f.Default("0"),
f.ConfigPath("lumberjacklogger.maxbackups"),
f.Required(),
),
s.WithFlag(
"--log-maxsize",
"max size of log in megabytes",
v.Int,
f.Default("5"),
f.ConfigPath("lumberjacklogger.maxsize"),
f.Required(),
),
s.WithSection(
"config",
"config commands",
"Config commands",
s.WithCommand(
"edit",
"Edit or create configuration file. Uses $EDITOR as a fallback",
"Edit or create configuration file.",
editConfig,
c.WithFlag(
"--editor",
"path to editor",
v.String,
f.Default("vi"),
f.EnvVars("EDITOR"),
f.Required(),
),
),
),
Expand All @@ -505,9 +516,9 @@ grabbit grab --config-path ./grabbit.yaml
w.OverrideHelp(
os.Stderr,
[]string{"-h", "--help"},
w.DefaultSectionHelp,
w.DefaultCommandHelp,
help.DefaultSectionHelp,
help.DefaultCommandHelp,
),
)
app.MustRun()
app.MustRun(os.Args, os.LookupEnv)
}

0 comments on commit b66d532

Please sign in to comment.