Skip to content

Commit 36663b9

Browse files
authored
Allow unknown-flags (#29)
1 parent 6006f3b commit 36663b9

File tree

3 files changed

+19
-9
lines changed

3 files changed

+19
-9
lines changed

main.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,9 @@ func main() {
4242

4343
func bootstrapper(fs afero.Fs) *cobra.Command {
4444
cmd := &cobra.Command{
45-
Use: "dynatrace-bootstrapper",
46-
RunE: run(fs),
45+
Use: "dynatrace-bootstrapper",
46+
RunE: run(fs),
47+
FParseErrWhitelist: cobra.FParseErrWhitelist{UnknownFlags: true},
4748
}
4849

4950
AddFlags(cmd)
@@ -70,6 +71,7 @@ func AddFlags(cmd *cobra.Command) {
7071
func run(fs afero.Fs) func(cmd *cobra.Command, _ []string) error {
7172
return func(cmd *cobra.Command, _ []string) error {
7273
setupLogger()
74+
7375
if isDebug {
7476
log.Info("debug logs enabled")
7577
}

main_test.go

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@ func TestBootstrapper(t *testing.T) {
4040

4141
require.NoError(t, err)
4242

43-
4443
cmd = bootstrapper(afero.NewMemMapFs())
4544
// Note: we can't skip/mask the validation of the required flags
4645
cmd.SetArgs([]string{"--source", "\\\\", "--target", "\\\\", "--suppress-error", "true"})
@@ -49,4 +48,13 @@ func TestBootstrapper(t *testing.T) {
4948

5049
require.NoError(t, err)
5150
})
51+
52+
t.Run("should allow unknown flags -> no error", func(t *testing.T) {
53+
cmd := bootstrapper(afero.NewMemMapFs())
54+
cmd.SetArgs([]string{"--source", "./", "--target", "./", "--unknown", "--flag", "value"})
55+
56+
err := cmd.Execute()
57+
58+
require.NoError(t, err)
59+
})
5260
}

pkg/configure/cmd.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,9 @@ import (
1818
)
1919

2020
const (
21-
inputFolderFlag = "input-directory"
22-
configFolderFlag = "config-directory"
23-
installPathFlag = "install-path"
21+
InputFolderFlag = "input-directory"
22+
ConfigFolderFlag = "config-directory"
23+
InstallPathFlag = "install-path"
2424
)
2525

2626
var (
@@ -33,11 +33,11 @@ var (
3333
)
3434

3535
func AddFlags(cmd *cobra.Command) {
36-
cmd.PersistentFlags().StringVar(&inputFolder, inputFolderFlag, "", "(Optional) Base path where to look for the configuration files.")
36+
cmd.PersistentFlags().StringVar(&inputFolder, InputFolderFlag, "", "(Optional) Base path where to look for the configuration files.")
3737

38-
cmd.PersistentFlags().StringVar(&configFolder, configFolderFlag, "", "(Optional) Base path where to put the configuration files.")
38+
cmd.PersistentFlags().StringVar(&configFolder, ConfigFolderFlag, "", "(Optional) Base path where to put the configuration files.")
3939

40-
cmd.PersistentFlags().StringVar(&installPath, installPathFlag, "/opt/dynatrace/oneagent", "(Optional) Base path where the agent binary will be put.")
40+
cmd.PersistentFlags().StringVar(&installPath, InstallPathFlag, "/opt/dynatrace/oneagent", "(Optional) Base path where the agent binary will be put.")
4141

4242
cmd.PersistentFlags().StringArrayVar(&containerAttributes, container.Flag, []string{}, "(Optional) Container-specific attributes in JSON format.")
4343

0 commit comments

Comments
 (0)