Skip to content

Commit

Permalink
Merge pull request #38 from bbkane/bbkane/update-warg
Browse files Browse the repository at this point in the history
bbkane/update warg
  • Loading branch information
bbkane authored Jan 7, 2025
2 parents a01e92a + d96459c commit 4c04078
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 19 deletions.
7 changes: 4 additions & 3 deletions config.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"go.bbkane.com/logos"
"go.bbkane.com/warg/command"
"go.bbkane.com/warg/help/common"
"go.bbkane.com/warg/path"
"go.uber.org/zap"
lumberjack "gopkg.in/natefinch/lumberjack.v2"
)
Expand All @@ -20,7 +21,7 @@ var embeddedConfig []byte
func editConfig(ctx command.Context) error {
// retrieve types:
lumberJackLogger := &lumberjack.Logger{
Filename: ctx.Flags["--log-filename"].(string),
Filename: ctx.Flags["--log-filename"].(path.Path).MustExpand(),
MaxAge: ctx.Flags["--log-maxage"].(int),
MaxBackups: ctx.Flags["--log-maxbackups"].(int),
MaxSize: ctx.Flags["--log-maxsize"].(int),
Expand All @@ -37,7 +38,7 @@ func editConfig(ctx command.Context) error {
logger := logos.New(zapLogger, color)
logger.LogOnPanic()

configPath, configPathExists := ctx.Flags["--config"].(string)
configPath, configPathExists := ctx.Flags["--config"]
if !configPathExists {
err := errors.New("must path --config")
logger.Errorw(
Expand All @@ -48,7 +49,7 @@ func editConfig(ctx command.Context) error {
}
editor := ctx.Flags["--editor"].(string)

err = glib.EditFile(embeddedConfig, configPath, editor)
err = glib.EditFile(embeddedConfig, configPath.(path.Path).MustExpand(), editor)
if err != nil {
logger.Errorw(
"Unable to edit config",
Expand Down
6 changes: 3 additions & 3 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
module go.bbkane.com/grabbit/v4

go 1.22
go 1.23

require (
github.com/bbkane/glib v0.1.1
github.com/pkg/errors v0.9.1
github.com/vartanbeno/go-reddit/v2 v2.0.1
go.bbkane.com/logos v0.4.0
go.bbkane.com/warg v0.0.23
go.bbkane.com/warg v0.0.26
go.uber.org/zap v1.27.0
gopkg.in/natefinch/lumberjack.v2 v2.2.1
)
Expand All @@ -28,6 +28,6 @@ require (
go.uber.org/multierr v1.11.0 // indirect
golang.org/x/net v0.26.0 // indirect
golang.org/x/oauth2 v0.21.0 // indirect
golang.org/x/sys v0.21.0 // indirect
golang.org/x/sys v0.29.0 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
)
4 changes: 4 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ go.bbkane.com/logos v0.4.0 h1:7k6mQiSK7ZXJa/OGZATxCeNgZX9D0qPx+NwWwEb2NwA=
go.bbkane.com/logos v0.4.0/go.mod h1:sxAz5z3jxSA3GQ2z6NL7wmGXISGQKCuA7XM0DGY+fKE=
go.bbkane.com/warg v0.0.23 h1:Eh0sEXkl+GudyPLHLJGzAOAhzFnnzxanxLXi1hrOKhU=
go.bbkane.com/warg v0.0.23/go.mod h1:fuaPJpxxTab3Yf8GFI3c0O6ou09UE7tdcXY0XTB2hRc=
go.bbkane.com/warg v0.0.26 h1:jaNPwisZLuD9Ga3yWKPLWFmsBt1lh9eLoSkJEXqgtHU=
go.bbkane.com/warg v0.0.26/go.mod h1:xttS0YH1LCuFurEvk2mu2jn9DCKYS8T8sokxNg2JARo=
go.uber.org/goleak v1.3.0 h1:2K3zAYmnTNqV73imy9J1T3WC+gmCePx2hEGkimedGto=
go.uber.org/goleak v1.3.0/go.mod h1:CoHD4mav9JJNrW/WLlf7HGZPjdw8EucARQHekz1X6bE=
go.uber.org/multierr v1.11.0 h1:blXXJkSxSSfBVBlC76pxqeO+LN3aDfLQo+309xJstO0=
Expand All @@ -54,6 +56,8 @@ golang.org/x/sync v0.0.0-20181221193216-37e7f081c4d4/go.mod h1:RxMgew5VJxzue5/jJ
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.21.0 h1:rF+pYz3DAGSQAxAu1CbC7catZg4ebC4UIeIhKxBZvws=
golang.org/x/sys v0.21.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/sys v0.29.0 h1:TPYlXGxvx1MGTn2GiZDhnjPA9wZzZeGKHHmKhHYvgaU=
golang.org/x/sys v0.29.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
google.golang.org/appengine v1.4.0/go.mod h1:xpcJRLb0r/rnEns0DIKYYv+WjYCduHsrkT7/EB5XEv4=
Expand Down
25 changes: 16 additions & 9 deletions grab.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"go.bbkane.com/logos"
"go.bbkane.com/warg/command"
"go.bbkane.com/warg/help/common"
"go.bbkane.com/warg/path"
"go.uber.org/zap"
lumberjack "gopkg.in/natefinch/lumberjack.v2"
)
Expand Down Expand Up @@ -293,16 +294,22 @@ func testRedditConnection(logger *logos.Logger) error {
// Test connection
conn, err := tls.DialWithDialer(
&net.Dialer{
Timeout: time.Second * 30,
Cancel: nil,
Control: nil,
ControlContext: nil,
Deadline: time.Time{},
LocalAddr: nil,
DualStack: false,
FallbackDelay: 0,
KeepAlive: 0,
Resolver: nil,
Cancel: nil,
Control: nil,
ControlContext: nil,
KeepAliveConfig: net.KeepAliveConfig{
Enable: false,
Idle: 0,
Interval: 0,
Count: 0,
},
LocalAddr: nil,
Resolver: nil,
Timeout: time.Second * 30,
},
"tcp",
net.JoinHostPort("reddit.com", "443"),
Expand Down Expand Up @@ -336,7 +343,7 @@ func grab(ctx command.Context) error {

// retrieve types:
lumberJackLogger := &lumberjack.Logger{
Filename: ctx.Flags["--log-filename"].(string),
Filename: ctx.Flags["--log-filename"].(path.Path).MustExpand(),
MaxAge: ctx.Flags["--log-maxage"].(int),
MaxBackups: ctx.Flags["--log-maxbackups"].(int),
MaxSize: ctx.Flags["--log-maxsize"].(int),
Expand All @@ -353,7 +360,7 @@ func grab(ctx command.Context) error {
logger := logos.New(zapLogger, color)
logger.LogOnPanic()

subredditDestinations := ctx.Flags["--subreddit-destination"].([]string)
subredditDestinations := ctx.Flags["--subreddit-destination"].([]path.Path)
subredditLimits := ctx.Flags["--subreddit-limit"].([]int)
subredditNames := ctx.Flags["--subreddit-name"].([]string)
subredditTimeframes := ctx.Flags["--subreddit-timeframe"].([]string)
Expand Down Expand Up @@ -382,7 +389,7 @@ func grab(ctx command.Context) error {

sr := subreddit{
Name: subredditNames[i],
Destination: subredditDestinations[i],
Destination: subredditDestinations[i].MustExpand(),
Timeframe: subredditTimeframes[i],
Limit: subredditLimits[i],
}
Expand Down
9 changes: 5 additions & 4 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"go.bbkane.com/warg/command"
"go.bbkane.com/warg/config/yamlreader"
"go.bbkane.com/warg/flag"
"go.bbkane.com/warg/path"
"go.bbkane.com/warg/section"
"go.bbkane.com/warg/value/scalar"
"go.bbkane.com/warg/value/slice"
Expand Down Expand Up @@ -35,7 +36,7 @@ Homepage: https://github.com/bbkane/grabbit
"--log-filename": flag.New(
"Log filename",
scalar.Path(
scalar.Default("~/.config/grabbit.jsonl"),
scalar.Default(path.New("~/.config/grabbit.jsonl")),
),
flag.ConfigPath("lumberjacklogger.filename"),
flag.Required(),
Expand Down Expand Up @@ -89,7 +90,7 @@ Homepage: https://github.com/bbkane/grabbit
"--subreddit-destination",
"Where to store the subreddit",
slice.Path(
slice.Default([]string{".", "."}),
slice.Default([]path.Path{path.New("."), path.New(".")}),
),
flag.Alias("-sd"),
flag.ConfigPath("subreddits[].destination"),
Expand Down Expand Up @@ -152,8 +153,8 @@ Homepage: https://github.com/bbkane/grabbit
),
warg.ConfigFlag(
"--config",
[]scalar.ScalarOpt[string]{
scalar.Default("~/.config/grabbit.yaml"),
[]scalar.ScalarOpt[path.Path]{
scalar.Default(path.New("~/.config/grabbit.yaml")),
},
yamlreader.New,
"Config filepath",
Expand Down

0 comments on commit 4c04078

Please sign in to comment.