|
| 1 | +package cli |
| 2 | + |
| 3 | +import ( |
| 4 | +"fmt" |
| 5 | + |
| 6 | +"github.com/google/uuid" |
| 7 | +"github.com/spf13/cobra" |
| 8 | +"golang.org/x/xerrors" |
| 9 | + |
| 10 | +"github.com/coder/coder/codersdk" |
| 11 | +) |
| 12 | + |
| 13 | +funcparameterList()*cobra.Command { |
| 14 | +var ( |
| 15 | +columns []string |
| 16 | +) |
| 17 | +cmd:=&cobra.Command{ |
| 18 | +Use:"list", |
| 19 | +Aliases: []string{"ls"}, |
| 20 | +Args:cobra.ExactArgs(2), |
| 21 | +RunE:func(cmd*cobra.Command,args []string)error { |
| 22 | +scope,name:=args[0],args[1] |
| 23 | + |
| 24 | +client,err:=createClient(cmd) |
| 25 | +iferr!=nil { |
| 26 | +returnerr |
| 27 | +} |
| 28 | + |
| 29 | +organization,err:=currentOrganization(cmd,client) |
| 30 | +iferr!=nil { |
| 31 | +returnxerrors.Errorf("get current organization: %w",err) |
| 32 | +} |
| 33 | + |
| 34 | +varscopeID uuid.UUID |
| 35 | +switchcodersdk.ParameterScope(scope) { |
| 36 | +casecodersdk.ParameterWorkspace: |
| 37 | +workspace,err:=namedWorkspace(cmd,client,name) |
| 38 | +iferr!=nil { |
| 39 | +returnerr |
| 40 | +} |
| 41 | +scopeID=workspace.ID |
| 42 | +casecodersdk.ParameterTemplate: |
| 43 | +template,err:=client.TemplateByName(cmd.Context(),organization.ID,name) |
| 44 | +iferr!=nil { |
| 45 | +returnxerrors.Errorf("get workspace template: %w",err) |
| 46 | +} |
| 47 | +scopeID=template.ID |
| 48 | + |
| 49 | +casecodersdk.ParameterScopeImportJob,"template_version": |
| 50 | +scope=string(codersdk.ParameterScopeImportJob) |
| 51 | +scopeID,err=uuid.Parse(name) |
| 52 | +iferr!=nil { |
| 53 | +returnxerrors.Errorf("%q must be a uuid for this scope type",name) |
| 54 | +} |
| 55 | +default: |
| 56 | +returnxerrors.Errorf("%q is an unsupported scope, use %v",scope, []codersdk.ParameterScope{ |
| 57 | +codersdk.ParameterWorkspace,codersdk.ParameterTemplate,codersdk.ParameterScopeImportJob, |
| 58 | +}) |
| 59 | +} |
| 60 | + |
| 61 | +params,err:=client.Parameters(cmd.Context(),codersdk.ParameterScope(scope),scopeID) |
| 62 | +iferr!=nil { |
| 63 | +returnxerrors.Errorf("fetch params: %w",err) |
| 64 | +} |
| 65 | + |
| 66 | +_,err=fmt.Fprintln(cmd.OutOrStdout(),displayParameters(columns,params...)) |
| 67 | +returnerr |
| 68 | +}, |
| 69 | +} |
| 70 | +cmd.Flags().StringArrayVarP(&columns,"column","c", []string{"name","source_scheme","destination_scheme"}, |
| 71 | +"Specify a column to filter in the table.") |
| 72 | +returncmd |
| 73 | +} |