Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 12 additions & 3 deletions cmd/contacts.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ type contactFieldParams struct {
func addContactFieldFlags(cmd *cobra.Command) {
cmd.Flags().String("first-name", "", "First name")
cmd.Flags().String("last-name", "", "Last name")
cmd.Flags().BoolP("subscribed", "s", false, "Subscribed status")
cmd.Flags().StringP("subscribed", "s", "", `Subscribed status ("true" or "false")`)
cmd.Flags().String("user-group", "", "User group")
cmd.Flags().StringArray("list", nil, "Mailing list subscription as id=true|false (repeatable)")
cmd.Flags().String("contact-props", "", "Path to a JSON file of contact properties")
Expand All @@ -43,8 +43,17 @@ func contactFieldParamsFromCmd(cmd *cobra.Command) (contactFieldParams, error) {
}

if cmd.Flags().Changed("subscribed") {
sub, _ := cmd.Flags().GetBool("subscribed")
params.Subscribed = &sub
subStr, _ := cmd.Flags().GetString("subscribed")
switch subStr {
case "true":
b := true
params.Subscribed = &b
case "false":
b := false
params.Subscribed = &b
default:
return params, fmt.Errorf("--subscribed must be \"true\" or \"false\"")
}
}

listPairs, _ := cmd.Flags().GetStringArray("list")
Expand Down
9 changes: 9 additions & 0 deletions cmd/contacts_create_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,15 @@ func TestContactFieldParamsFromCmd(t *testing.T) {
}
})

t.Run("invalid --subscribed returns error", func(t *testing.T) {
cmd := newFieldCmd(t)
cmd.Flags().Set("subscribed", "yes")
_, err := contactFieldParamsFromCmd(cmd)
if err == nil {
t.Fatal("expected error, got nil")
}
})

t.Run("invalid --list returns error", func(t *testing.T) {
cmd := newFieldCmd(t)
cmd.Flags().Set("list", "badvalue")
Expand Down