Skip to content

Commit

Permalink
misc: add json config file parsing
Browse files Browse the repository at this point in the history
Signed-off-by: Mark Pashmfouroush <[email protected]>
  • Loading branch information
markpash committed Mar 21, 2024
1 parent cbc22b6 commit 6793f83
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 3 deletions.
11 changes: 11 additions & 0 deletions example_config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"verbose": false,
"bind": "127.0.0.1:8086",
"endpoint": "",
"key": "",
"gool": false,
"cfon": false,
"country": "DE",
"scan": true,
"rtt": "1000ms"
}
12 changes: 9 additions & 3 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import (

"github.com/peterbourgon/ff/v4"
"github.com/peterbourgon/ff/v4/ffhelp"
"github.com/peterbourgon/ff/v4/ffjson"
)

var psiphonCountries = []string{
Expand Down Expand Up @@ -66,12 +67,17 @@ func main() {
gool = fs.BoolLong("gool", "enable gool mode (warp in warp)")
psiphon = fs.BoolLong("cfon", "enable psiphon mode (must provide country as well)")
country = fs.StringEnumLong("country", fmt.Sprintf("psiphon country code (valid values: %s)", psiphonCountries), psiphonCountries...)
scan = fs.BoolLong("scan", "enable warp scanning (experimental)")
scan = fs.BoolLong("scan", "enable warp scanning")
rtt = fs.DurationLong("rtt", 1000*time.Millisecond, "scanner rtt limit")
_ = fs.String('c', "config", "", "path to config file")
)

// Config file and envvars can be added through ff later
err := ff.Parse(fs, os.Args[1:])
err := ff.Parse(
fs,
os.Args[1:],
ff.WithConfigFileFlag("config"),
ff.WithConfigFileParser(ffjson.Parse),
)
switch {
case errors.Is(err, ff.ErrHelp):
fmt.Fprintf(os.Stderr, "%s\n", ffhelp.Flags(fs))
Expand Down

0 comments on commit 6793f83

Please sign in to comment.