github.com/leg100/ots@v0.0.7-0.20210919080622-034055ced4bd/cmd/ots/workspace_edit.go (about) 1 package main 2 3 import ( 4 "encoding/json" 5 "fmt" 6 7 "github.com/leg100/go-tfe" 8 "github.com/leg100/ots" 9 "github.com/spf13/cobra" 10 ) 11 12 func WorkspaceEditCommand(config ClientConfig) *cobra.Command { 13 var organization, workspace string 14 15 var opts tfe.WorkspaceUpdateOptions 16 17 cmd := &cobra.Command{ 18 Use: "edit [name]", 19 Short: "Edit a workspace", 20 Args: cobra.ExactArgs(1), 21 RunE: func(cmd *cobra.Command, args []string) error { 22 workspace = args[0] 23 24 client, err := config.NewClient() 25 if err != nil { 26 return err 27 } 28 29 ws, err := client.Workspaces().Update(cmd.Context(), organization, workspace, opts) 30 if err != nil { 31 return err 32 } 33 34 out, err := json.MarshalIndent(ws, "", " ") 35 if err != nil { 36 return err 37 } 38 39 fmt.Println(string(out)) 40 41 return nil 42 }, 43 } 44 45 opts.ExecutionMode = cmd.Flags().String("execution-mode", ots.DefaultExecutionMode, "Which execution mode to use. Valid values are remote, local") 46 47 cmd.Flags().StringVar(&organization, "organization", "", "Organization workspace belongs to") 48 cmd.MarkFlagRequired("organization") 49 50 return cmd 51 }