Skip to content
This repository has been archived by the owner on Jul 31, 2024. It is now read-only.

Commit

Permalink
Merge pull request #54 from iljaSL/add-new-settings-cmd
Browse files Browse the repository at this point in the history
Add new settings cmd
  • Loading branch information
iljaSL authored Feb 16, 2024
2 parents 0da6d36 + fe1fa17 commit ce80204
Showing 1 changed file with 42 additions and 10 deletions.
52 changes: 42 additions & 10 deletions cmd/settings.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,6 @@ func init() {
rootCmd.AddCommand(settingsCmd())
}

//
//
func settingsCmd() *cobra.Command {
cmd := &cobra.Command{
Use: "settings",
Expand All @@ -45,12 +43,11 @@ func settingsCmd() *cobra.Command {
cmd.AddCommand(settingUpdateCmd())
cmd.AddCommand(schemaListCmd())
cmd.AddCommand(schemaShowCmd())
cmd.AddCommand(settingRestartRequiredCmd())

return cmd
}

//
//
func settingShowCmd() *cobra.Command {
options := settingsOptions{}

Expand Down Expand Up @@ -96,8 +93,6 @@ func settingShow(options settingsOptions) error {
}
}

//
//
func settingUpdateCmd() *cobra.Command {
options := settingsOptions{}

Expand Down Expand Up @@ -144,8 +139,6 @@ func settingUpdate(options settingsOptions, args []string) error {
return err
}

//
//
func schemaListCmd() *cobra.Command {
options := settingsOptions{}

Expand Down Expand Up @@ -179,8 +172,6 @@ func schemaList(options settingsOptions) error {
return stdout(res)
}

//
//
func schemaShowCmd() *cobra.Command {
options := settingsOptions{}

Expand Down Expand Up @@ -216,3 +207,44 @@ func schemaShow(options settingsOptions) error {

return stdout(res)
}

func settingRestartRequiredCmd() *cobra.Command {
options := settingsOptions{}

cmd := &cobra.Command{
Use: "restart-required",
Short: "Verify if restart is required.",
Long: `Verify if restart is required for given settings scope.`,
Example: `
privx-cli settings restart-required [access flags] --scope <SCOPE>
`,
Args: cobra.ExactArgs(1),
SilenceUsage: true,
RunE: func(cmd *cobra.Command, args []string) error {
return settingRestartRequired(options, args)
},
}

flags := cmd.Flags()
flags.StringVar(&options.scope, "scope", "", "scope setting name")
cmd.MarkFlagRequired("scope")

return cmd
}

func settingRestartRequired(options settingsOptions, args []string) error {
var s json.RawMessage
api := settings.New(curl())

err := decodeJSON(args[0], &s)
if err != nil {
return err
}

res, err := api.RestartRequired(&s, options.normalize_scope())
if err != nil {
return err
}

return stdout(res)
}

0 comments on commit ce80204

Please sign in to comment.