-
Notifications
You must be signed in to change notification settings - Fork 44
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
Add configure flags
command for configuring CLI behavior
#436
Merged
+504
−40
Merged
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
f4b59de
chore: refactor logging environment notice
Piccirello d2603bb
Add `configure flags` command for configuring CLI behavior
Piccirello f55280c
chore: support managing analytics via flags
Piccirello 152110c
chore: support managing environment warning via flags
Piccirello 322fd32
chore: support disabling checking for updates via flags
Piccirello 183ad81
chore: support configuring flags via doppler.yaml
Piccirello 8eb10e0
chore: add e2e tests for flags
Piccirello 55a0f0c
chore: disabling checking for updates when running tests
Piccirello 2ae9ab9
chore: replace md5 with sha in tests
nmanoogian dde6f0e
chore: replace slices.Contains with utils.Contains
nmanoogian e093993
chore: update federacy/scan-action to 0.1.5
nmanoogian 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 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 |
---|---|---|
|
@@ -25,7 +25,7 @@ jobs: | |
- uses: actions/checkout@v2 | ||
- name: Salus Scan | ||
id: salus_scan | ||
uses: federacy/[email protected].4 | ||
uses: federacy/[email protected].5 | ||
env: | ||
SALUS_CONFIGURATION: "file://salus-config.yaml" | ||
with: | ||
|
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
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,151 @@ | ||
/* | ||
Copyright © 2023 Doppler <[email protected]> | ||
|
||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
|
||
http://www.apache.org/licenses/LICENSE-2.0 | ||
|
||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
package cmd | ||
|
||
import ( | ||
"errors" | ||
"fmt" | ||
|
||
"github.com/DopplerHQ/cli/pkg/configuration" | ||
"github.com/DopplerHQ/cli/pkg/models" | ||
"github.com/DopplerHQ/cli/pkg/printer" | ||
"github.com/DopplerHQ/cli/pkg/utils" | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
var configureFlagsCmd = &cobra.Command{ | ||
Use: "flags", | ||
Short: "View current flags", | ||
Args: cobra.NoArgs, | ||
Run: func(cmd *cobra.Command, args []string) { | ||
values := map[string]bool{} | ||
flags := models.GetFlags() | ||
for _, flag := range flags { | ||
value := configuration.GetFlag(flag) | ||
values[flag] = value | ||
} | ||
|
||
printer.Flags(values, utils.OutputJSON) | ||
}, | ||
} | ||
|
||
var configureFlagsGetCmd = &cobra.Command{ | ||
Use: "get [flag]", | ||
Short: "Get the value of a flag", | ||
ValidArgsFunction: FlagsValidArgs, | ||
Args: cobra.ExactArgs(1), | ||
Run: func(cmd *cobra.Command, args []string) { | ||
plain := utils.GetBoolFlag(cmd, "plain") | ||
|
||
flag := args[0] | ||
if !configuration.IsValidFlag(flag) { | ||
utils.HandleError(errors.New("invalid flag " + flag)) | ||
} | ||
|
||
enabled := configuration.GetFlag(flag) | ||
|
||
printer.Flag(flag, enabled, utils.OutputJSON, plain, false) | ||
}, | ||
} | ||
|
||
var configureFlagsEnableCmd = &cobra.Command{ | ||
Use: "enable [flag]", | ||
Short: "Enable a flag", | ||
ValidArgsFunction: FlagsValidArgs, | ||
Args: cobra.ExactArgs(1), | ||
Run: func(cmd *cobra.Command, args []string) { | ||
flag := args[0] | ||
if !configuration.IsValidFlag(flag) { | ||
utils.HandleError(errors.New("invalid flag " + flag)) | ||
} | ||
|
||
const value = true | ||
configuration.SetFlag(flag, value) | ||
|
||
if !utils.Silent { | ||
printer.Flag(flag, value, utils.OutputJSON, false, false) | ||
} | ||
}, | ||
} | ||
|
||
var configureFlagsDisableCmd = &cobra.Command{ | ||
Use: "disable [flag]", | ||
Short: "Disable a flag", | ||
ValidArgsFunction: FlagsValidArgs, | ||
Args: cobra.ExactArgs(1), | ||
Run: func(cmd *cobra.Command, args []string) { | ||
flag := args[0] | ||
if !configuration.IsValidFlag(flag) { | ||
utils.HandleError(errors.New("invalid flag " + flag)) | ||
} | ||
|
||
const value = false | ||
configuration.SetFlag(flag, value) | ||
|
||
if !utils.Silent { | ||
printer.Flag(flag, value, utils.OutputJSON, false, false) | ||
} | ||
}, | ||
} | ||
|
||
var configureFlagsResetCmd = &cobra.Command{ | ||
Use: "reset [flag]", | ||
Short: "Reset a flag to its default", | ||
Args: cobra.ExactArgs(1), | ||
Run: func(cmd *cobra.Command, args []string) { | ||
|
||
flag := args[0] | ||
if !configuration.IsValidFlag(flag) { | ||
utils.HandleError(errors.New("invalid flag " + flag)) | ||
} | ||
|
||
yes := utils.GetBoolFlag(cmd, "yes") | ||
defaultValue := configuration.GetFlagDefault(flag) | ||
|
||
if !yes { | ||
utils.PrintWarning(fmt.Sprintf("This will reset the %s flag to %t", flag, defaultValue)) | ||
if !utils.ConfirmationPrompt("Continue?", false) { | ||
utils.Log("Aborting") | ||
return | ||
} | ||
} | ||
|
||
configuration.SetFlag(flag, defaultValue) | ||
printer.Flag(flag, defaultValue, utils.OutputJSON, false, false) | ||
}, | ||
} | ||
|
||
func FlagsValidArgs(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) { | ||
persistentValidArgsFunction(cmd) | ||
|
||
return models.GetFlags(), cobra.ShellCompDirectiveNoFileComp | ||
} | ||
|
||
func init() { | ||
configureCmd.AddCommand(configureFlagsCmd) | ||
|
||
configureFlagsGetCmd.Flags().Bool("plain", false, "print value without formatting") | ||
configureFlagsCmd.AddCommand(configureFlagsGetCmd) | ||
|
||
configureFlagsCmd.AddCommand(configureFlagsEnableCmd) | ||
|
||
configureFlagsCmd.AddCommand(configureFlagsDisableCmd) | ||
|
||
configureFlagsResetCmd.Flags().BoolP("yes", "y", false, "proceed without confirmation") | ||
configureFlagsCmd.AddCommand(configureFlagsResetCmd) | ||
|
||
rootCmd.AddCommand(configureFlagsCmd) | ||
} |
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
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
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
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
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Relocated this logic from
loadFlags()
since the config file isn't loaded yet when that function runs.