Skip to content

Commit 0e8aa2e

Browse files
committed
feat(prompts): set current user as default owner for prompt creation
This commit modifies the `src prompts create` command to default the prompt owner to the current user if no owner is explicitly specified via the `-owner` flag.
1 parent 0ba4140 commit 0e8aa2e

1 file changed

Lines changed: 12 additions & 6 deletions

File tree

cmd/src/prompts_create.go

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ Examples:
3333
nameFlag = flagSet.String("name", "", "The prompt name")
3434
descriptionFlag = flagSet.String("description", "", "Description of the prompt")
3535
contentFlag = flagSet.String("content", "", "The prompt template text content")
36-
ownerFlag = flagSet.String("owner", "", "The ID of the owner (user or organization)")
36+
ownerFlag = flagSet.String("owner", "", "The ID of the owner (user or organization). Defaults to current user if not specified.")
3737
tagsFlag = flagSet.String("tags", "", "Comma-separated list of tag IDs")
3838
draftFlag = flagSet.Bool("draft", false, "Whether the prompt is a draft")
3939
visibilityFlag = flagSet.String("visibility", "PUBLIC", "Visibility of the prompt (PUBLIC or SECRET)")
@@ -57,8 +57,16 @@ Examples:
5757
if *contentFlag == "" {
5858
return errors.New("provide content for the prompt")
5959
}
60-
if *ownerFlag == "" {
61-
return errors.New("provide an owner ID for the prompt")
60+
client := cfg.apiClient(apiFlags, flagSet.Output())
61+
62+
// Use current user as default owner if not specified
63+
ownerID := *ownerFlag
64+
if ownerID == "" {
65+
var err error
66+
ownerID, err = getViewerUserID(context.Background(), client)
67+
if err != nil {
68+
return errors.Wrap(err, "failed to get current user ID")
69+
}
6270
}
6371

6472
// Validate mode
@@ -81,8 +89,6 @@ Examples:
8189
tagIDs = strings.Split(*tagsFlag, ",")
8290
}
8391

84-
client := cfg.apiClient(apiFlags, flagSet.Output())
85-
8692
query := `mutation CreatePrompt(
8793
$input: PromptInput!
8894
) {
@@ -96,7 +102,7 @@ Examples:
96102
"name": *nameFlag,
97103
"description": *descriptionFlag,
98104
"definitionText": *contentFlag,
99-
"owner": *ownerFlag,
105+
"owner": ownerID,
100106
"draft": *draftFlag,
101107
"visibility": visibility,
102108
"autoSubmit": *autoSubmitFlag,

0 commit comments

Comments
 (0)