Skip to content

Commit c260881

Browse files
committed
Make --recursive flag a string input
Previously, the `--recursive` flag had a Boolean type. That is logical, since it uses values of true and false. However, the fact that the default value of this flag is true changes matters. With the other Boolean flags, the default value is false, so when you want to set it to true you only need to use the flag without a value, as is standard. But with a default true flag it's necessary to unset the value, which can't be done with a bare flag, so you must pass false to the flag. You would expect to be able to do this with either a space separator or an equals sign, just like with the string flags, but the former is not supported: $ ./arduino-check --recursive false Configuration error: PROJECT_PATH argument false does not exist Only the equals sign is supported (`--recursive=false`). So I think the UI is more intuitive with this flag a string type, so the behavior is consistent with the other flags.
1 parent 63844cd commit c260881

File tree

4 files changed

+10
-3
lines changed

4 files changed

+10
-3
lines changed

cli/cli.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ func Root() *cobra.Command {
3535
rootCommand.PersistentFlags().String("format", "text", "The output format can be {text|json}.")
3636
rootCommand.PersistentFlags().String("library-manager", "", "Configure the checks for libraries in the Arduino Library Manager index. Can be {submit|update|false}.\nsubmit: Also run additional checks required to pass before a library is accepted for inclusion in the index.\nupdate: Also run additional checks required to pass before new releases of a library already in the index are accepted.\nfalse: Don't run any Library Manager-specific checks.")
3737
rootCommand.PersistentFlags().String("project-type", "all", "Only check projects of the specified type and their subprojects. Can be {sketch|library|all}.")
38-
rootCommand.PersistentFlags().Bool("recursive", true, "Search path recursively for Arduino projects to check. Can be {true|false}.")
38+
rootCommand.PersistentFlags().String("recursive", "true", "Search path recursively for Arduino projects to check. Can be {true|false}.")
3939
rootCommand.PersistentFlags().String("report-file", "", "Save a report on the checks to this file.")
4040
rootCommand.PersistentFlags().BoolP("verbose", "v", false, "Show more information while running checks.")
4141
rootCommand.PersistentFlags().Bool("version", false, "Print version and timestamp of the build.")

configuration/configuration.go

+5-1
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,11 @@ func Initialize(flags *pflag.FlagSet, projectPaths []string) error {
8080
return fmt.Errorf("--project-type flag value %s not valid", superprojectTypeFilterString)
8181
}
8282

83-
recursive, _ = flags.GetBool("recursive")
83+
recursiveString, _ := flags.GetString("recursive")
84+
recursive, err = strconv.ParseBool(recursiveString)
85+
if err != nil {
86+
return fmt.Errorf("--recursive flag value %s not valid", recursiveString)
87+
}
8488

8589
reportFilePathString, _ := flags.GetString("report-file")
8690
reportFilePath = paths.New(reportFilePathString)

configuration/configuration_test.go

+3
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,9 @@ func TestInitializeProjectType(t *testing.T) {
160160
func TestInitializeRecursive(t *testing.T) {
161161
flags := test.ConfigurationFlags()
162162

163+
flags.Set("recursive", "foo")
164+
assert.Error(t, Initialize(flags, projectPaths))
165+
163166
flags.Set("recursive", "true")
164167
assert.Nil(t, Initialize(flags, projectPaths))
165168
assert.True(t, Recursive())

util/test/test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ func ConfigurationFlags() *pflag.FlagSet {
2727
flags.String("log-format", "text", "")
2828
flags.String("log-level", "panic", "")
2929
flags.String("project-type", "all", "")
30-
flags.Bool("recursive", true, "")
30+
flags.String("recursive", "true", "")
3131
flags.String("report-file", "", "")
3232
flags.Bool("verbose", false, "")
3333
flags.Bool("version", false, "")

0 commit comments

Comments
 (0)