Skip to content

Commit 1295c0b

Browse files
committed
Fixed json output for 'profile set-default' command
1 parent 290e0e1 commit 1295c0b

File tree

2 files changed

+18
-3
lines changed

2 files changed

+18
-3
lines changed

internal/cli/profile/profile_set-default.go

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,5 +51,19 @@ func runSetDefaultCommand(ctx context.Context, args []string, srv rpc.ArduinoCor
5151
if err != nil {
5252
feedback.Fatal(i18n.Tr("Cannot set %s as default profile: %v", profileName, err), feedback.ErrGeneric)
5353
}
54-
feedback.Print(i18n.Tr("Default profile set to: %s", profileName))
54+
feedback.PrintResult(&profileSetDefaultResult{
55+
DefaultProfile: profileName,
56+
})
57+
}
58+
59+
type profileSetDefaultResult struct {
60+
DefaultProfile string `json:"default_profile"`
61+
}
62+
63+
func (r *profileSetDefaultResult) String() string {
64+
return i18n.Tr("Default profile set to: %s", r.DefaultProfile)
65+
}
66+
67+
func (r *profileSetDefaultResult) Data() any {
68+
return r
5569
}

internal/integrationtest/profiles/profiles_test.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -378,13 +378,14 @@ func TestProfileSetDefault(t *testing.T) {
378378
require.Contains(t, fileContent, "default_profile: uno")
379379
require.NotContains(t, fileContent, "default_profile: my_profile")
380380

381-
// Change default profile
382-
_, _, err = cli.Run("profile", "set-default", "my_profile", "--sketch-path", sk.String())
381+
// Change default profile, and test JSON output
382+
out, _, err := cli.Run("profile", "set-default", "my_profile", "--sketch-path", sk.String(), "--json")
383383
require.NoError(t, err)
384384
fileContent, err = sk.Join("sketch.yaml").ReadFileAsLines()
385385
require.NoError(t, err)
386386
require.NotContains(t, fileContent, "default_profile: uno")
387387
require.Contains(t, fileContent, "default_profile: my_profile")
388+
requirejson.Parse(t, out).Query(".default_profile").MustEqual(`"my_profile"`)
388389

389390
// Changing to an inexistent profile returns an error
390391
_, stderr, err := cli.Run("profile", "set-default", "inexistent_profile", "--sketch-path", sk.String())

0 commit comments

Comments
 (0)