-
Notifications
You must be signed in to change notification settings - Fork 182
Feature/issue 419 config cmd #1127
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
omarbassem128
wants to merge
12
commits into
kitops-ml:main
Choose a base branch
from
omarbassem128:feature/issue-419-config-cmd
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 10 commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
5c98e5d
feat(config): implement set subcommand with cross-platform support
omarbassem128 84da567
refactor: cleanup set subcommand implementation
omarbassem128 f7c518e
feat: add config get subcommand
omarbassem128 eb76217
refactor: remove closures from run commands
omarbassem128 bdb3562
feat: add config list command
omarbassem128 343852a
feat: add config reset command
omarbassem128 b66d0ba
refactor: Update error handling
omarbassem128 80e606d
feat: Replace map implementation with strict struct schema
omarbassem128 c404fbe
fix: handle missing config file in list and set commands
omarbassem128 201069d
feat: integrate config with root command options
omarbassem128 5d6d204
refactor(config): decouple storage path from config state and fix wri…
omarbassem128 89d6836
fix(cmd): initialize output streams before configuration parsing
omarbassem128 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,130 @@ | ||
| package config | ||
|
|
||
| import ( | ||
| "encoding/json" | ||
|
|
||
| "fmt" | ||
|
|
||
| "strings" | ||
|
|
||
| "github.com/kitops-ml/kitops/pkg/lib/util" | ||
| "github.com/kitops-ml/kitops/pkg/output" | ||
| "github.com/spf13/cobra" | ||
| ) | ||
|
|
||
| type Config struct { | ||
| ConfigHome string `yaml:"configHome" json:"configHome"` | ||
| Verbosity int `yaml:"verbosity" json:"verbosity"` | ||
| LogLevel string `yaml:"logLevel" json:"logLevel"` | ||
| ProgressBars string `yaml:"progressBars" json:"progressBars"` | ||
| } | ||
|
|
||
| func ConfigCommand() *cobra.Command { | ||
| cmd := &cobra.Command{ | ||
| Use: "config", | ||
| Short: configShortDesc, | ||
| Long: configLongDesc, | ||
| } | ||
| cmd.AddCommand(configSetCommand()) | ||
| cmd.AddCommand(configGetCommand()) | ||
| cmd.AddCommand(configListCommand()) | ||
| cmd.AddCommand(configResetCommand()) | ||
|
|
||
| return cmd | ||
| } | ||
|
|
||
| func configSetCommand() *cobra.Command { | ||
| cmd := &cobra.Command{ | ||
| Use: "set KEY VALUE", | ||
| Short: setConfigShortDesc, | ||
| Long: setConfigLongDesc, | ||
| RunE: runSetCommand, | ||
| } | ||
| cmd.Args = cobra.ExactArgs(2) | ||
|
|
||
| return cmd | ||
| } | ||
|
|
||
| func runSetCommand(cmd *cobra.Command, args []string) error { | ||
| if err := setConfig(args[0], args[1]); err != nil { | ||
| return output.Fatalf("%s", err) | ||
| } | ||
| return nil | ||
| } | ||
|
|
||
| func configGetCommand() *cobra.Command { | ||
| cmd := &cobra.Command{ | ||
| Use: "get KEY", | ||
| Short: getConfigShortDesc, | ||
| Long: getConfigLongDesc, | ||
| RunE: runGetCommand, | ||
| } | ||
| cmd.Args = cobra.ExactArgs(1) | ||
|
|
||
| return cmd | ||
| } | ||
|
|
||
| func runGetCommand(cmd *cobra.Command, args []string) error { | ||
| val, err := getConfig(args[0]) | ||
| if err != nil { | ||
| return output.Fatalf("%s", err) | ||
| } | ||
| fmt.Fprintln(output.GetOut(), val) | ||
| return nil | ||
| } | ||
|
|
||
| func configListCommand() *cobra.Command { | ||
| cmd := &cobra.Command{ | ||
| Use: "list", | ||
| Short: listConfigShortDesc, | ||
| Long: listConfigLongDesc, | ||
| RunE: runListCommand, | ||
| } | ||
| cmd.Args = cobra.NoArgs | ||
|
|
||
| return cmd | ||
| } | ||
|
|
||
| func runListCommand(cmd *cobra.Command, args []string) error { | ||
| configStruct, err := listConfig() | ||
| if err != nil { | ||
| return output.Fatalf("%s", err) | ||
| } | ||
|
|
||
| list, jsonErr := json.MarshalIndent(configStruct, "", " ") | ||
|
|
||
| if jsonErr != nil { | ||
| return jsonErr | ||
| } | ||
|
|
||
| output.Infoln(string(list)) | ||
|
|
||
| return nil | ||
| } | ||
|
|
||
| func configResetCommand() *cobra.Command { | ||
| cmd := &cobra.Command{ | ||
| Use: "reset", | ||
| Short: resetConfigShortDesc, | ||
| Long: resetConfigLongDesc, | ||
| RunE: runResetCommand, | ||
| } | ||
| cmd.Args = cobra.NoArgs | ||
|
|
||
| return cmd | ||
| } | ||
|
|
||
| func runResetCommand(cmd *cobra.Command, args []string) error { | ||
| warning := "Warning: this action is destructive and cannot be undone.Proceed? (y/N): " | ||
|
|
||
| choice, choiceErr := util.PromptForInput(warning, false) | ||
| if choiceErr != nil { | ||
| return choiceErr | ||
| } | ||
|
|
||
| if !strings.EqualFold(choice, "y") && !strings.EqualFold(choice, "yes") { | ||
| return nil | ||
| } | ||
|
|
||
| return resetConfig() | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.