@@ -52,6 +52,8 @@ commands, respectively:
52
52
cmd .AddCommand (NewConfigUseContextCommand ())
53
53
cmd .AddCommand (NewConfigCreateContextCommand ())
54
54
cmd .AddCommand (NewConfigDeleteContextCommand ())
55
+ cmd .AddCommand (NewConfigSetRuntimeCommand ())
56
+ cmd .AddCommand (NewConfigGetRuntimeCommand ())
55
57
56
58
return cmd
57
59
}
@@ -139,6 +141,76 @@ func RunConfigCurrentContext(ctx context.Context) error {
139
141
return nil
140
142
}
141
143
144
+ func NewConfigSetRuntimeCommand () * cobra.Command {
145
+ cmd := & cobra.Command {
146
+ Use : "set-runtime RUNTIME" ,
147
+ Short : "Sets the default runtime name to use for the current authentication context" ,
148
+ Example : util .Doc (`
149
+ # Sets the default runtime to 'runtime-2':
150
+
151
+ <BIN> config set-runtime runtime-2` ),
152
+ RunE : func (cmd * cobra.Command , args []string ) error {
153
+ if len (args ) < 1 {
154
+ return fmt .Errorf ("must provide runtime name to use" )
155
+
156
+ }
157
+
158
+ return RunConfigSetRuntime (cmd .Context (), args [0 ])
159
+ },
160
+ }
161
+
162
+ return cmd
163
+ }
164
+
165
+ func RunConfigSetRuntime (ctx context.Context , runtime string ) error {
166
+ _ , err := cfConfig .NewClient ().V2 ().Runtime ().Get (ctx , runtime )
167
+ if err != nil {
168
+ return err
169
+ }
170
+
171
+ cur := cfConfig .GetCurrentContext ()
172
+ if cur .Name == "" {
173
+ log .G (ctx ).Fatal (util .Doc ("no currently selected context, use '<BIN> config use-context' to select a context" ))
174
+ }
175
+
176
+ cur .DefaultRuntime = runtime
177
+
178
+ if err := cfConfig .Save (); err != nil {
179
+ return fmt .Errorf ("failed to save config: %w" , err )
180
+ }
181
+
182
+ log .G (ctx ).Infof ("default runtime set to: %s" , runtime )
183
+
184
+ return nil
185
+ }
186
+
187
+ func NewConfigGetRuntimeCommand () * cobra.Command {
188
+ cmd := & cobra.Command {
189
+ Use : "get-runtime" ,
190
+ Short : "Gets the default runtime for the current authentication context" ,
191
+ Example : util .Doc (`
192
+ # Prints the default runtime:
193
+
194
+ <BIN> config get-runtime` ),
195
+ RunE : func (cmd * cobra.Command , args []string ) error {
196
+ return RunConfigGetRuntime (cmd .Context ())
197
+ },
198
+ }
199
+
200
+ return cmd
201
+ }
202
+
203
+ func RunConfigGetRuntime (ctx context.Context ) error {
204
+ cur := cfConfig .GetCurrentContext ()
205
+ if cur .DefaultRuntime == "" {
206
+ return fmt .Errorf (util .Doc ("no default runtime is set for current context, use '<BIN> config set-runtime' to set one" ))
207
+ }
208
+
209
+ log .G (ctx ).Infof ("default runtime set to: %s" , cur .DefaultRuntime )
210
+
211
+ return nil
212
+ }
213
+
142
214
func NewConfigUseContextCommand () * cobra.Command {
143
215
cmd := & cobra.Command {
144
216
Use : "use-context CONTEXT" ,
0 commit comments