mirror of
https://github.com/sourcegraph/sourcegraph.git
synced 2026-02-06 16:31:47 +00:00
chore(local): sg warns about opposite default value on dev builds (#63612)
As I just reviewed a PR for `sg` about analytics, I've wasted 10m wondering why I wasn't seeing anything (thought I might be on the wrong branch, that type of things). Turned out, we obviously flip certain default value for flags (such as disabling analytics) when running a dev build. `sg` now prints out a warning at the beginning stating which of those are flipped out. ## Test plan CI + local run  Warning sign is missing, but it's there, something wrong with my font. <!-- REQUIRED; info at https://docs-legacy.sourcegraph.com/dev/background-information/testing_principles --> ## Changelog <!-- OPTIONAL; info at https://www.notion.so/sourcegraph/Writing-a-changelog-entry-dd997f411d524caabf0d8d38a24a878c -->
This commit is contained in:
parent
09df420893
commit
f5bbbcb572
@ -6,6 +6,7 @@ import (
|
||||
"fmt"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
hashstructure "github.com/mitchellh/hashstructure/v2"
|
||||
@ -128,18 +129,18 @@ var sg = &cli.App{
|
||||
Value: false,
|
||||
Destination: &disableOverwrite,
|
||||
},
|
||||
&cli.BoolFlag{
|
||||
warnSkippedInDev(&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
|
||||
},
|
||||
&cli.BoolFlag{
|
||||
}),
|
||||
warnSkippedInDev(&cli.BoolFlag{
|
||||
Name: "disable-analytics",
|
||||
Usage: "disable event logging (logged to '~/.sourcegraph/events')",
|
||||
EnvVars: []string{"SG_DISABLE_ANALYTICS"},
|
||||
Value: BuildCommit == "dev", // Default to skip in dev
|
||||
},
|
||||
}),
|
||||
&cli.BoolFlag{
|
||||
Name: "disable-output-detection",
|
||||
Usage: "use fixed output configuration instead of detecting terminal capabilities",
|
||||
@ -178,6 +179,12 @@ var sg = &cli.App{
|
||||
// Configure global output
|
||||
std.Out = std.NewOutput(cmd.App.Writer, verbose)
|
||||
|
||||
// Print out a warning about flags which are disabled by default only in dev, but
|
||||
// enabled otherwise.
|
||||
if BuildCommit == "dev" {
|
||||
printSkippedInDevWarning()
|
||||
}
|
||||
|
||||
// Set up analytics and hooks for each command - do this as the first context
|
||||
// setup
|
||||
if !cmd.Bool("disable-analytics") {
|
||||
@ -424,6 +431,24 @@ func watchConfig(ctx context.Context) (<-chan *sgconf.Config, error) {
|
||||
return output, err
|
||||
}
|
||||
|
||||
var skippedInDevFlags = []cli.Flag{}
|
||||
|
||||
// warnSkippedInDev registers a flag as having a different default value when sg is running in dev mode.
|
||||
func warnSkippedInDev(flag cli.Flag) cli.Flag {
|
||||
skippedInDevFlags = append(skippedInDevFlags, flag)
|
||||
return flag
|
||||
}
|
||||
|
||||
// printSkippedInDevWarning reminds the user that sg is running in dev mode and certain flags have a different default value.
|
||||
func printSkippedInDevWarning() {
|
||||
names := []string{}
|
||||
for _, f := range skippedInDevFlags {
|
||||
// Safe because it's not possible for a flag to not have name.
|
||||
names = append(names, f.Names()[0])
|
||||
}
|
||||
std.Out.WriteWarningf("Running sg with a dev build, following flags have different default value unless explictly set: %s", strings.Join(names, ", "))
|
||||
}
|
||||
|
||||
func exists(file string) bool {
|
||||
_, err := os.Stat(file)
|
||||
return !os.IsNotExist(err)
|
||||
|
||||
Loading…
Reference in New Issue
Block a user