Skip to content

Commit d682c81

Browse files
mwbrookszimeg
andauthored
fix: disable upgrade notification for the manifest info command (#548)
* fix: disable upgrade notification for the manifest info command * fix: also ignore the manifest command for upgrade notifications The top-level `manifest` command is an alias that runs `manifest info`, so it should also be ignored for upgrade notification checks. Co-Authored-By: Eden Zimbelman <eden.zimbelman@salesforce.com> --------- Co-authored-by: Eden Zimbelman <eden.zimbelman@salesforce.com>
1 parent 0160824 commit d682c81

3 files changed

Lines changed: 47 additions & 7 deletions

File tree

cmd/manifest/manifest.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,8 @@ func NewCommand(clients *shared.ClientFactory) *cobra.Command {
7272
clients.Config.SetFlags(cmd)
7373
return cmdutil.IsValidProjectDirectory(clients)
7474
},
75+
// DEPRECATED(semver:major): remove RunE so this command prints help like other parent commands
76+
// and remove "manifest" from the ignore list in internal/update/update.go
7577
RunE: func(cmd *cobra.Command, args []string) error {
7678
return runInfoCommand(cmd, clients)
7779
},

internal/update/update.go

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,11 @@ import (
1919
"net/http"
2020
"os"
2121
"reflect"
22+
"strings"
2223
"sync"
2324
"time"
2425

2526
"github.com/slackapi/slack-cli/internal/api"
26-
"github.com/slackapi/slack-cli/internal/goutils"
2727
"github.com/slackapi/slack-cli/internal/shared"
2828
"github.com/slackapi/slack-cli/internal/slackerror"
2929
"github.com/spf13/cobra"
@@ -223,13 +223,30 @@ func (u *UpdateNotification) isCI() bool {
223223

224224
// isIgnoredCommand returns true when the process is in the list of commands.
225225
func (u *UpdateNotification) isIgnoredCommand() bool {
226-
ignoredCommands := []string{"_fingerprint", "api", "version"}
227-
osStr := os.Args[0:]
228-
if len(osStr) < 2 {
226+
// "manifest" is included because it's an alias that runs "manifest info"
227+
ignoredCommands := []string{"_fingerprint", "api", "manifest", "manifest info", "version"}
228+
if len(os.Args) < 2 {
229229
return false
230230
}
231-
commandName := osStr[1]
232-
return goutils.Contains(ignoredCommands, commandName, true)
231+
commandStr := strings.Join(os.Args[1:], " ")
232+
for _, ignored := range ignoredCommands {
233+
if commandStr == ignored {
234+
return true
235+
}
236+
// Match commands with additional flags (e.g. "manifest info --source local")
237+
// but not subcommands (e.g. "manifest validate" should not match "manifest")
238+
if strings.HasPrefix(commandStr, ignored+" ") {
239+
rest := commandStr[len(ignored)+1:]
240+
if strings.HasPrefix(rest, "-") {
241+
return true
242+
}
243+
// Allow prefix match for multi-word commands (e.g. "manifest info --flag")
244+
if strings.Contains(ignored, " ") {
245+
return true
246+
}
247+
}
248+
}
249+
return false
233250
}
234251

235252
// isLastUpdateCheckedAtGreaterThan returns true when the time since the last update check is greater

internal/update/update_test.go

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ package update
1717
import (
1818
"context"
1919
"os"
20+
"strings"
2021
"testing"
2122

2223
"github.com/slackapi/slack-cli/internal/config"
@@ -165,14 +166,34 @@ func Test_UpdateNotification_isIgnoredCommand(t *testing.T) {
165166
command: "version",
166167
expected: true,
167168
},
169+
"manifest command": {
170+
command: "manifest",
171+
expected: true,
172+
},
173+
"manifest command with flags": {
174+
command: "manifest --source local",
175+
expected: true,
176+
},
177+
"manifest info command": {
178+
command: "manifest info",
179+
expected: true,
180+
},
181+
"manifest info command with flags": {
182+
command: "manifest info --source local",
183+
expected: true,
184+
},
185+
"manifest validate command": {
186+
command: "manifest validate",
187+
expected: false,
188+
},
168189
"auth command": {
169190
command: "auth",
170191
expected: false,
171192
},
172193
} {
173194
t.Run(name, func(t *testing.T) {
174195
if tc.command != "" {
175-
os.Args = []string{"placeholder", tc.command}
196+
os.Args = append([]string{"placeholder"}, strings.Split(tc.command, " ")...)
176197
} else {
177198
os.Args = []string{"placeholder"}
178199
}

0 commit comments

Comments
 (0)