Skip to content

Commit 9e407bd

Browse files
authored
fix(contacts): reject conflicting from-file update flags
Reject all individual contact update flags when --from-file is used.\n\nThanks @klodr.
1 parent 70076e3 commit 9e407bd

2 files changed

Lines changed: 26 additions & 2 deletions

File tree

internal/cmd/contacts_crud.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -440,7 +440,10 @@ func (c *ContactsUpdateCmd) Run(ctx context.Context, kctx *kong.Context, flags *
440440
}
441441

442442
if strings.TrimSpace(c.FromFile) != "" {
443-
if flagProvided(kctx, "given") || flagProvided(kctx, "family") || flagProvided(kctx, "email") || flagProvided(kctx, "phone") || flagProvided(kctx, "birthday") || flagProvided(kctx, "notes") || flagProvided(kctx, "relation") {
443+
if flagProvided(kctx, "given") || flagProvided(kctx, "family") || flagProvided(kctx, "email") || flagProvided(kctx, "phone") ||
444+
flagProvided(kctx, "org") || flagProvided(kctx, "title") || flagProvided(kctx, "url") ||
445+
flagProvided(kctx, "note") || flagProvided(kctx, "address") || flagProvided(kctx, "custom") ||
446+
flagProvided(kctx, "birthday") || flagProvided(kctx, "notes") || flagProvided(kctx, "relation") {
444447
return usage("can't combine --from-file with other update flags")
445448
}
446449
return c.updateFromJSON(ctx, svc, resourceName, u)

internal/cmd/contacts_update_json_more_test.go

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -189,8 +189,29 @@ func TestContactsUpdate_FromFile_CantCombineWithFlags(t *testing.T) {
189189
}
190190
_ = tmp.Close()
191191

192+
// Previously covered: --email
192193
err = runKong(t, &ContactsUpdateCmd{}, []string{"people/c1", "--from-file", tmp.Name(), "--email", "x@example.com"}, context.Background(), &RootFlags{Account: "a@b.com"})
193194
if err == nil || !strings.Contains(err.Error(), "can't combine --from-file") {
194-
t.Fatalf("expected combine error, got %v", err)
195+
t.Fatalf("expected combine error for --email, got %v", err)
196+
}
197+
198+
// Flags that were previously missing from the conflict guard: org, title, url, note, address, custom
199+
conflictCases := []struct {
200+
name string
201+
extra []string
202+
}{
203+
{"org", []string{"--org", "Acme"}},
204+
{"title", []string{"--title", "CEO"}},
205+
{"url", []string{"--url", "https://example.com"}},
206+
{"note", []string{"--note", "some note"}},
207+
{"address", []string{"--address", "123 Main St"}},
208+
{"custom", []string{"--custom", "key=value"}},
209+
}
210+
for _, tc := range conflictCases {
211+
args := append([]string{"people/c1", "--from-file", tmp.Name()}, tc.extra...)
212+
runErr := runKong(t, &ContactsUpdateCmd{}, args, context.Background(), &RootFlags{Account: "a@b.com"})
213+
if runErr == nil || !strings.Contains(runErr.Error(), "can't combine --from-file") {
214+
t.Fatalf("expected combine error for --%s, got %v", tc.name, runErr)
215+
}
195216
}
196217
}

0 commit comments

Comments
 (0)