From 31bee373b584acb66d997cdaeeed66e94377eb7d Mon Sep 17 00:00:00 2001 From: Justin McBride Date: Fri, 28 Mar 2025 21:43:42 +0000 Subject: [PATCH 1/2] add env and secret support to create --- cmd/create.go | 41 +++++++++++++++++++++++++++++++++-------- 1 file changed, 33 insertions(+), 8 deletions(-) diff --git a/cmd/create.go b/cmd/create.go index e3410ce..8971808 100644 --- a/cmd/create.go +++ b/cmd/create.go @@ -4,6 +4,7 @@ import ( "bytes" "encoding/json" "fmt" + "strings" "github.com/MakeNowJust/heredoc" "github.com/cli/go-gh/v2/pkg/api" @@ -11,7 +12,9 @@ import ( ) type createCmdFlags struct { - app string + app string + EnvironmentVariables []string + Secrets []string } type createReq struct { @@ -31,7 +34,7 @@ func init() { Create a GitHub Runtime app `), Example: heredoc.Doc(` - $ gh runtime create --app my-app + $ gh runtime create --app my-app --env key1=value1 --env key2=value2 --secret key3=value3 --secret key4=value4 # => Creates the app named 'my-app' `), Run: func(cmd *cobra.Command, args []string) { @@ -42,12 +45,32 @@ func init() { // Construct the request body requestBody := createReq{ - EnvironmentVariables: map[string]string{ - "EXAMPLE_ENV": "value1", - }, - Secrets: map[string]string{ - "SECRET_KEY": "secret_value", - }, + EnvironmentVariables: map[string]string{}, + Secrets: map[string]string{}, + } + + for _, pair := range createCmdFlags.EnvironmentVariables { + parts := strings.SplitN(pair, "=", 2) + if len(parts) == 2 { + key := parts[0] + value := parts[1] + requestBody.EnvironmentVariables[key] = value + } else { + fmt.Printf("Error: Invalid environment variable format (%s). Must be in the form 'key=value'\n", pair) + return + } + } + + for _, pair := range createCmdFlags.Secrets { + parts := strings.SplitN(pair, "=", 2) + if len(parts) == 2 { + key := parts[0] + value := parts[1] + requestBody.Secrets[key] = value + } else { + fmt.Printf("Error: Invalid environment variable format (%s). Must be in the form 'key=value'\n", pair) + return + } } body, err := json.Marshal(requestBody) @@ -74,5 +97,7 @@ func init() { } createCmd.Flags().StringVarP(&createCmdFlags.app, "app", "a", "", "The app to create") + createCmd.Flags().StringSliceVarP(&createCmdFlags.EnvironmentVariables, "env", "e", []string{}, "Environment variables to set on the app in the form 'key=value'") + createCmd.Flags().StringSliceVarP(&createCmdFlags.Secrets, "secret", "s", []string{}, "Secrets to set on the app in the form 'key=value'") rootCmd.AddCommand(createCmd) } From 00b06597404e240ffe903aad2ec4f1e02f9bf521 Mon Sep 17 00:00:00 2001 From: Justin McBride Date: Fri, 28 Mar 2025 15:45:49 -0600 Subject: [PATCH 2/2] Update cmd/create.go Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --- cmd/create.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cmd/create.go b/cmd/create.go index 8971808..db21a55 100644 --- a/cmd/create.go +++ b/cmd/create.go @@ -68,7 +68,7 @@ func init() { value := parts[1] requestBody.Secrets[key] = value } else { - fmt.Printf("Error: Invalid environment variable format (%s). Must be in the form 'key=value'\n", pair) + fmt.Printf("Error: Invalid secret format (%s). Must be in the form 'key=value'\n", pair) return } }