Skip to content

Commit

Permalink
feat(influxd): refactor run command to use cli.Program to respect con…
Browse files Browse the repository at this point in the history
…fig file
  • Loading branch information
jsteenb2 committed Jun 18, 2020
1 parent 8d9e3bb commit 108abb9
Showing 1 changed file with 17 additions and 12 deletions.
29 changes: 17 additions & 12 deletions cmd/influxd/launcher/launcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,19 +87,19 @@ const (
// NewCommand creates the command to run influxdb.
func NewCommand() *cobra.Command {
l := NewLauncher()
cmd := &cobra.Command{
Use: "run",
Short: "Start the influxd server (default)",
Run: func(cmd *cobra.Command, args []string) {

prog := cli.Program{
Name: "run",
Opts: launcherOpts(l),
Run: func() error {
// exit with SIGINT and SIGTERM
ctx := context.Background()
ctx = signals.WithStandardSignals(ctx)

if err := l.run(ctx); err != nil {
fmt.Fprintln(os.Stderr, err)
os.Exit(1)
return err
} else if !l.Running() {
os.Exit(1)
return errors.New("already running...")
}

var wg sync.WaitGroup
Expand All @@ -120,23 +120,25 @@ func NewCommand() *cobra.Command {
defer cancel()
l.Shutdown(ctx)
wg.Wait()

return nil
},
}

buildLauncherCommand(l, cmd)

cmd := cli.NewCommand(&prog)
cmd.AddCommand(inspect.NewCommand())
return cmd
}

var vaultConfig vault.Config

func buildLauncherCommand(l *Launcher, cmd *cobra.Command) {
func launcherOpts(l *Launcher) []cli.Opt {
dir, err := fs.InfluxDir()
if err != nil {
panic(fmt.Errorf("failed to determine influx directory: %v", err))
}

opts := []cli.Opt{
return []cli.Opt{
{
DestP: &l.logLevel,
Flag: "log-level",
Expand Down Expand Up @@ -312,7 +314,10 @@ func buildLauncherCommand(l *Launcher, cmd *cobra.Command) {
Desc: "feature flag overrides",
},
}
cli.BindOptions(cmd, opts)
}

func buildLauncherCommand(l *Launcher, cmd *cobra.Command) {
cli.BindOptions(cmd, launcherOpts(l))
cmd.AddCommand(inspect.NewCommand())
}

Expand Down

0 comments on commit 108abb9

Please sign in to comment.