Skip to content

Commit eb93aaa

Browse files
authored
fix: remove version checks on all commands (#840)
1 parent aedfa70 commit eb93aaa

2 files changed

Lines changed: 10 additions & 42 deletions

File tree

cmd/kosli/root.go

Lines changed: 0 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -315,8 +315,6 @@ func getConfigFileFlagDefault() string {
315315
func newRootCmd(out, errOut io.Writer, args []string) (*cobra.Command, error) {
316316
global = new(GlobalOpts)
317317

318-
var updateNoticeCh = make(chan string, 1) // buffered — goroutine never blocks
319-
320318
cmd := &cobra.Command{
321319
Use: "kosli",
322320
Short: "The Kosli CLI.",
@@ -332,24 +330,6 @@ func newRootCmd(out, errOut io.Writer, args []string) (*cobra.Command, error) {
332330
return err
333331
}
334332

335-
// Fire update check in background — result collected in PostRun.
336-
// Skip when:
337-
// - "version" subcommand: runs the check synchronously itself
338-
// - "__complete*": Cobra shell-completion commands fire on every Tab press
339-
// - debug mode: noisy HTTP traffic is undesirable when debugging
340-
// Note: --version is handled by Cobra before any hooks run, so it never
341-
// reaches this point; innerMain handles the notice for that case.
342-
if cmd.Name() != "version" && !strings.HasPrefix(cmd.Name(), "__") && !global.Debug {
343-
f := cmd.Flags().Lookup("output")
344-
// skip version checks for programmatic output (avoid polluting JSON in CI pipelines)
345-
if f == nil || f.Value.String() == "table" {
346-
go func() {
347-
notice, _ := version.CheckForUpdate(version.GetVersion())
348-
updateNoticeCh <- notice
349-
}()
350-
}
351-
}
352-
353333
if global.ApiToken == "DRY_RUN" {
354334
global.DryRun = true
355335
}
@@ -372,16 +352,6 @@ func newRootCmd(out, errOut io.Writer, args []string) (*cobra.Command, error) {
372352

373353
return flagError
374354
},
375-
PersistentPostRun: func(cmd *cobra.Command, args []string) {
376-
select {
377-
case notice := <-updateNoticeCh:
378-
if notice != "" {
379-
_, _ = fmt.Fprint(errOut, notice) // stderr — doesn't pollute piped stdout
380-
}
381-
default:
382-
// goroutine not done yet (took > command duration) — skip silently
383-
}
384-
},
385355
}
386356
cmd.SetVersionTemplate("{{.Version}}\n")
387357
cmd.PersistentFlags().StringVarP(&global.ApiToken, "api-token", "a", "", apiTokenFlag)

cmd/kosli/root_test.go

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -73,22 +73,20 @@ func (suite *UpdateNoticeTestSuite) TestVersionFlagPrintsNotice() {
7373
suite.Contains(errBuf.String(), "A new version")
7474
}
7575

76-
func (suite *UpdateNoticeTestSuite) TestVersionNoticeSkippedForJSON() {
76+
func (suite *UpdateNoticeTestSuite) TestVersionNoticeNotShownOnRegularCommands() {
7777
const fakeNotice = "\nA new version of the Kosli CLI is available: v9.99.0 (you have v0.0.1)\nUpgrade: https://docs.kosli.com/getting_started/install/\n"
7878

7979
defer version.SetCheckForUpdateOverride(func(string) (string, error) { return fakeNotice, nil })()
8080

81-
// with --output json: no notice in stderr
82-
_, _, _, stderr, err := executeCommandC(
83-
fmt.Sprintf("list flows --output json %s", suite.defaultKosliArguments))
84-
suite.NoError(err)
85-
suite.Empty(stderr)
86-
87-
// with --output table: notice IS in stderr
88-
_, _, _, stderr, err = executeCommandC(
89-
fmt.Sprintf("list flows --output table %s", suite.defaultKosliArguments))
90-
suite.NoError(err)
91-
suite.Contains(stderr, "A new version")
81+
// The update check only runs for the `version` subcommand and the
82+
// `--version` flag — regular commands must not print the notice,
83+
// regardless of output format.
84+
for _, format := range []string{"json", "table"} {
85+
_, _, _, stderr, err := executeCommandC(
86+
fmt.Sprintf("list flows --output %s %s", format, suite.defaultKosliArguments))
87+
suite.NoError(err)
88+
suite.NotContains(stderr, "A new version", "no update notice expected for --output %s", format)
89+
}
9290
}
9391

9492
func TestUpdateNoticeTestSuite(t *testing.T) {

0 commit comments

Comments
 (0)