(state *globalState)
| 172 | } |
| 173 | |
| 174 | func (a *App) configSetCommand(state *globalState) *cobra.Command { |
| 175 | var app string |
| 176 | var scope string |
| 177 | cmd := &cobra.Command{ |
| 178 | Use: "set KEY[=VALUE] [VALUE]", |
| 179 | Short: "Set a configuration key", |
| 180 | Args: cobra.RangeArgs(1, 2), |
| 181 | RunE: func(cmd *cobra.Command, args []string) error { |
| 182 | out := cmd.OutOrStdout() |
| 183 | key, value, ok := splitKeyValue(args) |
| 184 | if !ok { |
| 185 | return fmt.Errorf("expected KEY=VALUE or KEY VALUE") |
| 186 | } |
| 187 | // Legacy CAM-config mode: when --config is set and --app is not. |
| 188 | if app == "" && state.configPath != "" { |
| 189 | if err := legacyApplyValue(state.configPath, key, value); err != nil { |
| 190 | return err |
| 191 | } |
| 192 | fmt.Fprintf(out, "Updated %s\n", key) |
| 193 | return nil |
| 194 | } |
| 195 | editor := app |
| 196 | if editor == "" { |
| 197 | return fmt.Errorf("--app is required (no --config supplied)") |
| 198 | } |
| 199 | tool, ok := editorconfig.DefaultRegistry().Get(editor) |
| 200 | if !ok { |
| 201 | return fmt.Errorf("Unknown app: %s", editor) |
| 202 | } |
| 203 | coerced := editorconfig.ParseScalar(value) |
| 204 | savedPath, err := tool.Set(scopeOrDefault(scope), key, coerced) |
| 205 | if err != nil { |
| 206 | return err |
| 207 | } |
| 208 | fmt.Fprintf(out, "Set %s = %v (%s scope)\n", key, coerced, scopeOrDefault(scope)) |
| 209 | fmt.Fprintf(out, " Config: %s\n", savedPath) |
| 210 | return nil |
| 211 | }, |
| 212 | } |
| 213 | cmd.Flags().StringVarP(&app, "app", "a", "", "Editor to set configuration for") |
| 214 | cmd.Flags().StringVarP(&scope, "scope", "s", "user", "Configuration scope (user|project)") |
| 215 | return cmd |
| 216 | } |
| 217 | |
| 218 | func (a *App) configUnsetCommand(state *globalState) *cobra.Command { |
| 219 | var app string |
no test coverage detected