Skip to content
This repository has been archived by the owner on Sep 30, 2024. It is now read-only.

Commit

Permalink
unify on global verbose flag
Browse files Browse the repository at this point in the history
  • Loading branch information
bobheadxi committed Apr 13, 2022
1 parent 2272bf9 commit a36e552
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 27 deletions.
2 changes: 1 addition & 1 deletion dev/sg/generates.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ var allGenerateTargets = generateTargets{
}

func generateGoRunner(ctx context.Context, args []string) *generate.Report {
if generateVerbose {
if verbose {
return golang.Generate(ctx, args, golang.VerboseOutput)
} else if generateQuiet {
return golang.Generate(ctx, args, golang.QuietOutput)
Expand Down
22 changes: 12 additions & 10 deletions dev/sg/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,11 @@ var (
// Note that these values are only available after the main sg CLI app has been run.
configFlag string
overwriteConfigFlag string
verboseFlag bool
skipAutoUpdatesFlag bool

// Global verbose mode
verbose bool

// postInitHooks is useful for doing anything that requires flags to be set beforehand,
// e.g. generating help text based on parsed config
postInitHooks []cli.ActionFunc
Expand All @@ -64,37 +66,37 @@ var sg = &cli.App{
&cli.BoolFlag{
Name: "verbose",
Usage: "toggle verbose mode",
Aliases: []string{"v"},
EnvVars: []string{"SG_VERBOSE"},
Value: false,
Destination: &verboseFlag,
Destination: &verbose,
},
&cli.StringFlag{
Name: "config",
Usage: "specify a sg configuration file",
TakesFile: true, // Enable completions
EnvVars: []string{"SG_CONFIG"},
TakesFile: true,
Value: defaultConfigFile,
Destination: &configFlag,
DefaultText: "path",
EnvVars: []string{"SG_CONFIG"},
},
&cli.StringFlag{
Name: "overwrite",
Usage: "configuration overwrites file that is gitignored and can be used to, for example, add credentials",
TakesFile: true, // Enable completions
EnvVars: []string{"SG_OVERWRITE"},
TakesFile: true,
Value: defaultConfigOverwriteFile,
Destination: &overwriteConfigFlag,
DefaultText: "path",
EnvVars: []string{"SG_OVERWRITE"},
},
&cli.BoolFlag{
Name: "skip-auto-update",
Usage: "prevent sg from automatically updating itself",
EnvVars: []string{"SG_SKIP_AUTO_UPDATE"},
Value: BuildCommit == "dev", // Default to skip in dev, otherwise don't
Destination: &skipAutoUpdatesFlag,
EnvVars: []string{"SG_SKIP_AUTO_UPDATE"},
},
},
Before: func(cmd *cli.Context) error {
if verboseFlag {
if verbose {
stdout.Out.SetVerbose()
}

Expand Down
26 changes: 12 additions & 14 deletions dev/sg/sg_generate.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,23 +16,21 @@ import (
)

var (
generateVerbose bool
generateQuiet bool
generateQuiet bool
)

var generateCommand = &cli.Command{
Name: "generate",
ArgsUsage: "[target]",
Usage: "Run code and docs generation tasks",
Description: "Run code and docs generation tasks - if no target is provided, all target are run with default arguments.",
Category: CategoryDev,
Name: "generate",
ArgsUsage: "[target]",
Usage: "Run code and docs generation tasks",
Description: `Run code and docs generation tasks - if no target is provided, all target are run with default arguments.
Verbose mode can be enabled with the global verbose flag, e.g.
sg --verbose generate ...
`,
Category: CategoryDev,
Flags: []cli.Flag{
&cli.BoolFlag{
Name: "verbose",
Aliases: []string{"v"},
Usage: "Display output from generate tasks",
Destination: &generateVerbose,
},
&cli.BoolFlag{
Name: "quiet",
Aliases: []string{"q"},
Expand All @@ -41,7 +39,7 @@ var generateCommand = &cli.Command{
},
},
Before: func(cmd *cli.Context) error {
if generateVerbose && generateQuiet {
if verbose && generateQuiet {
return errors.Errorf("-q and --verbose flags are exclusive")
}
return nil
Expand Down
2 changes: 1 addition & 1 deletion dev/sg/sg_run.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ func runExec(ctx context.Context, args []string) error {
cmds = append(cmds, cmd)
}

return run.Commands(ctx, globalConf.Env, addToMacOSFirewall, verboseFlag, cmds...)
return run.Commands(ctx, globalConf.Env, addToMacOSFirewall, verbose, cmds...)
}
func constructRunCmdLongHelp() string {
var out strings.Builder
Expand Down
2 changes: 1 addition & 1 deletion dev/sg/sg_start.go
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ func startCommandSet(ctx context.Context, set *Commandset, conf *Config, addToMa
env[k] = v
}

return run.Commands(ctx, env, addToMacOSFirewall, verboseFlag, cmds...)
return run.Commands(ctx, env, addToMacOSFirewall, verbose, cmds...)
}

// logLevelOverrides builds a map of commands -> log level that should be overridden in the environment.
Expand Down

0 comments on commit a36e552

Please sign in to comment.