Skip to content

Commit

Permalink
feat(cmd/cupd): support env vars
Browse files Browse the repository at this point in the history
  • Loading branch information
GeorgeMac committed Aug 3, 2023
1 parent 6ff3d9d commit fc1caf4
Showing 1 changed file with 20 additions and 3 deletions.
23 changes: 20 additions & 3 deletions cmd/cupd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,13 @@ package main

import (
"context"
"errors"
"flag"
"os"

"github.com/peterbourgon/ff/v3"
"github.com/peterbourgon/ff/v3/ffcli"
"github.com/peterbourgon/ff/v3/ffyaml"
"go.flipt.io/cup/pkg/config"
"golang.org/x/exp/slog"
)
Expand All @@ -17,9 +21,20 @@ func main() {
},
)))

set := flag.NewFlagSet("cupd", flag.ContinueOnError)
_ = set.String("config", "", "server config file")

cfg := &config.Config{}
root := &ffcli.Command{
Name: "cupd",
Name: "cupd",
FlagSet: set,
Options: []ff.Option{
ff.WithEnvVarPrefix("CUPD"),
ff.WithConfigFileParser((&ffyaml.ParseConfig{
Delimiter: "-",
}).Parse),
ff.WithConfigFileFlag("config"),
},
Subcommands: []*ffcli.Command{
{
Name: "serve",
Expand All @@ -34,8 +49,10 @@ func main() {
}

if err := root.ParseAndRun(context.Background(), os.Args[1:]); err != nil {
slog.Error("Exiting...", "error", err)
os.Exit(1)
if !errors.Is(err, flag.ErrHelp) {
slog.Error("Exiting...", "error", err)
os.Exit(1)
}
}
}

Expand Down

0 comments on commit fc1caf4

Please sign in to comment.