Skip to content

Commit af1b796

Browse files
committed
general improvements for consistency between commands
1 parent 79891ff commit af1b796

File tree

15 files changed

+69
-67
lines changed

15 files changed

+69
-67
lines changed

cli/burnbootloader/burnbootloader.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ func NewCommand() *cobra.Command {
4747
Long: tr("Upload the bootloader on the board using an external programmer."),
4848
Example: " " + os.Args[0] + " burn-bootloader -b arduino:avr:uno -P atmel_ice",
4949
Args: cobra.MaximumNArgs(1),
50-
Run: run,
50+
Run: runBootloaderCommand,
5151
}
5252

5353
fqbn.AddToCommand(burnBootloaderCommand)
@@ -61,7 +61,7 @@ func NewCommand() *cobra.Command {
6161
return burnBootloaderCommand
6262
}
6363

64-
func run(command *cobra.Command, args []string) {
64+
func runBootloaderCommand(command *cobra.Command, args []string) {
6565
instance := instance.CreateAndInit()
6666

6767
// We don't need a Sketch to upload a board's bootloader

cli/compile/compile.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ func NewCommand() *cobra.Command {
7676
" " + os.Args[0] + ` compile -b arduino:avr:uno --build-property "build.extra_flags=-DPIN=2 \"-DMY_DEFINE=\"hello world\"\"" /home/user/Arduino/MySketch` + "\n" +
7777
" " + os.Args[0] + ` compile -b arduino:avr:uno --build-property build.extra_flags=-DPIN=2 --build-property "compiler.cpp.extra_flags=\"-DSSID=\"hello world\"\"" /home/user/Arduino/MySketch` + "\n",
7878
Args: cobra.MaximumNArgs(1),
79-
Run: run,
79+
Run: runCompileCommand,
8080
}
8181

8282
fqbn.AddToCommand(compileCommand)
@@ -120,7 +120,7 @@ func NewCommand() *cobra.Command {
120120
return compileCommand
121121
}
122122

123-
func run(cmd *cobra.Command, args []string) {
123+
func runCompileCommand(cmd *cobra.Command, args []string) {
124124
inst := instance.CreateAndInit()
125125

126126
path := ""

cli/completion/completion.go

+5-5
Original file line numberDiff line numberDiff line change
@@ -31,22 +31,22 @@ var (
3131

3232
// NewCommand created a new `completion` command
3333
func NewCommand() *cobra.Command {
34-
command := &cobra.Command{
34+
completionCommand := &cobra.Command{
3535
Use: "completion [bash|zsh|fish|powershell] [--no-descriptions]",
3636
ValidArgs: []string{"bash", "zsh", "fish", "powershell"},
3737
Args: cobra.ExactArgs(1),
3838
Short: tr("Generates completion scripts"),
3939
Long: tr("Generates completion scripts for various shells"),
4040
Example: " " + os.Args[0] + " completion bash > completion.sh\n" +
4141
" " + "source completion.sh",
42-
Run: run,
42+
Run: runCompletionCommand,
4343
}
44-
command.Flags().BoolVar(&completionNoDesc, "no-descriptions", false, tr("Disable completion description for shells that support it"))
44+
completionCommand.Flags().BoolVar(&completionNoDesc, "no-descriptions", false, tr("Disable completion description for shells that support it"))
4545

46-
return command
46+
return completionCommand
4747
}
4848

49-
func run(cmd *cobra.Command, args []string) {
49+
func runCompletionCommand(cmd *cobra.Command, args []string) {
5050
if completionNoDesc && (args[0] == "powershell") {
5151
feedback.Errorf(tr("Error: command description is not supported by %v"), args[0])
5252
os.Exit(errorcodes.ErrGeneric)

cli/config/config.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ func NewCommand() *cobra.Command {
3636

3737
configCommand.AddCommand(initAddCommand())
3838
configCommand.AddCommand(initDeleteCommand())
39-
configCommand.AddCommand(initDumpCmd())
39+
configCommand.AddCommand(initDumpCommand())
4040
configCommand.AddCommand(initInitCommand())
4141
configCommand.AddCommand(initRemoveCommand())
4242
configCommand.AddCommand(initSetCommand())

cli/config/delete.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ import (
2727
)
2828

2929
func initDeleteCommand() *cobra.Command {
30-
addCommand := &cobra.Command{
30+
deleteCommand := &cobra.Command{
3131
Use: "delete",
3232
Short: tr("Deletes a settings key and all its sub keys."),
3333
Long: tr("Deletes a settings key and all its sub keys."),
@@ -40,7 +40,7 @@ func initDeleteCommand() *cobra.Command {
4040
return configuration.Settings.AllKeys(), cobra.ShellCompDirectiveDefault
4141
},
4242
}
43-
return addCommand
43+
return deleteCommand
4444
}
4545

4646
func runDeleteCommand(cmd *cobra.Command, args []string) {

cli/config/dump.go

+8-8
Original file line numberDiff line numberDiff line change
@@ -25,16 +25,21 @@ import (
2525
"gopkg.in/yaml.v2"
2626
)
2727

28-
func initDumpCmd() *cobra.Command {
29-
var dumpCmd = &cobra.Command{
28+
func initDumpCommand() *cobra.Command {
29+
var dumpCommand = &cobra.Command{
3030
Use: "dump",
3131
Short: tr("Prints the current configuration"),
3232
Long: tr("Prints the current configuration."),
3333
Example: " " + os.Args[0] + " config dump",
3434
Args: cobra.NoArgs,
3535
Run: runDumpCommand,
3636
}
37-
return dumpCmd
37+
return dumpCommand
38+
}
39+
40+
func runDumpCommand(cmd *cobra.Command, args []string) {
41+
logrus.Info("Executing `arduino config dump`")
42+
feedback.PrintResult(dumpResult{configuration.Settings.AllSettings()})
3843
}
3944

4045
// output from this command requires special formatting, let's create a dedicated
@@ -56,8 +61,3 @@ func (dr dumpResult) String() string {
5661

5762
return string(bs)
5863
}
59-
60-
func runDumpCommand(cmd *cobra.Command, args []string) {
61-
logrus.Info("Executing `arduino config dump`")
62-
feedback.PrintResult(dumpResult{configuration.Settings.AllSettings()})
63-
}

cli/config/remove.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ import (
2626
)
2727

2828
func initRemoveCommand() *cobra.Command {
29-
addCommand := &cobra.Command{
29+
removeCommand := &cobra.Command{
3030
Use: "remove",
3131
Short: tr("Removes one or more values from a setting."),
3232
Long: tr("Removes one or more values from a setting."),
@@ -39,7 +39,7 @@ func initRemoveCommand() *cobra.Command {
3939
return GetConfigurationKeys(), cobra.ShellCompDirectiveDefault
4040
},
4141
}
42-
return addCommand
42+
return removeCommand
4343
}
4444

4545
func runRemoveCommand(cmd *cobra.Command, args []string) {

cli/config/set.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ import (
2727
)
2828

2929
func initSetCommand() *cobra.Command {
30-
addCommand := &cobra.Command{
30+
setCommand := &cobra.Command{
3131
Use: "set",
3232
Short: tr("Sets a setting value."),
3333
Long: tr("Sets a setting value."),
@@ -42,7 +42,7 @@ func initSetCommand() *cobra.Command {
4242
return configuration.Settings.AllKeys(), cobra.ShellCompDirectiveDefault
4343
},
4444
}
45-
return addCommand
45+
return setCommand
4646
}
4747

4848
func runSetCommand(cmd *cobra.Command, args []string) {

cli/core/uninstall.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ import (
3232
)
3333

3434
func initUninstallCommand() *cobra.Command {
35-
return &cobra.Command{
35+
uninstallCommand := &cobra.Command{
3636
Use: fmt.Sprintf("uninstall %s:%s ...", tr("PACKAGER"), tr("ARCH")),
3737
Short: tr("Uninstalls one or more cores and corresponding tool dependencies if no longer used."),
3838
Long: tr("Uninstalls one or more cores and corresponding tool dependencies if no longer used."),
@@ -43,6 +43,7 @@ func initUninstallCommand() *cobra.Command {
4343
return arguments.GetUninstallableCores(), cobra.ShellCompDirectiveDefault
4444
},
4545
}
46+
return uninstallCommand
4647
}
4748

4849
func runUninstallCommand(cmd *cobra.Command, args []string) {

cli/daemon/daemon.go

+7-7
Original file line numberDiff line numberDiff line change
@@ -50,20 +50,20 @@ var (
5050

5151
// NewCommand created a new `daemon` command
5252
func NewCommand() *cobra.Command {
53-
cmd := &cobra.Command{
53+
daemonCommand := &cobra.Command{
5454
Use: "daemon",
5555
Short: tr("Run as a daemon on port: %s", configuration.Settings.GetString("daemon.port")),
5656
Long: tr("Running as a daemon the initialization of cores and libraries is done only once."),
5757
Example: " " + os.Args[0] + " daemon",
5858
Args: cobra.NoArgs,
5959
Run: runDaemonCommand,
6060
}
61-
cmd.PersistentFlags().String("port", "", tr("The TCP port the daemon will listen to"))
62-
configuration.Settings.BindPFlag("daemon.port", cmd.PersistentFlags().Lookup("port"))
63-
cmd.Flags().BoolVar(&daemonize, "daemonize", false, tr("Do not terminate daemon process if the parent process dies"))
64-
cmd.Flags().BoolVar(&debug, "debug", false, tr("Enable debug logging of gRPC calls"))
65-
cmd.Flags().StringSliceVar(&debugFilters, "debug-filter", []string{}, tr("Display only the provided gRPC calls"))
66-
return cmd
61+
daemonCommand.PersistentFlags().String("port", "", tr("The TCP port the daemon will listen to"))
62+
configuration.Settings.BindPFlag("daemon.port", daemonCommand.PersistentFlags().Lookup("port"))
63+
daemonCommand.Flags().BoolVar(&daemonize, "daemonize", false, tr("Do not terminate daemon process if the parent process dies"))
64+
daemonCommand.Flags().BoolVar(&debug, "debug", false, tr("Enable debug logging of gRPC calls"))
65+
daemonCommand.Flags().StringSliceVar(&debugFilters, "debug-filter", []string{}, tr("Display only the provided gRPC calls"))
66+
return daemonCommand
6767
}
6868

6969
func runDaemonCommand(cmd *cobra.Command, args []string) {

cli/generatedocs/generatedocs.go

+6-6
Original file line numberDiff line numberDiff line change
@@ -31,30 +31,30 @@ var (
3131
tr = i18n.Tr
3232
)
3333

34-
// NewCommand created a new `generatedocs` command
34+
// NewCommand created a new `generate-docs` command
3535
func NewCommand() *cobra.Command {
36-
command := &cobra.Command{
36+
generateDocsCommand := &cobra.Command{
3737
Use: "generate-docs",
3838
Short: tr("Generates bash completion and command manpages."),
3939
Long: tr("Generates bash completion and command manpages."),
4040
Example: " " + os.Args[0] + " generate-docs bash-completions",
4141
Hidden: true,
4242
}
4343

44-
command.PersistentFlags().StringVarP(&outputDir, "output-dir", "o", "",
44+
generateDocsCommand.PersistentFlags().StringVarP(&outputDir, "output-dir", "o", "",
4545
tr("Directory where to save generated files. Default is './docs', the directory must exist."))
46-
command.AddCommand(&cobra.Command{
46+
generateDocsCommand.AddCommand(&cobra.Command{
4747
Use: "manpage",
4848
Args: cobra.NoArgs,
4949
Run: generateManPages,
5050
})
51-
command.AddCommand(&cobra.Command{
51+
generateDocsCommand.AddCommand(&cobra.Command{
5252
Use: "bash-completions",
5353
Args: cobra.NoArgs,
5454
Run: generateBashCompletions,
5555
})
5656

57-
return command
57+
return generateDocsCommand
5858
}
5959

6060
func generateBashCompletions(cmd *cobra.Command, args []string) {

cli/sketch/archive.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ var includeBuildDir bool
3434

3535
// initArchiveCommand creates a new `archive` command
3636
func initArchiveCommand() *cobra.Command {
37-
command := &cobra.Command{
37+
archiveCommand := &cobra.Command{
3838
Use: fmt.Sprintf("archive <%s> <%s>", tr("sketchPath"), tr("archivePath")),
3939
Short: tr("Creates a zip file containing all sketch files."),
4040
Long: tr("Creates a zip file containing all sketch files."),
@@ -48,9 +48,9 @@ func initArchiveCommand() *cobra.Command {
4848
Run: runArchiveCommand,
4949
}
5050

51-
command.Flags().BoolVar(&includeBuildDir, "include-build-dir", false, tr("Includes %s directory in the archive.", "build"))
51+
archiveCommand.Flags().BoolVar(&includeBuildDir, "include-build-dir", false, tr("Includes %s directory in the archive.", "build"))
5252

53-
return command
53+
return archiveCommand
5454
}
5555

5656
func runArchiveCommand(cmd *cobra.Command, args []string) {

cli/sketch/sketch.go

+4-4
Original file line numberDiff line numberDiff line change
@@ -26,15 +26,15 @@ var tr = i18n.Tr
2626

2727
// NewCommand created a new `sketch` command
2828
func NewCommand() *cobra.Command {
29-
cmd := &cobra.Command{
29+
sketchCommand := &cobra.Command{
3030
Use: "sketch",
3131
Short: tr("Arduino CLI sketch commands."),
3232
Long: tr("Arduino CLI sketch commands."),
3333
Example: " " + os.Args[0] + " sketch new MySketch",
3434
}
3535

36-
cmd.AddCommand(initNewCommand())
37-
cmd.AddCommand(initArchiveCommand())
36+
sketchCommand.AddCommand(initNewCommand())
37+
sketchCommand.AddCommand(initArchiveCommand())
3838

39-
return cmd
39+
return sketchCommand
4040
}

cli/version/version.go

+4-3
Original file line numberDiff line numberDiff line change
@@ -32,17 +32,18 @@ var tr = i18n.Tr
3232

3333
// NewCommand created a new `version` command
3434
func NewCommand() *cobra.Command {
35-
return &cobra.Command{
35+
versionCommand := &cobra.Command{
3636
Use: "version",
3737
Short: tr("Shows version number of Arduino CLI."),
3838
Long: tr("Shows the version number of Arduino CLI which is installed on your system."),
3939
Example: " " + os.Args[0] + " version",
4040
Args: cobra.NoArgs,
41-
Run: run,
41+
Run: runVersionCommand,
4242
}
43+
return versionCommand
4344
}
4445

45-
func run(cmd *cobra.Command, args []string) {
46+
func runVersionCommand(cmd *cobra.Command, args []string) {
4647
if strings.Contains(globals.VersionInfo.VersionString, "git-snapshot") || strings.Contains(globals.VersionInfo.VersionString, "nightly") {
4748
// We're using a development version, no need to check if there's a
4849
// new release available

0 commit comments

Comments
 (0)