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

Add new settings cmd #54

Merged
merged 3 commits into from
Feb 16, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)
}
Loading