@@ -20,13 +20,15 @@ import (
2020 "os"
2121 "path/filepath"
2222 "runtime"
23+ "slices"
2324 "strconv"
2425 "strings"
2526 "time"
2627
2728 "golang.org/x/mod/semver"
2829
2930 "github.com/spf13/cobra"
31+ "github.com/spf13/pflag"
3032 "github.com/spf13/viper"
3133
3234 daprRuntime "github.com/dapr/dapr/pkg/runtime"
@@ -78,18 +80,13 @@ const (
7880 runtimeWaitTimeoutInSeconds = 60
7981)
8082
81- // Flags that are incompatible with --run-file
82- var runFileIncompatibleFlags = []string {
83- "app-id" , "app-port" , "app-protocol" , "app-max-concurrency" ,
84- "app-ssl" , "app-channel-address" , "enable-app-health-check" ,
85- "app-health-check-path" , "app-health-probe-interval" ,
86- "app-health-probe-timeout" , "app-health-threshold" ,
87- "config" , "dapr-http-port" , "dapr-grpc-port" ,
88- "dapr-internal-grpc-port" , "enable-profiling" , "profile-port" ,
89- "dapr-http-max-request-size" , "dapr-http-read-buffer-size" ,
90- "metrics-port" , "placement-host-address" , "scheduler-host-address" ,
91- "components-path" , "resources-path" , "unix-domain-socket" ,
92- "enable-api-logging" , "dapr-listen-addresses" , "log-level" ,
83+ // Flags that are compatible with --run-file
84+ var runFileCompatibleFlags = []string {
85+ "kubernetes" ,
86+ "help" ,
87+ "version" ,
88+ "runtime-path" ,
89+ "log-as-json" ,
9390}
9491
9592var RunCmd = & cobra.Command {
@@ -1084,21 +1081,25 @@ func getRunFilePath(path string) (string, error) {
10841081 return path , nil
10851082}
10861083
1084+ // getConflictingFlags checks if any flags are set other than the ones passed in the excludedFlags slice.
1085+ // Used for logic or notifications when any of the flags are conflicting and should not be used together.
1086+ func getConflictingFlags (cmd * cobra.Command , excludedFlags ... string ) []string {
1087+ var conflictingFlags []string
1088+ cmd .Flags ().Visit (func (f * pflag.Flag ) {
1089+ if ! slices .Contains (excludedFlags , f .Name ) {
1090+ conflictingFlags = append (conflictingFlags , f .Name )
1091+ }
1092+ })
1093+ return conflictingFlags
1094+ }
1095+
10871096// detectIncompatibleFlags checks if any incompatible flags are used with --run-file
10881097// and returns a slice of the flag names that were used
10891098func detectIncompatibleFlags (cmd * cobra.Command ) []string {
10901099 if runFilePath == "" {
10911100 return nil // No run file specified, so no incompatibilities
10921101 }
10931102
1094- var incompatibleFlags []string
1095-
1096- // Check each incompatible flag to see if it was explicitly set
1097- for _ , flagName := range runFileIncompatibleFlags {
1098- if cmd .Flags ().Changed (flagName ) {
1099- incompatibleFlags = append (incompatibleFlags , flagName )
1100- }
1101- }
1102-
1103- return incompatibleFlags
1103+ // Get all flags that are not in the compatible list
1104+ return getConflictingFlags (cmd , append (runFileCompatibleFlags , "run-file" )... )
11041105}
0 commit comments