Skip to content

Hint at existing favs instead of duplicate config - #117

Draft
codybuell wants to merge 2 commits into
mainfrom
existing-favorites-detection
Draft

Hint at existing favs instead of duplicate config#117
codybuell wants to merge 2 commits into
mainfrom
existing-favorites-detection

Conversation

@codybuell

Copy link
Copy Markdown
Collaborator

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.

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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant