-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
52 additions
and
1 deletion.
There are no files selected for viewing
This file contains 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,46 @@ | ||
package cmd | ||
|
||
import ( | ||
"errors" | ||
"fmt" | ||
"strings" | ||
|
||
"github.com/anoriqq/qpm/internal/config" | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
var configCmd = &cobra.Command{ | ||
Use: "config", | ||
Short: "update config", | ||
Example: ` # set ScriptDir to ~/.qpm | ||
qpm config ScriptDir ~/.qpm`, | ||
RunE: configRun, | ||
} | ||
|
||
func init() { | ||
rootCmd.AddCommand(configCmd) | ||
} | ||
|
||
var r = strings.NewReplacer("{", "", "}", "", ":", ": ") | ||
|
||
func configRun(_ *cobra.Command, args []string) error { | ||
if len(args) < 2 { | ||
return errors.New("config field and value is required") | ||
} | ||
if len(args) != 2 { | ||
return errors.New("too many arguments") | ||
} | ||
|
||
configField, configValue := args[0], args[1] | ||
|
||
switch strings.ToLower(configField) { | ||
case "scriptdir": | ||
config.SetScriptDir(configValue) | ||
default: | ||
return fmt.Errorf("unknown config field: %s", configField) | ||
} | ||
|
||
fmt.Println(r.Replace(fmt.Sprintf("%+v\n", config.Cfg))) | ||
|
||
return nil | ||
} |
This file contains 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