Skip to content

Commit fbc13a9

Browse files
committed
Preserve wallpaper follow-up profile and account scope
1 parent 2b89e5a commit fbc13a9

2 files changed

Lines changed: 60 additions & 9 deletions

File tree

‎internal/commands/projects.go‎

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -503,6 +503,7 @@ its current mode.`, wallpaperFormatNames(), maxWallpaperMB, strings.Join(wallpap
503503
}
504504

505505
app := appctx.FromContext(cmd.Context())
506+
scope := newFollowUpScope(app)
506507
projectID, err := wallpaperProjectID(cmd, app)
507508
if err != nil {
508509
return err
@@ -524,7 +525,7 @@ its current mode.`, wallpaperFormatNames(), maxWallpaperMB, strings.Join(wallpap
524525
if mode != "" {
525526
summary += " (" + mode + ")"
526527
}
527-
return respondWithWallpaperProject(cmd, app, projectID, map[string]any{"id": projectID}, summary,
528+
return respondWithWallpaperProject(cmd, app, projectID, scope, map[string]any{"id": projectID}, summary,
528529
output.Breadcrumb{
529530
Action: "mode",
530531
Cmd: fmt.Sprintf("basecamp projects wallpaper mode <fill|tile> --project %d", projectID),
@@ -567,6 +568,7 @@ A project with no wallpaper keeps the mode for the next one uploaded.`,
567568
}
568569

569570
app := appctx.FromContext(cmd.Context())
571+
scope := newFollowUpScope(app)
570572
projectID, err := wallpaperProjectID(cmd, app)
571573
if err != nil {
572574
return err
@@ -583,7 +585,7 @@ A project with no wallpaper keeps the mode for the next one uploaded.`,
583585
return convertSDKError(err)
584586
}
585587

586-
return respondWithWallpaperProject(cmd, app, projectID, project, "Wallpaper mode set to "+mode,
588+
return respondWithWallpaperProject(cmd, app, projectID, scope, project, "Wallpaper mode set to "+mode,
587589
output.Breadcrumb{
588590
Action: "set",
589591
Cmd: fmt.Sprintf("basecamp projects wallpaper set <file> --project %d", projectID),
@@ -604,6 +606,7 @@ func newProjectsWallpaperRemoveCmd() *cobra.Command {
604606
Args: cobra.NoArgs,
605607
RunE: func(cmd *cobra.Command, args []string) error {
606608
app := appctx.FromContext(cmd.Context())
609+
scope := newFollowUpScope(app)
607610
projectID, err := wallpaperProjectID(cmd, app)
608611
if err != nil {
609612
return err
@@ -613,7 +616,7 @@ func newProjectsWallpaperRemoveCmd() *cobra.Command {
613616
return convertSDKError(err)
614617
}
615618

616-
return respondWithWallpaperProject(cmd, app, projectID, map[string]any{"id": projectID}, "Wallpaper removed",
619+
return respondWithWallpaperProject(cmd, app, projectID, scope, map[string]any{"id": projectID}, "Wallpaper removed",
617620
output.Breadcrumb{
618621
Action: "set",
619622
Cmd: fmt.Sprintf("basecamp projects wallpaper set <file> --project %d", projectID),
@@ -683,15 +686,20 @@ func wallpaperProjectID(cmd *cobra.Command, app *appctx.App) (int64, error) {
683686
// the output carries its wallpaper. The change has already happened, so a
684687
// failed read falls back to what the caller has, with a diagnostic, rather
685688
// than failing the command.
686-
func respondWithWallpaperProject(cmd *cobra.Command, app *appctx.App, projectID int64, fallback any, summary string, crumbs ...output.Breadcrumb) error {
689+
func respondWithWallpaperProject(cmd *cobra.Command, app *appctx.App, projectID int64, scope followUpScope, fallback any, summary string, crumbs ...output.Breadcrumb) error {
690+
crumbs = append([]output.Breadcrumb{{
691+
Action: "show",
692+
Cmd: fmt.Sprintf("basecamp projects show %d", projectID),
693+
Description: "View the project",
694+
}}, crumbs...)
695+
scopeArgs := scope.args(app.Config.AccountID)
696+
for i := range crumbs {
697+
crumbs[i].Cmd += scopeArgs
698+
}
687699
opts := []output.ResponseOption{
688700
output.WithEntity("project"),
689701
output.WithSummary(summary),
690-
output.WithBreadcrumbs(append([]output.Breadcrumb{{
691-
Action: "show",
692-
Cmd: fmt.Sprintf("basecamp projects show %d", projectID),
693-
Description: "View the project",
694-
}}, crumbs...)...),
702+
output.WithBreadcrumbs(crumbs...),
695703
}
696704
data := fallback
697705
project, err := app.Account().Projects().Get(cmd.Context(), projectID)

‎internal/commands/projects_wallpaper_test.go‎

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import (
1818
"github.com/stretchr/testify/require"
1919

2020
"github.com/basecamp/basecamp-cli/internal/appctx"
21+
"github.com/basecamp/basecamp-cli/internal/config"
2122
"github.com/basecamp/basecamp-cli/internal/output"
2223
)
2324

@@ -192,6 +193,48 @@ func TestProjectsWallpaperSetUploadsTheFileAndReturnsTheProject(t *testing.T) {
192193
assert.Equal(t, "basecamp projects show 123", env.Breadcrumbs[0].Cmd)
193194
}
194195

196+
func TestProjectsWallpaperFollowUpsPreserveScope(t *testing.T) {
197+
for _, scope := range []struct {
198+
name, profile, accountSource, suffix string
199+
}{
200+
{"configured account", "", string(config.SourceGlobal), ""},
201+
{"active profile", "staging", "profile", " --profile staging"},
202+
{"explicit account override", "staging", string(config.SourceFlag), " --profile staging --account 99999"},
203+
{"selected account", "", string(config.SourcePrompt), " --account 99999"},
204+
} {
205+
for _, action := range []string{"set", "mode", "remove"} {
206+
t.Run(scope.name+"/"+action, func(t *testing.T) {
207+
_, app, buf := newWallpaperServer(t)
208+
app.Flags.Project = "123"
209+
app.Config.ActiveProfile = scope.profile
210+
app.Config.Sources = map[string]string{"account_id": scope.accountSource}
211+
args := []string{"wallpaper", action}
212+
want := map[string]string{"show": "basecamp projects show 123" + scope.suffix}
213+
switch action {
214+
case "set":
215+
args = append(args, writeWallpaperFile(t, "image.png", 0))
216+
want["mode"] = "basecamp projects wallpaper mode <fill|tile> --project 123" + scope.suffix
217+
want["remove"] = "basecamp projects wallpaper remove --project 123" + scope.suffix
218+
case "mode":
219+
args = append(args, "tile")
220+
fallthrough
221+
case "remove":
222+
want["set"] = "basecamp projects wallpaper set <file> --project 123" + scope.suffix
223+
}
224+
225+
require.NoError(t, executeCommand(NewProjectsCmd(), app, args...))
226+
env := decodeWallpaperEnvelope(t, buf)
227+
require.Len(t, env.Breadcrumbs, len(want))
228+
got := make(map[string]string, len(env.Breadcrumbs))
229+
for _, breadcrumb := range env.Breadcrumbs {
230+
got[breadcrumb.Action] = breadcrumb.Cmd
231+
}
232+
assert.Equal(t, want, got)
233+
})
234+
}
235+
}
236+
}
237+
195238
func TestProjectsWallpaperSetWithoutModeKeepsTheCurrentMode(t *testing.T) {
196239
s, app, buf := newWallpaperServer(t)
197240
app.Config.ProjectID = "123"

0 commit comments

Comments
 (0)