Commit 8ff498b6 authored by Umberto Baldi's avatar Umberto Baldi

general improvements for consistency between commands

parent aeb15287
...@@ -47,7 +47,7 @@ func NewCommand() *cobra.Command { ...@@ -47,7 +47,7 @@ func NewCommand() *cobra.Command {
Long: tr("Upload the bootloader on the board using an external programmer."), Long: tr("Upload the bootloader on the board using an external programmer."),
Example: " " + os.Args[0] + " burn-bootloader -b arduino:avr:uno -P atmel_ice", Example: " " + os.Args[0] + " burn-bootloader -b arduino:avr:uno -P atmel_ice",
Args: cobra.MaximumNArgs(1), Args: cobra.MaximumNArgs(1),
Run: run, Run: runBootloaderCommand,
} }
fqbn.AddToCommand(burnBootloaderCommand) fqbn.AddToCommand(burnBootloaderCommand)
...@@ -61,7 +61,7 @@ func NewCommand() *cobra.Command { ...@@ -61,7 +61,7 @@ func NewCommand() *cobra.Command {
return burnBootloaderCommand return burnBootloaderCommand
} }
func run(command *cobra.Command, args []string) { func runBootloaderCommand(command *cobra.Command, args []string) {
instance := instance.CreateAndInit() instance := instance.CreateAndInit()
// We don't need a Sketch to upload a board's bootloader // We don't need a Sketch to upload a board's bootloader
......
...@@ -76,7 +76,7 @@ func NewCommand() *cobra.Command { ...@@ -76,7 +76,7 @@ func NewCommand() *cobra.Command {
" " + os.Args[0] + ` compile -b arduino:avr:uno --build-property "build.extra_flags=-DPIN=2 \"-DMY_DEFINE=\"hello world\"\"" /home/user/Arduino/MySketch` + "\n" + " " + os.Args[0] + ` compile -b arduino:avr:uno --build-property "build.extra_flags=-DPIN=2 \"-DMY_DEFINE=\"hello world\"\"" /home/user/Arduino/MySketch` + "\n" +
" " + 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", " " + 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",
Args: cobra.MaximumNArgs(1), Args: cobra.MaximumNArgs(1),
Run: run, Run: runCompileCommand,
} }
fqbn.AddToCommand(compileCommand) fqbn.AddToCommand(compileCommand)
...@@ -120,7 +120,7 @@ func NewCommand() *cobra.Command { ...@@ -120,7 +120,7 @@ func NewCommand() *cobra.Command {
return compileCommand return compileCommand
} }
func run(cmd *cobra.Command, args []string) { func runCompileCommand(cmd *cobra.Command, args []string) {
inst := instance.CreateAndInit() inst := instance.CreateAndInit()
path := "" path := ""
......
...@@ -31,7 +31,7 @@ var ( ...@@ -31,7 +31,7 @@ var (
// NewCommand created a new `completion` command // NewCommand created a new `completion` command
func NewCommand() *cobra.Command { func NewCommand() *cobra.Command {
command := &cobra.Command{ completionCommand := &cobra.Command{
Use: "completion [bash|zsh|fish|powershell] [--no-descriptions]", Use: "completion [bash|zsh|fish|powershell] [--no-descriptions]",
ValidArgs: []string{"bash", "zsh", "fish", "powershell"}, ValidArgs: []string{"bash", "zsh", "fish", "powershell"},
Args: cobra.ExactArgs(1), Args: cobra.ExactArgs(1),
...@@ -39,14 +39,14 @@ func NewCommand() *cobra.Command { ...@@ -39,14 +39,14 @@ func NewCommand() *cobra.Command {
Long: tr("Generates completion scripts for various shells"), Long: tr("Generates completion scripts for various shells"),
Example: " " + os.Args[0] + " completion bash > completion.sh\n" + Example: " " + os.Args[0] + " completion bash > completion.sh\n" +
" " + "source completion.sh", " " + "source completion.sh",
Run: run, Run: runCompletionCommand,
} }
command.Flags().BoolVar(&completionNoDesc, "no-descriptions", false, tr("Disable completion description for shells that support it")) completionCommand.Flags().BoolVar(&completionNoDesc, "no-descriptions", false, tr("Disable completion description for shells that support it"))
return command return completionCommand
} }
func run(cmd *cobra.Command, args []string) { func runCompletionCommand(cmd *cobra.Command, args []string) {
if completionNoDesc && (args[0] == "powershell") { if completionNoDesc && (args[0] == "powershell") {
feedback.Errorf(tr("Error: command description is not supported by %v"), args[0]) feedback.Errorf(tr("Error: command description is not supported by %v"), args[0])
os.Exit(errorcodes.ErrGeneric) os.Exit(errorcodes.ErrGeneric)
......
...@@ -36,7 +36,7 @@ func NewCommand() *cobra.Command { ...@@ -36,7 +36,7 @@ func NewCommand() *cobra.Command {
configCommand.AddCommand(initAddCommand()) configCommand.AddCommand(initAddCommand())
configCommand.AddCommand(initDeleteCommand()) configCommand.AddCommand(initDeleteCommand())
configCommand.AddCommand(initDumpCmd()) configCommand.AddCommand(initDumpCommand())
configCommand.AddCommand(initInitCommand()) configCommand.AddCommand(initInitCommand())
configCommand.AddCommand(initRemoveCommand()) configCommand.AddCommand(initRemoveCommand())
configCommand.AddCommand(initSetCommand()) configCommand.AddCommand(initSetCommand())
......
...@@ -27,7 +27,7 @@ import ( ...@@ -27,7 +27,7 @@ import (
) )
func initDeleteCommand() *cobra.Command { func initDeleteCommand() *cobra.Command {
addCommand := &cobra.Command{ deleteCommand := &cobra.Command{
Use: "delete", Use: "delete",
Short: tr("Deletes a settings key and all its sub keys."), Short: tr("Deletes a settings key and all its sub keys."),
Long: tr("Deletes a settings key and all its sub keys."), Long: tr("Deletes a settings key and all its sub keys."),
...@@ -40,7 +40,7 @@ func initDeleteCommand() *cobra.Command { ...@@ -40,7 +40,7 @@ func initDeleteCommand() *cobra.Command {
return configuration.Settings.AllKeys(), cobra.ShellCompDirectiveDefault return configuration.Settings.AllKeys(), cobra.ShellCompDirectiveDefault
}, },
} }
return addCommand return deleteCommand
} }
func runDeleteCommand(cmd *cobra.Command, args []string) { func runDeleteCommand(cmd *cobra.Command, args []string) {
......
...@@ -25,8 +25,8 @@ import ( ...@@ -25,8 +25,8 @@ import (
"gopkg.in/yaml.v2" "gopkg.in/yaml.v2"
) )
func initDumpCmd() *cobra.Command { func initDumpCommand() *cobra.Command {
var dumpCmd = &cobra.Command{ var dumpCommand = &cobra.Command{
Use: "dump", Use: "dump",
Short: tr("Prints the current configuration"), Short: tr("Prints the current configuration"),
Long: tr("Prints the current configuration."), Long: tr("Prints the current configuration."),
...@@ -34,7 +34,12 @@ func initDumpCmd() *cobra.Command { ...@@ -34,7 +34,12 @@ func initDumpCmd() *cobra.Command {
Args: cobra.NoArgs, Args: cobra.NoArgs,
Run: runDumpCommand, Run: runDumpCommand,
} }
return dumpCmd return dumpCommand
}
func runDumpCommand(cmd *cobra.Command, args []string) {
logrus.Info("Executing `arduino config dump`")
feedback.PrintResult(dumpResult{configuration.Settings.AllSettings()})
} }
// output from this command requires special formatting, let's create a dedicated // output from this command requires special formatting, let's create a dedicated
...@@ -56,8 +61,3 @@ func (dr dumpResult) String() string { ...@@ -56,8 +61,3 @@ func (dr dumpResult) String() string {
return string(bs) return string(bs)
} }
func runDumpCommand(cmd *cobra.Command, args []string) {
logrus.Info("Executing `arduino config dump`")
feedback.PrintResult(dumpResult{configuration.Settings.AllSettings()})
}
...@@ -26,7 +26,7 @@ import ( ...@@ -26,7 +26,7 @@ import (
) )
func initRemoveCommand() *cobra.Command { func initRemoveCommand() *cobra.Command {
addCommand := &cobra.Command{ removeCommand := &cobra.Command{
Use: "remove", Use: "remove",
Short: tr("Removes one or more values from a setting."), Short: tr("Removes one or more values from a setting."),
Long: tr("Removes one or more values from a setting."), Long: tr("Removes one or more values from a setting."),
...@@ -39,7 +39,7 @@ func initRemoveCommand() *cobra.Command { ...@@ -39,7 +39,7 @@ func initRemoveCommand() *cobra.Command {
return GetConfigurationKeys(), cobra.ShellCompDirectiveDefault return GetConfigurationKeys(), cobra.ShellCompDirectiveDefault
}, },
} }
return addCommand return removeCommand
} }
func runRemoveCommand(cmd *cobra.Command, args []string) { func runRemoveCommand(cmd *cobra.Command, args []string) {
......
...@@ -27,7 +27,7 @@ import ( ...@@ -27,7 +27,7 @@ import (
) )
func initSetCommand() *cobra.Command { func initSetCommand() *cobra.Command {
addCommand := &cobra.Command{ setCommand := &cobra.Command{
Use: "set", Use: "set",
Short: tr("Sets a setting value."), Short: tr("Sets a setting value."),
Long: tr("Sets a setting value."), Long: tr("Sets a setting value."),
...@@ -42,7 +42,7 @@ func initSetCommand() *cobra.Command { ...@@ -42,7 +42,7 @@ func initSetCommand() *cobra.Command {
return configuration.Settings.AllKeys(), cobra.ShellCompDirectiveDefault return configuration.Settings.AllKeys(), cobra.ShellCompDirectiveDefault
}, },
} }
return addCommand return setCommand
} }
func runSetCommand(cmd *cobra.Command, args []string) { func runSetCommand(cmd *cobra.Command, args []string) {
......
...@@ -32,7 +32,7 @@ import ( ...@@ -32,7 +32,7 @@ import (
) )
func initUninstallCommand() *cobra.Command { func initUninstallCommand() *cobra.Command {
return &cobra.Command{ uninstallCommand := &cobra.Command{
Use: fmt.Sprintf("uninstall %s:%s ...", tr("PACKAGER"), tr("ARCH")), Use: fmt.Sprintf("uninstall %s:%s ...", tr("PACKAGER"), tr("ARCH")),
Short: tr("Uninstalls one or more cores and corresponding tool dependencies if no longer used."), Short: tr("Uninstalls one or more cores and corresponding tool dependencies if no longer used."),
Long: tr("Uninstalls one or more cores and corresponding tool dependencies if no longer used."), Long: tr("Uninstalls one or more cores and corresponding tool dependencies if no longer used."),
...@@ -43,6 +43,7 @@ func initUninstallCommand() *cobra.Command { ...@@ -43,6 +43,7 @@ func initUninstallCommand() *cobra.Command {
return arguments.GetUninstallableCores(), cobra.ShellCompDirectiveDefault return arguments.GetUninstallableCores(), cobra.ShellCompDirectiveDefault
}, },
} }
return uninstallCommand
} }
func runUninstallCommand(cmd *cobra.Command, args []string) { func runUninstallCommand(cmd *cobra.Command, args []string) {
......
...@@ -50,7 +50,7 @@ var ( ...@@ -50,7 +50,7 @@ var (
// NewCommand created a new `daemon` command // NewCommand created a new `daemon` command
func NewCommand() *cobra.Command { func NewCommand() *cobra.Command {
cmd := &cobra.Command{ daemonCommand := &cobra.Command{
Use: "daemon", Use: "daemon",
Short: tr("Run as a daemon on port: %s", configuration.Settings.GetString("daemon.port")), Short: tr("Run as a daemon on port: %s", configuration.Settings.GetString("daemon.port")),
Long: tr("Running as a daemon the initialization of cores and libraries is done only once."), Long: tr("Running as a daemon the initialization of cores and libraries is done only once."),
...@@ -58,12 +58,12 @@ func NewCommand() *cobra.Command { ...@@ -58,12 +58,12 @@ func NewCommand() *cobra.Command {
Args: cobra.NoArgs, Args: cobra.NoArgs,
Run: runDaemonCommand, Run: runDaemonCommand,
} }
cmd.PersistentFlags().String("port", "", tr("The TCP port the daemon will listen to")) daemonCommand.PersistentFlags().String("port", "", tr("The TCP port the daemon will listen to"))
configuration.Settings.BindPFlag("daemon.port", cmd.PersistentFlags().Lookup("port")) configuration.Settings.BindPFlag("daemon.port", daemonCommand.PersistentFlags().Lookup("port"))
cmd.Flags().BoolVar(&daemonize, "daemonize", false, tr("Do not terminate daemon process if the parent process dies")) daemonCommand.Flags().BoolVar(&daemonize, "daemonize", false, tr("Do not terminate daemon process if the parent process dies"))
cmd.Flags().BoolVar(&debug, "debug", false, tr("Enable debug logging of gRPC calls")) daemonCommand.Flags().BoolVar(&debug, "debug", false, tr("Enable debug logging of gRPC calls"))
cmd.Flags().StringSliceVar(&debugFilters, "debug-filter", []string{}, tr("Display only the provided gRPC calls")) daemonCommand.Flags().StringSliceVar(&debugFilters, "debug-filter", []string{}, tr("Display only the provided gRPC calls"))
return cmd return daemonCommand
} }
func runDaemonCommand(cmd *cobra.Command, args []string) { func runDaemonCommand(cmd *cobra.Command, args []string) {
......
...@@ -31,9 +31,9 @@ var ( ...@@ -31,9 +31,9 @@ var (
tr = i18n.Tr tr = i18n.Tr
) )
// NewCommand created a new `generatedocs` command // NewCommand created a new `generate-docs` command
func NewCommand() *cobra.Command { func NewCommand() *cobra.Command {
command := &cobra.Command{ generateDocsCommand := &cobra.Command{
Use: "generate-docs", Use: "generate-docs",
Short: tr("Generates bash completion and command manpages."), Short: tr("Generates bash completion and command manpages."),
Long: tr("Generates bash completion and command manpages."), Long: tr("Generates bash completion and command manpages."),
...@@ -41,20 +41,20 @@ func NewCommand() *cobra.Command { ...@@ -41,20 +41,20 @@ func NewCommand() *cobra.Command {
Hidden: true, Hidden: true,
} }
command.PersistentFlags().StringVarP(&outputDir, "output-dir", "o", "", generateDocsCommand.PersistentFlags().StringVarP(&outputDir, "output-dir", "o", "",
tr("Directory where to save generated files. Default is './docs', the directory must exist.")) tr("Directory where to save generated files. Default is './docs', the directory must exist."))
command.AddCommand(&cobra.Command{ generateDocsCommand.AddCommand(&cobra.Command{
Use: "manpage", Use: "manpage",
Args: cobra.NoArgs, Args: cobra.NoArgs,
Run: generateManPages, Run: generateManPages,
}) })
command.AddCommand(&cobra.Command{ generateDocsCommand.AddCommand(&cobra.Command{
Use: "bash-completions", Use: "bash-completions",
Args: cobra.NoArgs, Args: cobra.NoArgs,
Run: generateBashCompletions, Run: generateBashCompletions,
}) })
return command return generateDocsCommand
} }
func generateBashCompletions(cmd *cobra.Command, args []string) { func generateBashCompletions(cmd *cobra.Command, args []string) {
......
...@@ -34,7 +34,7 @@ var includeBuildDir bool ...@@ -34,7 +34,7 @@ var includeBuildDir bool
// initArchiveCommand creates a new `archive` command // initArchiveCommand creates a new `archive` command
func initArchiveCommand() *cobra.Command { func initArchiveCommand() *cobra.Command {
command := &cobra.Command{ archiveCommand := &cobra.Command{
Use: fmt.Sprintf("archive <%s> <%s>", tr("sketchPath"), tr("archivePath")), Use: fmt.Sprintf("archive <%s> <%s>", tr("sketchPath"), tr("archivePath")),
Short: tr("Creates a zip file containing all sketch files."), Short: tr("Creates a zip file containing all sketch files."),
Long: tr("Creates a zip file containing all sketch files."), Long: tr("Creates a zip file containing all sketch files."),
...@@ -48,9 +48,9 @@ func initArchiveCommand() *cobra.Command { ...@@ -48,9 +48,9 @@ func initArchiveCommand() *cobra.Command {
Run: runArchiveCommand, Run: runArchiveCommand,
} }
command.Flags().BoolVar(&includeBuildDir, "include-build-dir", false, tr("Includes %s directory in the archive.", "build")) archiveCommand.Flags().BoolVar(&includeBuildDir, "include-build-dir", false, tr("Includes %s directory in the archive.", "build"))
return command return archiveCommand
} }
func runArchiveCommand(cmd *cobra.Command, args []string) { func runArchiveCommand(cmd *cobra.Command, args []string) {
......
...@@ -26,15 +26,15 @@ var tr = i18n.Tr ...@@ -26,15 +26,15 @@ var tr = i18n.Tr
// NewCommand created a new `sketch` command // NewCommand created a new `sketch` command
func NewCommand() *cobra.Command { func NewCommand() *cobra.Command {
cmd := &cobra.Command{ sketchCommand := &cobra.Command{
Use: "sketch", Use: "sketch",
Short: tr("Arduino CLI sketch commands."), Short: tr("Arduino CLI sketch commands."),
Long: tr("Arduino CLI sketch commands."), Long: tr("Arduino CLI sketch commands."),
Example: " " + os.Args[0] + " sketch new MySketch", Example: " " + os.Args[0] + " sketch new MySketch",
} }
cmd.AddCommand(initNewCommand()) sketchCommand.AddCommand(initNewCommand())
cmd.AddCommand(initArchiveCommand()) sketchCommand.AddCommand(initArchiveCommand())
return cmd return sketchCommand
} }
...@@ -32,17 +32,18 @@ var tr = i18n.Tr ...@@ -32,17 +32,18 @@ var tr = i18n.Tr
// NewCommand created a new `version` command // NewCommand created a new `version` command
func NewCommand() *cobra.Command { func NewCommand() *cobra.Command {
return &cobra.Command{ versionCommand := &cobra.Command{
Use: "version", Use: "version",
Short: tr("Shows version number of Arduino CLI."), Short: tr("Shows version number of Arduino CLI."),
Long: tr("Shows the version number of Arduino CLI which is installed on your system."), Long: tr("Shows the version number of Arduino CLI which is installed on your system."),
Example: " " + os.Args[0] + " version", Example: " " + os.Args[0] + " version",
Args: cobra.NoArgs, Args: cobra.NoArgs,
Run: run, Run: runVersionCommand,
} }
return versionCommand
} }
func run(cmd *cobra.Command, args []string) { func runVersionCommand(cmd *cobra.Command, args []string) {
if strings.Contains(globals.VersionInfo.VersionString, "git-snapshot") || strings.Contains(globals.VersionInfo.VersionString, "nightly") { if strings.Contains(globals.VersionInfo.VersionString, "git-snapshot") || strings.Contains(globals.VersionInfo.VersionString, "nightly") {
// We're using a development version, no need to check if there's a // We're using a development version, no need to check if there's a
// new release available // new release available
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment