(state *globalState)
| 216 | } |
| 217 | |
| 218 | func (a *App) configUnsetCommand(state *globalState) *cobra.Command { |
| 219 | var app string |
| 220 | var scope string |
| 221 | cmd := &cobra.Command{ |
| 222 | Use: "unset KEY", |
| 223 | Short: "Unset a configuration key", |
| 224 | Args: cobra.ExactArgs(1), |
| 225 | RunE: func(cmd *cobra.Command, args []string) error { |
| 226 | out := cmd.OutOrStdout() |
| 227 | key := args[0] |
| 228 | if app == "" && state.configPath != "" { |
| 229 | if err := legacyUnsetConfig(state.configPath, key); err != nil { |
| 230 | return err |
| 231 | } |
| 232 | fmt.Fprintf(out, "Removed %s\n", key) |
| 233 | return nil |
| 234 | } |
| 235 | editor := app |
| 236 | if editor == "" { |
| 237 | return fmt.Errorf("--app is required (no --config supplied)") |
| 238 | } |
| 239 | tool, ok := editorconfig.DefaultRegistry().Get(editor) |
| 240 | if !ok { |
| 241 | return fmt.Errorf("Unknown app: %s", editor) |
| 242 | } |
| 243 | found, _, err := tool.Unset(scopeOrDefault(scope), key) |
| 244 | if err != nil { |
| 245 | return err |
| 246 | } |
| 247 | if !found { |
| 248 | fmt.Fprintf(out, "Key not found: %s\n", key) |
| 249 | return nil |
| 250 | } |
| 251 | fmt.Fprintf(out, "Unset %s from %s scope\n", key, scopeOrDefault(scope)) |
| 252 | return nil |
| 253 | }, |
| 254 | } |
| 255 | cmd.Flags().StringVarP(&app, "app", "a", "", "Editor to unset configuration for") |
| 256 | cmd.Flags().StringVarP(&scope, "scope", "s", "user", "Configuration scope (user|project)") |
| 257 | return cmd |
| 258 | } |
| 259 | |
| 260 | func scopeOrDefault(scope string) editorconfig.Scope { |
| 261 | if scope == "project" { |
no test coverage detected