From c751e88120baa4f25ec978a092e308d915f95cc3 Mon Sep 17 00:00:00 2001 From: Camilo Garcia La Rotta Date: Wed, 21 Jul 2021 19:56:08 -0400 Subject: [PATCH] feat: introduce repo, branch and machine flags for ghcs create --- cmd/ghcs/create.go | 44 ++++++++++++++++++++++++++++++++++++-------- 1 file changed, 36 insertions(+), 8 deletions(-) diff --git a/cmd/ghcs/create.go b/cmd/ghcs/create.go index 44bedb5f2..35cd49a2d 100644 --- a/cmd/ghcs/create.go +++ b/cmd/ghcs/create.go @@ -12,17 +12,45 @@ import ( "github.com/spf13/cobra" ) -var createCmd = &cobra.Command{ - Use: "create", - Short: "Create", - Long: "Create", - RunE: func(cmd *cobra.Command, args []string) error { - return Create() - }, +var repo, branch, machine string + +type machineType string + +const ( + basicMachine machineType = "basic" + standardMachine machineType = "standard" + premiumMachine machineType = "premium" + ExtremeMachine machineType = "extreme" +) + +func newCreateCmd() *cobra.Command { + createCmd := &cobra.Command{ + Use: "create", + Short: "Create a codespace", + Long: `Create a codespace for a given repository and branch. +You must also choose the type of machine to use.`, + RunE: func(cmd *cobra.Command, args []string) error { + if machine != "" { + switch machineType(machine) { + case basicMachine, standardMachine, premiumMachine, ExtremeMachine: + break + default: + return fmt.Errorf("invalid machine type: %s", machine) + } + } + return Create() + }, + } + + createCmd.Flags().StringVarP(&repo, "repo", "r", "", "repository name with owner: user/repo") + createCmd.Flags().StringVarP(&branch, "branch", "b", "", "repository branch") + createCmd.Flags().StringVarP(&machine, "machine", "m", "", "hardware specifications for the VM. Can be: basic, standard, premium, extreme") + + return createCmd } func init() { - rootCmd.AddCommand(createCmd) + rootCmd.AddCommand(newCreateCmd()) } var createSurvey = []*survey.Question{