Skip to content

Commit

Permalink
Merge pull request #418 from CircleCI-Public/skip-update-check-ci
Browse files Browse the repository at this point in the history
Skip auto-update check while running in CI.
  • Loading branch information
marcomorain authored May 19, 2020
2 parents 797fc65 + bbb2ab9 commit 5b80b52
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 23 deletions.
2 changes: 1 addition & 1 deletion cmd/check_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ var _ = Describe("Check", func() {
Expect(err).ShouldNot(HaveOccurred())

command = commandWithHome(checkCLI, tempSettings.Home,
"help", "--github-api", tempSettings.TestServer.URL(),
"help", "--skip-update-check=false", "--github-api", tempSettings.TestServer.URL(),
)

response = `
Expand Down
38 changes: 16 additions & 22 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,31 +124,21 @@ func MakeCommands() *cobra.Command {
rootCmd.AddCommand(newStepCommand(rootOptions))
rootCmd.AddCommand(newSwitchCommand(rootOptions))

rootCmd.PersistentFlags().BoolVar(&rootOptions.Debug,
"debug", rootOptions.Debug, "Enable debug logging.")
rootCmd.PersistentFlags().StringVar(&rootTokenFromFlag,
"token", "", "your token for using CircleCI, also CIRCLECI_CLI_TOKEN")
rootCmd.PersistentFlags().StringVar(&rootOptions.Host,
"host", rootOptions.Host, "URL to your CircleCI host, also CIRCLECI_CLI_HOST")
rootCmd.PersistentFlags().StringVar(&rootOptions.Endpoint,
"endpoint", rootOptions.Endpoint, "URI to your CircleCI GraphQL API endpoint")

rootCmd.PersistentFlags().StringVar(&rootOptions.GitHubAPI, "github-api", "https://api.github.com/", "Change the default endpoint to GitHub API for retrieving updates")
if err := rootCmd.PersistentFlags().MarkHidden("github-api"); err != nil {
panic(err)
}
flags := rootCmd.PersistentFlags()

rootCmd.PersistentFlags().BoolVar(&rootOptions.SkipUpdateCheck, "skip-update-check", false, "Skip the check for updates check run before every command")
if err := rootCmd.PersistentFlags().MarkHidden("skip-update-check"); err != nil {
panic(err)
}
flags.BoolVar(&rootOptions.Debug, "debug", rootOptions.Debug, "Enable debug logging.")
flags.StringVar(&rootTokenFromFlag, "token", "", "your token for using CircleCI, also CIRCLECI_CLI_TOKEN")
flags.StringVar(&rootOptions.Host, "host", rootOptions.Host, "URL to your CircleCI host, also CIRCLECI_CLI_HOST")
flags.StringVar(&rootOptions.Endpoint, "endpoint", rootOptions.Endpoint, "URI to your CircleCI GraphQL API endpoint")
flags.StringVar(&rootOptions.GitHubAPI, "github-api", "https://api.github.com/", "Change the default endpoint to GitHub API for retrieving updates")
flags.BoolVar(&rootOptions.SkipUpdateCheck, "skip-update-check", runningInCi(), "Skip the check for updates check run before every command.")

if err := rootCmd.PersistentFlags().MarkHidden("debug"); err != nil {
panic(err)
}
hidden := []string{"github-api", "debug", "endpoint"}

if err := rootCmd.PersistentFlags().MarkHidden("endpoint"); err != nil {
panic(err)
for _, f := range hidden {
if err := flags.MarkHidden(f); err != nil {
panic(err)
}
}

// Cobra has a peculiar default behaviour:
Expand Down Expand Up @@ -264,3 +254,7 @@ This project is the seed for CircleCI's new command-line application.`
For more help, see the documentation here: %s`, long, config.Data.Links.CLIDocs)
}

func runningInCi() bool {
return os.Getenv("CI") == "true"
}

0 comments on commit 5b80b52

Please sign in to comment.