Hint at existing favs instead of duplicate config - #117
Draft
codybuell wants to merge 2 commits into
Draft
Conversation
When printing the "save as favorite" helper after a stak or console run, check the user's combined favorites (config + API) for one that already matches the selected account, cloud access role, and access type. If found, print the command to use it rather than a config snippet the user does not need. MatchExistingFavorite prefers an exact access_type match and falls back to a favorite with no access_type set, which Favorites treats as CLI access. In that generic case the console path appends --web to the suggested command so the hint federates into the browser rather than dropping the user into a subshell. Failure to retrieve favorites is non-fatal and falls back to the existing config snippet.
The previous commit treated a favorites lookup failure as "no favorite found", which fell through to printing the config snippet. That told a user who already had a matching favorite to create a duplicate. Skip the hint entirely when the lookup fails instead, since we cannot tell whether a favorite exists. Add tests for MatchExistingFavorite covering exact access_type matches, the generic fallback, exact-beats-generic in either slice order, and the account, cloud access role, and access type mismatch cases. Add tests for PrintFavoriteConfig covering both output branches, the region conditional, and the --web flag appended for a generic match. color.NoColor is pinned in the print test because fatih/color decides whether to emit escape codes from os.Stdout rather than the writer it is given, so assertions would otherwise depend on whether tests run attached to a tty.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
When printing the "save as favorite" helper after a stak or console run, check the user's combined favorites (config + API) for one that already matches the selected account, cloud access role, and access type. If found, print the command to use it rather than a config snippet the user does not need.
MatchExistingFavorite prefers an exact access_type match and falls back to a favorite with no access_type set, which Favorites treats as CLI access. In that generic case the console path appends --web to the suggested command so the hint federates into the browser rather than dropping the user into a subshell.
Failure to retrieve favorites is non-fatal and falls back to the existing config snippet.