Skip to content

Commit 7415e26

Browse files
cmaglieper1234
andauthored
[skip-changelog] Removed unnecessary fmt.*printf before tr(...) / Fixed i18n early static initialization problem (#1425)
* Removed unnecessary fmt.*printf * removed unused variable * Fixed i18n early static initialization problem #1425 (comment) these particular strings are not correctly handled by the i18n package because they are declared at package level before the call to i18n.Init(), and so are just returned as-is. * Fix lint errors and use error.Is instead of direct comparison * Revert "guard" in Tr function otherwise the unit-tests will fail: === RUN TestBoardOptions --- FAIL: TestBoardOptions (0.00s) panic: i18n.Tr called before i18n.Init() [recovered] panic: i18n.Tr called before i18n.Init() goroutine 9 [running]: testing.tRunner.func1.2(0xc56e00, 0xeaee20) /opt/hostedtoolcache/go/1.16.7/x64/src/testing/testing.go:1143 +0x332 testing.tRunner.func1(0xc0002a2f00) /opt/hostedtoolcache/go/1.16.7/x64/src/testing/testing.go:1146 +0x4b6 panic(0xc56e00, 0xeaee20) /opt/hostedtoolcache/go/1.16.7/x64/src/runtime/panic.go:965 +0x1b9 github.com/arduino/arduino-cli/i18n.Tr(0xdceacd, 0x28, 0x0, 0x0, 0x0, 0x0, 0x1) /home/runner/work/arduino-cli/arduino-cli/i18n/i18n.go:54 +0xd9 github.com/arduino/arduino-cli/arduino/cores.(*Board).GetBuildProperties(0x13bf060, 0xc0003b6150, 0xc000339400, 0x0, 0x0) /home/runner/work/arduino-cli/arduino-cli/arduino/cores/board.go:109 +0x69d github.com/arduino/arduino-cli/arduino/cores.(*Board).GeneratePropertiesForConfiguration(0x13bf060, 0xdb5f54, 0xe, 0xc000309ef0, 0xc911e0, 0xc0003b6000) /home/runner/work/arduino-cli/arduino-cli/arduino/cores/board.go:141 +0x28f github.com/arduino/arduino-cli/arduino/cores.TestBoardOptions(0xc0002a2f00) /home/runner/work/arduino-cli/arduino-cli/arduino/cores/board_test.go:298 +0x4bd testing.tRunner(0xc0002a2f00, 0xe052a8) /opt/hostedtoolcache/go/1.16.7/x64/src/testing/testing.go:1193 +0xef created by testing.(*T).Run /opt/hostedtoolcache/go/1.16.7/x64/src/testing/testing.go:1238 +0x2b3 FAIL github.com/arduino/arduino-cli/arduino/cores 0.021s === RUN TestIndexParsing --- FAIL: TestIndexParsing (0.00s) panic: i18n.Tr called before i18n.Init() [recovered] panic: i18n.Tr called before i18n.Init() * Apply suggestions from code review Co-authored-by: per1234 <[email protected]> Co-authored-by: per1234 <[email protected]>
1 parent 15e2452 commit 7415e26

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

57 files changed

+496
-595
lines changed

Diff for: arduino/builder/compilation_database.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -60,10 +60,10 @@ func LoadCompilationDatabase(file *paths.Path) (*CompilationDatabase, error) {
6060
// see https://clang.llvm.org/docs/JSONCompilationDatabase.html
6161
func (db *CompilationDatabase) SaveToFile() {
6262
if jsonContents, err := json.MarshalIndent(db.Contents, "", " "); err != nil {
63-
fmt.Printf(tr("Error serializing compilation database: %s"), err)
63+
fmt.Println(tr("Error serializing compilation database: %s", err))
6464
return
6565
} else if err := db.File.WriteFile(jsonContents); err != nil {
66-
fmt.Printf(tr("Error writing compilation database: %s"), err)
66+
fmt.Println(tr("Error writing compilation database: %s", err))
6767
}
6868
}
6969

@@ -75,7 +75,7 @@ func dirForCommand(command *exec.Cmd) string {
7575
}
7676
dir, err := os.Getwd()
7777
if err != nil {
78-
fmt.Printf(tr("Error getting current directory for compilation database: %s"), err)
78+
fmt.Println(tr("Error getting current directory for compilation database: %s", err))
7979
return ""
8080
}
8181
return dir

Diff for: arduino/discovery/discovery.go

+4-4
Original file line numberDiff line numberDiff line change
@@ -71,16 +71,16 @@ type discoveryMessage struct {
7171
func (msg discoveryMessage) String() string {
7272
s := fmt.Sprintf("type: %s", msg.EventType)
7373
if msg.Message != "" {
74-
s = fmt.Sprintf(tr("%[1]s, message: %[2]s"), s, msg.Message)
74+
s = tr("%[1]s, message: %[2]s", s, msg.Message)
7575
}
7676
if msg.ProtocolVersion != 0 {
77-
s = fmt.Sprintf(tr("%[1]s, protocol version: %[2]d"), s, msg.ProtocolVersion)
77+
s = tr("%[1]s, protocol version: %[2]d", s, msg.ProtocolVersion)
7878
}
7979
if len(msg.Ports) > 0 {
80-
s = fmt.Sprintf(tr("%[1]s, ports: %[2]s"), s, msg.Ports)
80+
s = tr("%[1]s, ports: %[2]s", s, msg.Ports)
8181
}
8282
if msg.Port != nil {
83-
s = fmt.Sprintf(tr("%[1]s, port: %[2]s"), s, msg.Port)
83+
s = tr("%[1]s, port: %[2]s", s, msg.Port)
8484
}
8585
return s
8686
}

Diff for: arduino/libraries/librariesmanager/install.go

+7-2
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ package librariesmanager
1717

1818
import (
1919
"context"
20-
"errors"
2120
"fmt"
2221
"net/url"
2322
"os"
@@ -32,10 +31,16 @@ import (
3231
"gopkg.in/src-d/go-git.v4"
3332
)
3433

34+
type alreadyInstalledError struct{}
35+
36+
func (e *alreadyInstalledError) Error() string {
37+
return tr("library already installed")
38+
}
39+
3540
var (
3641
// ErrAlreadyInstalled is returned when a library is already installed and task
3742
// cannot proceed.
38-
ErrAlreadyInstalled = errors.New(tr("library already installed"))
43+
ErrAlreadyInstalled = &alreadyInstalledError{}
3944
)
4045

4146
// InstallPrerequisiteCheck performs prequisite checks to install a library. It returns the

Diff for: arduino/libraries/librariesmanager/librariesmanager.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ var tr = i18n.Tr
6262
// Add adds a library to the alternatives
6363
func (alts *LibraryAlternatives) Add(library *libraries.Library) {
6464
if len(alts.Alternatives) > 0 && alts.Alternatives[0].Name != library.Name {
65-
panic(fmt.Sprintf(tr("the library name is different from the set (%[1]s != %[2]s)"), alts.Alternatives[0].Name, library.Name))
65+
panic(fmt.Sprintf("the library name is different from the set (%[1]s != %[2]s)", alts.Alternatives[0].Name, library.Name))
6666
}
6767
alts.Alternatives = append(alts.Alternatives, library)
6868
}

Diff for: arduino/serialutils/serialutils.go

+1-2
Original file line numberDiff line numberDiff line change
@@ -130,8 +130,7 @@ func Reset(portToTouch string, wait bool, cb *ResetProgressCallbacks, dryRun boo
130130
// do nothing!
131131
} else {
132132
if err := TouchSerialPortAt1200bps(portToTouch); err != nil {
133-
fmt.Printf(tr("TOUCH: error during reset: %s"), err)
134-
fmt.Println()
133+
fmt.Println(tr("TOUCH: error during reset: %s", err))
135134
}
136135
}
137136
}

Diff for: arduino/sketch/sketch.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -260,7 +260,7 @@ type InvalidSketchFolderNameError struct {
260260
}
261261

262262
func (e *InvalidSketchFolderNameError) Error() string {
263-
return fmt.Sprintf(tr("no valid sketch found in %[1]s: missing %[2]s"), e.SketchFolder, e.SketchFile)
263+
return tr("no valid sketch found in %[1]s: missing %[2]s", e.SketchFolder, e.SketchFile)
264264
}
265265

266266
// CheckForPdeFiles returns all files ending with .pde extension

Diff for: cli/board/attach.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ func initAttachCommand() *cobra.Command {
4242
Run: runAttachCommand,
4343
}
4444
attachCommand.Flags().StringVar(&attachFlags.searchTimeout, "timeout", "5s",
45-
fmt.Sprintf(tr("The connected devices search timeout, raise it if your board doesn't show up (e.g. to %s)."), "10s"))
45+
tr("The connected devices search timeout, raise it if your board doesn't show up (e.g. to %s).", "10s"))
4646
return attachCommand
4747
}
4848

Diff for: cli/cli.go

+5-5
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ func NewCommand() *cobra.Command {
7575
PersistentPostRun: postRun,
7676
}
7777

78-
arduinoCli.SetUsageTemplate(usageTemplate)
78+
arduinoCli.SetUsageTemplate(getUsageTemplate())
7979

8080
createCliCommandTree(arduinoCli)
8181

@@ -103,10 +103,10 @@ func createCliCommandTree(cmd *cobra.Command) {
103103
cmd.AddCommand(version.NewCommand())
104104

105105
cmd.PersistentFlags().BoolVarP(&verbose, "verbose", "v", false, tr("Print the logs on the standard output."))
106-
cmd.PersistentFlags().String("log-level", "", fmt.Sprintf(tr("Messages with this level and above will be logged. Valid levels are: %s, %s, %s, %s, %s, %s, %s"), "trace", "debug", "info", "warn", "error", "fatal", "panic"))
106+
cmd.PersistentFlags().String("log-level", "", tr("Messages with this level and above will be logged. Valid levels are: %s", "trace, debug, info, warn, error, fatal, panic"))
107107
cmd.PersistentFlags().String("log-file", "", tr("Path to the file where logs will be written."))
108-
cmd.PersistentFlags().String("log-format", "", fmt.Sprintf(tr("The output format for the logs, can be {%s|%s}."), "text", "json"))
109-
cmd.PersistentFlags().StringVar(&outputFormat, "format", "text", fmt.Sprintf(tr("The output format, can be {%s|%s}."), "text", "json"))
108+
cmd.PersistentFlags().String("log-format", "", tr("The output format for the logs, can be: %s", "text, json"))
109+
cmd.PersistentFlags().StringVar(&outputFormat, "format", "text", tr("The output format for the logs, can be: %s", "text, json"))
110110
cmd.PersistentFlags().StringVar(&configFile, "config-file", "", tr("The custom config file (if not specified the default will be used)."))
111111
cmd.PersistentFlags().StringSlice("additional-urls", []string{}, tr("Comma-separated list of additional URLs for the Boards Manager."))
112112
cmd.PersistentFlags().Bool("no-color", false, "Disable colored output.")
@@ -196,7 +196,7 @@ func preRun(cmd *cobra.Command, args []string) {
196196
if logFile != "" {
197197
file, err := os.OpenFile(logFile, os.O_CREATE|os.O_WRONLY|os.O_APPEND, 0666)
198198
if err != nil {
199-
fmt.Printf(tr("Unable to open file for logging: %s"), logFile)
199+
fmt.Println(tr("Unable to open file for logging: %s", logFile))
200200
os.Exit(errorcodes.ErrBadCall)
201201
}
202202

Diff for: cli/compile/compile.go

+2-3
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ import (
1919
"bytes"
2020
"context"
2121
"encoding/json"
22-
"fmt"
2322
"os"
2423

2524
"github.com/arduino/arduino-cli/arduino/discovery"
@@ -94,7 +93,7 @@ func NewCommand() *cobra.Command {
9493
command.Flags().StringArrayVar(&buildProperties, "build-property", []string{},
9594
tr("Override a build property with a custom value. Can be used multiple times for multiple properties."))
9695
command.Flags().StringVar(&warnings, "warnings", "none",
97-
fmt.Sprintf(tr(`Optional, can be "%[1]s", "%[2]s", "%[3]s" and "%[4]s". Defaults to "%[1]s". Used to tell gcc which warning level to use (-W flag).`), "none", "default", "more", "all"))
96+
tr(`Optional, can be: %s. Used to tell gcc which warning level to use (-W flag).`, "none, default, more, all"))
9897
command.Flags().BoolVarP(&verbose, "verbose", "v", false, tr("Optional, turns on verbose mode."))
9998
command.Flags().BoolVar(&quiet, "quiet", false, tr("Optional, suppresses almost every output."))
10099
command.Flags().BoolVarP(&uploadAfterCompile, "upload", "u", false, tr("Upload the binary after the compilation."))
@@ -215,7 +214,7 @@ func run(cmd *cobra.Command, args []string) {
215214

216215
fields := map[string]string{}
217216
if len(userFieldRes.UserFields) > 0 {
218-
feedback.Printf(tr("Uploading to specified board using %s protocol requires the following info:"), discoveryPort.Protocol)
217+
feedback.Print(tr("Uploading to specified board using %s protocol requires the following info:", discoveryPort.Protocol))
219218
fields = arguments.AskForUserFields(userFieldRes.UserFields)
220219
}
221220

Diff for: cli/config/init.go

+1-2
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
package config
1717

1818
import (
19-
"fmt"
2019
"os"
2120

2221
"github.com/arduino/arduino-cli/cli/errorcodes"
@@ -107,7 +106,7 @@ func runInitCommand(cmd *cobra.Command, args []string) {
107106
os.Exit(errorcodes.ErrGeneric)
108107
}
109108

110-
msg := fmt.Sprintf(tr("Config file written to: %s"), configFileAbsPath.String())
109+
msg := tr("Config file written to: %s", configFileAbsPath.String())
111110
logrus.Info(msg)
112111
feedback.Print(msg)
113112
}

Diff for: cli/core/download.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -33,12 +33,12 @@ import (
3333

3434
func initDownloadCommand() *cobra.Command {
3535
downloadCommand := &cobra.Command{
36-
Use: fmt.Sprintf(tr("download [%s:%s[@%s]]..."), tr("PACKAGER"), tr("ARCH"), tr("VERSION")),
36+
Use: fmt.Sprintf("download [%s:%s[@%s]]...", tr("PACKAGER"), tr("ARCH"), tr("VERSION")),
3737
Short: tr("Downloads one or more cores and corresponding tool dependencies."),
3838
Long: tr("Downloads one or more cores and corresponding tool dependencies."),
3939
Example: "" +
40-
" " + os.Args[0] + " core download arduino:samd # " + tr("to download the latest version of Arduino SAMD core.\n") +
41-
" " + os.Args[0] + " core download arduino:[email protected] # " + tr("for a specific version (in this case 1.6.9)."),
40+
" " + os.Args[0] + " core download arduino:samd # " + tr("download the latest version of Arduino SAMD core.") + "\n" +
41+
" " + os.Args[0] + " core download arduino:[email protected] # " + tr("download a specific version (in this case 1.6.9)."),
4242
Args: cobra.MinimumNArgs(1),
4343
Run: runDownloadCommand,
4444
}

Diff for: cli/core/list.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ func (ir installedResult) String() string {
8585
for _, p := range ir.platforms {
8686
name := p.Name
8787
if p.Deprecated {
88-
name = fmt.Sprintf(tr("[DEPRECATED] %s"), name)
88+
name = fmt.Sprintf("[%s] %s", tr("DEPRECATED"), name)
8989
}
9090
t.AddRow(p.Id, p.Installed, p.Latest, name)
9191
}

Diff for: cli/core/search.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ func (sr searchResults) String() string {
115115
for _, item := range sr.platforms {
116116
name := item.GetName()
117117
if item.Deprecated {
118-
name = fmt.Sprintf(tr("[DEPRECATED] %s"), name)
118+
name = fmt.Sprintf("[%s] %s", tr("DEPRECATED"), name)
119119
}
120120
t.AddRow(item.GetId(), item.GetLatest(), name)
121121
}

Diff for: cli/daemon/daemon.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ var tr = i18n.Tr
4747
func NewCommand() *cobra.Command {
4848
cmd := &cobra.Command{
4949
Use: "daemon",
50-
Short: fmt.Sprintf(tr("Run as a daemon on port %s"), configuration.Settings.GetString("daemon.port")),
50+
Short: tr("Run as a daemon on port: %s", configuration.Settings.GetString("daemon.port")),
5151
Long: tr("Running as a daemon the initialization of cores and libraries is done only once."),
5252
Example: " " + os.Args[0] + " daemon",
5353
Args: cobra.NoArgs,

Diff for: cli/debug/debug.go

+2-3
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ package debug
1717

1818
import (
1919
"context"
20-
"fmt"
2120
"os"
2221
"os/signal"
2322
"sort"
@@ -62,7 +61,7 @@ func NewCommand() *cobra.Command {
6261
debugCommand.Flags().StringVarP(&fqbn, "fqbn", "b", "", tr("Fully Qualified Board Name, e.g.: arduino:avr:uno"))
6362
port.AddToCommand(debugCommand)
6463
debugCommand.Flags().StringVarP(&programmer, "programmer", "P", "", tr("Programmer to use for debugging"))
65-
debugCommand.Flags().StringVar(&interpreter, "interpreter", "console", fmt.Sprintf(tr("Debug interpreter e.g.: %s, %s, %s, %s, %s"), "console", "mi", "mi1", "mi2", "mi3"))
64+
debugCommand.Flags().StringVar(&interpreter, "interpreter", "console", tr("Debug interpreter e.g.: %s", "console, mi, mi1, mi2, mi3"))
6665
debugCommand.Flags().StringVarP(&importDir, "input-dir", "", "", tr("Directory containing binaries for debug."))
6766
debugCommand.Flags().BoolVarP(&printInfo, "info", "I", false, tr("Show metadata about the debug session instead of starting the debugger."))
6867

@@ -151,7 +150,7 @@ func (r *debugInfoResult) String() string {
151150
conf := properties.NewFromHashmap(r.info.GetServerConfiguration())
152151
keys := conf.Keys()
153152
sort.Strings(keys)
154-
t.AddRow(fmt.Sprintf(tr("%s custom configurations"), r.info.GetServer()))
153+
t.AddRow(tr("Configuration options for %s", r.info.GetServer()))
155154
for _, k := range keys {
156155
t.AddRow(table.NewCell(" - "+k, dimGreen), table.NewCell(conf.Get(k), dimGreen))
157156
}

Diff for: cli/lib/check_deps.go

+4-3
Original file line numberDiff line numberDiff line change
@@ -87,15 +87,16 @@ func outputDep(dep *rpc.LibraryDependencyStatus) string {
8787
red := color.New(color.FgRed)
8888
yellow := color.New(color.FgYellow)
8989
if dep.GetVersionInstalled() == "" {
90-
res += fmt.Sprintf(tr("%s must be installed.")+"\n",
90+
res += tr("%s must be installed.",
9191
red.Sprintf("✕ %s %s", dep.GetName(), dep.GetVersionRequired()))
9292
} else if dep.GetVersionInstalled() == dep.GetVersionRequired() {
93-
res += fmt.Sprintf(tr("%s is already installed.")+"\n",
93+
res += tr("%s is already installed.",
9494
green.Sprintf("✓ %s %s", dep.GetName(), dep.GetVersionRequired()))
9595
} else {
96-
res += fmt.Sprintf(tr("%s is required but %s is currently installed.")+"\n",
96+
res += tr("%[1]s is required but %[2]s is currently installed.",
9797
yellow.Sprintf("✕ %s %s", dep.GetName(), dep.GetVersionRequired()),
9898
yellow.Sprintf("%s", dep.GetVersionInstalled()))
9999
}
100+
res += "\n"
100101
return res
101102
}

Diff for: cli/lib/examples.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ func (ir libraryExamplesResult) String() string {
115115
} else if lib.Library.Location != rpc.LibraryLocation_LIBRARY_LOCATION_USER {
116116
name += " (" + lib.Library.GetLocation().String() + ")"
117117
}
118-
r := fmt.Sprintf(tr("Examples for library %s")+"\n", color.GreenString("%s", name))
118+
r := tr("Examples for library %s", color.GreenString("%s", name)) + "\n"
119119
sort.Slice(lib.Examples, func(i, j int) bool {
120120
return strings.ToLower(lib.Examples[i]) < strings.ToLower(lib.Examples[j])
121121
})

Diff for: cli/lib/search.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ func (res result) String() string {
139139

140140
for _, lib := range results {
141141
if res.results.GetStatus() == rpc.LibrarySearchStatus_LIBRARY_SEARCH_STATUS_SUCCESS {
142-
out.WriteString(fmt.Sprintf(tr(`Name: "%s"`)+"\n", lib.Name))
142+
out.WriteString(tr(`Name: "%s"`, lib.Name) + "\n")
143143
if res.namesOnly {
144144
continue
145145
}

Diff for: cli/output/rpc_progress.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ func NewDownloadProgressBarCB() func(*rpc.DownloadProgress) {
6161
// fmt.Printf(">>> %v\n", curr)
6262
if filename := curr.GetFile(); filename != "" {
6363
if curr.GetCompleted() {
64-
fmt.Printf(tr("%s already downloaded")+"\n", filename)
64+
fmt.Println(tr("%s already downloaded", filename))
6565
return
6666
}
6767
prefix = filename
@@ -73,7 +73,7 @@ func NewDownloadProgressBarCB() func(*rpc.DownloadProgress) {
7373
bar.Set(int(curr.GetDownloaded()))
7474
}
7575
if curr.GetCompleted() {
76-
bar.FinishPrintOver(fmt.Sprintf(tr("%s downloaded"), prefix))
76+
bar.FinishPrintOver(tr("%s downloaded", prefix))
7777
}
7878
}
7979
}

Diff for: cli/sketch/archive.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ func initArchiveCommand() *cobra.Command {
4848
Run: runArchiveCommand,
4949
}
5050

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

5353
return command
5454
}

Diff for: cli/sketch/new.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -65,5 +65,5 @@ func runNewCommand(cmd *cobra.Command, args []string) {
6565
os.Exit(errorcodes.ErrGeneric)
6666
}
6767

68-
feedback.Printf(tr("Sketch created in: %s"), sketchDir)
68+
feedback.Print(tr("Sketch created in: %s", sketchDir))
6969
}

Diff for: cli/upload/upload.go

+2-3
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ package upload
1717

1818
import (
1919
"context"
20-
"fmt"
2120
"os"
2221

2322
"github.com/arduino/arduino-cli/arduino/sketch"
@@ -69,7 +68,7 @@ func NewCommand() *cobra.Command {
6968

7069
func checkFlagsConflicts(command *cobra.Command, args []string) {
7170
if importFile != "" && importDir != "" {
72-
feedback.Errorf(fmt.Sprintf(tr("error: %s and %s flags cannot be used together"), "--input-file", "--input-dir"))
71+
feedback.Errorf(tr("error: %s and %s flags cannot be used together", "--input-file", "--input-dir"))
7372
os.Exit(errorcodes.ErrBadArgument)
7473
}
7574
}
@@ -121,7 +120,7 @@ func run(command *cobra.Command, args []string) {
121120

122121
fields := map[string]string{}
123122
if len(userFieldRes.UserFields) > 0 {
124-
feedback.Printf(tr("Uploading to specified board using %s protocol requires the following info:"), discoveryPort.Protocol)
123+
feedback.Print(tr("Uploading to specified board using %s protocol requires the following info:", discoveryPort.Protocol))
125124
fields = arguments.AskForUserFields(userFieldRes.UserFields)
126125
}
127126

Diff for: cli/usage.go

+15-14
Original file line numberDiff line numberDiff line change
@@ -19,20 +19,20 @@ import (
1919
"github.com/arduino/arduino-cli/i18n"
2020
)
2121

22-
// Declare ids used in usage
23-
var (
24-
tr = i18n.Tr
25-
_ = tr("Usage:")
26-
_ = tr("Aliases:")
27-
_ = tr("Examples:")
28-
_ = tr("Available Commands:")
29-
_ = tr("Flags:")
30-
_ = tr("Global Flags:")
31-
_ = tr("Additional help topics:")
32-
_ = tr("Use %s for more information about a command.")
33-
)
34-
35-
const usageTemplate = `{{tr "Usage:"}}{{if .Runnable}}
22+
var tr = i18n.Tr
23+
24+
func getUsageTemplate() string {
25+
// Force i18n to generate translation strings
26+
_ = tr("Usage:")
27+
_ = tr("Aliases:")
28+
_ = tr("Examples:")
29+
_ = tr("Available Commands:")
30+
_ = tr("Flags:")
31+
_ = tr("Global Flags:")
32+
_ = tr("Additional help topics:")
33+
_ = tr("Use %s for more information about a command.")
34+
35+
return `{{tr "Usage:"}}{{if .Runnable}}
3636
{{.UseLine}}{{end}}{{if .HasAvailableSubCommands}}
3737
{{.CommandPath}} [command]{{end}}{{if gt (len .Aliases) 0}}
3838
@@ -56,3 +56,4 @@ const usageTemplate = `{{tr "Usage:"}}{{if .Runnable}}
5656
5757
{{tr "Use %s for more information about a command." (printf "%s %s" .CommandPath "[command] --help" | printf "%q")}}{{end}}
5858
`
59+
}

0 commit comments

Comments
 (0)