Skip to content

Commit 571fbad

Browse files
committed
removing Verbose flag and adding --names flag to lib command
1 parent b06db4b commit 571fbad

File tree

14 files changed

+93
-172
lines changed

14 files changed

+93
-172
lines changed

cmd/arduino.go

Lines changed: 4 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -167,14 +167,16 @@ func InitFlags() {
167167
arduinoSketchSyncCmd.ResetFlags()
168168
arduinoLoginCmd.ResetFlags()
169169

170-
ArduinoCmd.PersistentFlags().CountVarP(&GlobalFlags.Verbose, "verbose", "v", "enables verbose output (use more times for a higher level)")
170+
ArduinoCmd.PersistentFlags().BoolVar(&GlobalFlags.Debug, "debug", false, "enables debug output")
171171
ArduinoCmd.PersistentFlags().StringVar(&GlobalFlags.Format, "format", "invalid", "the output format, can be [text|json]")
172172

173173
ArduinoCmd.PersistentFlags().StringVar(&configs.FileLocation, "config-file", configs.FileLocation, "the custom config file (if not specified ./.cli-config.yml will be used)")
174174

175175
ArduinoCmd.Flags().BoolVar(&rootCmdFlags.GenerateDocs, "generate-docs", false, "generates the docs for the CLI and puts it in docs folder")
176176

177-
arduinoLibCmd.Flags().Bool("update-index", false, "Updates the libraries index")
177+
arduinoLibCmd.Flags().BoolVar(&arduinoLibFlags.updateIndex, "update-index", false, "Updates the libraries index")
178+
179+
arduinoLibSearchCmd.Flags().BoolVar(&arduinoLibSearchFlags.Names, "names", false, "Show library names only")
178180

179181
arduinoCoreCmd.Flags().BoolVar(&arduinoCoreFlags.updateIndex, "update-index", false, "Updates the index of cores to the latest version")
180182

@@ -294,21 +296,6 @@ func versionsToPrint(cmd *cobra.Command, isRoot bool) []string {
294296
verToPrint = append(verToPrint, cmd.Parent().Name())
295297
}
296298

297-
if GlobalFlags.Verbose > 0 {
298-
siblings := findSiblings(cmd)
299-
//search version command in siblings children.
300-
for _, sibling := range siblings {
301-
for _, sibChild := range sibling.Commands() {
302-
//fmt.Println(sibling.Name(), " >", sibChild.Name())
303-
if sibChild.Name() == "version" {
304-
verToPrint = append(verToPrint, sibling.Name())
305-
} else {
306-
verToPrint = append(verToPrint, versionsToPrint(sibChild, false)...)
307-
}
308-
}
309-
}
310-
}
311-
312299
return verToPrint
313300
}
314301

cmd/arduino_core.go

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ func init() {
9999

100100
func executeCoreCommand(cmd *cobra.Command, args []string) {
101101
if arduinoCoreFlags.updateIndex {
102-
common.ExecUpdateIndex(prettyPrints.DownloadCoreFileIndex(), GlobalFlags.Verbose)
102+
common.ExecUpdateIndex(prettyPrints.DownloadCoreFileIndex())
103103
} else {
104104
cmd.Help()
105105
os.Exit(errBadCall)
@@ -154,7 +154,7 @@ func executeCoreDownloadCommand(cmd *cobra.Command, args []string) {
154154
os.Exit(errBadCall)
155155
}
156156

157-
status, err := getPackagesStatusContext(GlobalFlags.Verbose)
157+
status, err := getPackagesStatusContext()
158158
if err != nil {
159159
os.Exit(errGeneric)
160160
}
@@ -171,12 +171,12 @@ func executeCoreDownloadCommand(cmd *cobra.Command, args []string) {
171171
downloads[i] = toolsToDownload[i].DownloadItem
172172
}
173173

174-
releases.ParallelDownload(downloads, true, "Downloaded", GlobalFlags.Verbose, &outputResults.Tools, "tool")
174+
releases.ParallelDownload(downloads, true, "Downloaded", &outputResults.Tools, "tool")
175175
downloads = make([]releases.DownloadItem, len(coresToDownload))
176176
for i := range coresToDownload {
177177
downloads[i] = coresToDownload[i].DownloadItem
178178
}
179-
releases.ParallelDownload(downloads, true, "Downloaded", GlobalFlags.Verbose, &outputResults.Cores, "core")
179+
releases.ParallelDownload(downloads, true, "Downloaded", &outputResults.Cores, "core")
180180

181181
formatter.Print(outputResults)
182182
}
@@ -187,7 +187,7 @@ func executeCoreInstallCommand(cmd *cobra.Command, args []string) {
187187
os.Exit(errBadCall)
188188
}
189189

190-
status, err := getPackagesStatusContext(GlobalFlags.Verbose)
190+
status, err := getPackagesStatusContext()
191191
if err != nil {
192192
formatter.PrintError(err)
193193
os.Exit(errCoreConfig)
@@ -204,13 +204,13 @@ func executeCoreInstallCommand(cmd *cobra.Command, args []string) {
204204
for i := range toolsToDownload {
205205
downloads[i] = toolsToDownload[i].DownloadItem
206206
}
207-
releases.ParallelDownload(downloads, false, "Installed", GlobalFlags.Verbose, &outputResults.Tools, "tool")
207+
releases.ParallelDownload(downloads, false, "Installed", &outputResults.Tools, "tool")
208208

209209
downloads = make([]releases.DownloadItem, len(coresToDownload))
210210
for i := range coresToDownload {
211211
downloads[i] = coresToDownload[i].DownloadItem
212212
}
213-
releases.ParallelDownload(downloads, false, "Installed", GlobalFlags.Verbose, &outputResults.Cores, "core")
213+
releases.ParallelDownload(downloads, false, "Installed", &outputResults.Cores, "core")
214214

215215
for i, item := range toolsToDownload {
216216
err = cores.InstallTool(item.Package, item.Name, item.Release)
@@ -296,11 +296,11 @@ func getInstalledStuff(packageName string, stuff *[]output.InstalledStuff, start
296296
}
297297
}
298298

299-
func getPackagesStatusContext(verbosity int) (*cores.StatusContext, error) {
299+
func getPackagesStatusContext() (*cores.StatusContext, error) {
300300
var index cores.Index
301301
err := cores.LoadIndex(&index)
302302
if err != nil {
303-
status, err := prettyPrints.CorruptedCoreIndexFix(index, verbosity)
303+
status, err := prettyPrints.CorruptedCoreIndexFix(index)
304304
if err != nil {
305305
return nil, err
306306
}

cmd/arduino_lib.go

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ func init() {
128128

129129
func executeLibCommand(cmd *cobra.Command, args []string) {
130130
if arduinoLibFlags.updateIndex {
131-
common.ExecUpdateIndex(prettyPrints.DownloadLibFileIndex(), GlobalFlags.Verbose)
131+
common.ExecUpdateIndex(prettyPrints.DownloadLibFileIndex())
132132
} else {
133133
cmd.Help()
134134
os.Exit(errBadCall)
@@ -141,7 +141,7 @@ func executeDownloadCommand(cmd *cobra.Command, args []string) {
141141
os.Exit(errBadCall)
142142
}
143143

144-
status, err := getLibStatusContext(GlobalFlags.Verbose)
144+
status, err := getLibStatusContext()
145145
if err != nil {
146146
os.Exit(errGeneric)
147147
}
@@ -157,7 +157,7 @@ func executeDownloadCommand(cmd *cobra.Command, args []string) {
157157
libs[i] = releases.DownloadItem(libsToDownload[i])
158158
}
159159

160-
releases.ParallelDownload(libs, false, "Downloaded", GlobalFlags.Verbose, &outputResults.Libraries, "library")
160+
releases.ParallelDownload(libs, false, "Downloaded", &outputResults.Libraries, "library")
161161

162162
formatter.Print(outputResults)
163163
}
@@ -168,7 +168,7 @@ func executeInstallCommand(cmd *cobra.Command, args []string) {
168168
os.Exit(errBadCall)
169169
}
170170

171-
status, err := getLibStatusContext(GlobalFlags.Verbose)
171+
status, err := getLibStatusContext()
172172
if err != nil {
173173
os.Exit(errGeneric)
174174
}
@@ -184,7 +184,7 @@ func executeInstallCommand(cmd *cobra.Command, args []string) {
184184
libs[i] = releases.DownloadItem(libsToDownload[i])
185185
}
186186

187-
releases.ParallelDownload(libs, false, "Installed", GlobalFlags.Verbose, &outputResults.Libraries, "library")
187+
releases.ParallelDownload(libs, false, "Installed", &outputResults.Libraries, "library")
188188

189189
folder, err := common.GetDefaultLibFolder()
190190
if err != nil {
@@ -323,7 +323,7 @@ func executeUninstallCommand(cmd *cobra.Command, args []string) {
323323
func executeSearchCommand(cmd *cobra.Command, args []string) {
324324
query := strings.ToLower(strings.Join(args, " "))
325325

326-
status, err := getLibStatusContext(GlobalFlags.Verbose)
326+
status, err := getLibStatusContext()
327327
if err != nil {
328328
os.Exit(errCoreConfig)
329329
}
@@ -340,17 +340,13 @@ func executeSearchCommand(cmd *cobra.Command, args []string) {
340340
for _, name := range names {
341341
if strings.Contains(strings.ToLower(name), query) {
342342
found = true
343-
item := items[name]
344-
if GlobalFlags.Verbose > 0 {
345-
message.Libraries = append(message.Libraries, item)
346-
if GlobalFlags.Verbose < 2 {
347-
item.Releases = nil
348-
}
349-
} else {
343+
if arduinoLibSearchFlags.Names {
350344
if formatter.IsCurrentFormat("text") {
351345
name = fmt.Sprintf("\"%s\"", name)
352346
}
353347
message.Libraries = append(message.Libraries, name)
348+
} else {
349+
message.Libraries = append(message.Libraries, items[name])
354350
}
355351
}
356352
}
@@ -449,11 +445,11 @@ func resultFromFileName(file os.FileInfo, libs *output.LibProcessResults) {
449445
})
450446
}
451447

452-
func getLibStatusContext(verbosity int) (*libraries.StatusContext, error) {
448+
func getLibStatusContext() (*libraries.StatusContext, error) {
453449
var index libraries.Index
454450
err := libraries.LoadIndex(&index)
455451
if err != nil {
456-
status, err := prettyPrints.CorruptedLibIndexFix(index, verbosity)
452+
status, err := prettyPrints.CorruptedLibIndexFix(index)
457453
if err != nil {
458454
return nil, err
459455
}

cmd/arduino_sketch.go

Lines changed: 6 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -135,13 +135,9 @@ func executeSketchSyncCommand(cmd *cobra.Command, args []string) {
135135

136136
username, bearerToken, err := login()
137137
if err != nil {
138-
if GlobalFlags.Verbose == 0 {
139-
formatter.PrintErrorMessage("Cannot login automatically: try arduino login the run again this command")
140-
} else {
141-
stopSpinner()
142-
formatter.PrintError(err)
143-
os.Exit(errNetwork)
144-
}
138+
stopSpinner()
139+
formatter.PrintError(err)
140+
os.Exit(errNetwork)
145141
}
146142

147143
sketchMap := sketches.Find(sketchbook, "libraries") //exclude libraries folder
@@ -266,14 +262,7 @@ func executeSketchSyncCommand(cmd *cobra.Command, args []string) {
266262
}
267263

268264
stopSpinner()
269-
270-
// for text mode, show full info (aka String()) only if verbose > 0.
271-
// for other formats always print full info.
272-
if GlobalFlags.Verbose > 0 || !formatter.IsCurrentFormat("text") {
273-
formatter.Print(result)
274-
} else {
275-
formatter.PrintResult("Sync Completed")
276-
}
265+
formatter.Print(result)
277266
}
278267

279268
func pushSketch(sketch sketches.Sketch, sketchbook string, bearerToken string) error {
@@ -454,10 +443,10 @@ func login() (string, string, error) {
454443
content, err := NetRC.MarshalText()
455444
if err == nil { //serialize new info
456445
err := ioutil.WriteFile(netRCFile, content, 0666)
457-
if err != nil && GlobalFlags.Verbose > 0 {
446+
if err != nil {
458447
formatter.Print(err.Error())
459448
}
460-
} else if GlobalFlags.Verbose > 0 {
449+
} else {
461450
formatter.Print(err.Error())
462451
}
463452
return arduinoMachine.Login, token, nil

cmd/cmd_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ func TestLibSearch(t *testing.T) {
9292
//executeWithArgs(t, "lib", "search", "you") //test not working on drone, but working locally
9393
// arduino lib search youtu --format json
9494
// arduino lib search youtu --format=json
95-
executeWithArgs(t, "lib", "search", "youtu", "--format", "json")
95+
executeWithArgs(t, "lib", "search", "youtu", "--format", "json", "--names")
9696

9797
checkOutput(t, want, tempFile)
9898
}

cmd/flags.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ import "regexp"
3434

3535
// GlobalFlags represents flags available in all the program.
3636
var GlobalFlags struct {
37-
Verbose int // More time verbose flag is written, the more the Verbose count increases. Represents verbosity level.
37+
Debug bool // If true, dump debug output to stderr.
3838
Format string // The Output format (e.g. text, json).
3939
configs.Configs // The Configurations for the CLI.
4040
}
@@ -49,6 +49,10 @@ var arduinoLibFlags struct {
4949
updateIndex bool // if true, updates libraries index.
5050
}
5151

52+
var arduinoLibSearchFlags struct {
53+
Names bool // if true outputs lib names only.
54+
}
55+
5256
// arduinoCoreFlags represents `arduino core` flags.
5357
var arduinoCoreFlags struct {
5458
updateIndex bool // If true, update packages index.

cmd/pretty_print/common.go

Lines changed: 10 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -62,16 +62,9 @@ func actionOnItems(itemPluralName string, actionPastParticiple string, itemOK []
6262
// uses DownloadFunc to download the file.
6363
func DownloadFileIndex(downloadFunc func() error) task.Wrapper {
6464
return task.Wrapper{
65-
BeforeMessage: []string{
66-
"",
67-
"Downloading from download.arduino.cc",
68-
},
69-
AfterMessage: []string{
70-
"Index File downloaded",
71-
},
72-
ErrorMessage: []string{
73-
"Can't download index file, check your network connection.",
74-
},
65+
BeforeMessage: "Downloading from download.arduino.cc",
66+
AfterMessage: "Index File downloaded",
67+
ErrorMessage: "Can't download index file, check your network connection.",
7568
Task: task.Task(func() task.Result {
7669
return task.Result{
7770
Result: nil,
@@ -82,34 +75,27 @@ func DownloadFileIndex(downloadFunc func() error) task.Wrapper {
8275
}
8376

8477
//corruptedIndexFixResults executes a generic index fix procedure, made by a download and parse task.
85-
func corruptedIndexFixResults(downloadTask, parseTask task.Wrapper, verbosity int) []task.Result {
78+
func corruptedIndexFixResults(downloadTask, parseTask task.Wrapper) []task.Result {
8679
subTasks := []task.Wrapper{downloadTask, parseTask}
8780
wrapper := indexFixWrapperSkeleton()
88-
wrapper.Task = task.CreateSequence(subTasks, []bool{false, false}, verbosity).Task()
89-
return wrapper.Execute(verbosity).Result.([]task.Result)
81+
wrapper.Task = task.CreateSequence(subTasks, []bool{false, false}).Task()
82+
return wrapper.Execute().Result.([]task.Result)
9083
}
9184

9285
// indexParseWrapperSkeleton provides an empty skeleton for a task wrapper regarding index (core index, lib index) error fixing tasks,
9386
// which will be assigned later.
9487
func indexFixWrapperSkeleton() task.Wrapper {
9588
return task.Wrapper{
96-
BeforeMessage: []string{
97-
"Cannot parse index file, it may be corrupted.",
98-
},
89+
BeforeMessage: "Cannot parse index file, it may be corrupted.",
9990
}
10091
}
10192

10293
// indexParseWrapperSkeleton provides an empty skeleton for a task wrapper regarding index (core index, lib index) parsing tasks,
10394
// which will be assigned later.
10495
func indexParseWrapperSkeleton() task.Wrapper {
10596
return task.Wrapper{
106-
BeforeMessage: []string{
107-
"",
108-
"Parsing downloaded index file",
109-
},
110-
ErrorMessage: []string{
111-
"Cannot parse index file",
112-
},
113-
Task: nil,
97+
BeforeMessage: "Parsing downloaded index file",
98+
ErrorMessage: "Cannot parse index file",
99+
Task: nil,
114100
}
115101
}

cmd/pretty_print/pretty_print_core.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,17 +40,17 @@ func DownloadCoreFileIndex() task.Wrapper {
4040
}
4141

4242
// CorruptedCoreIndexFix pretty prints messages regarding corrupted index fixes of cores.
43-
func CorruptedCoreIndexFix(index cores.Index, verbosity int) (cores.StatusContext, error) {
43+
func CorruptedCoreIndexFix(index cores.Index) (cores.StatusContext, error) {
4444
downloadTask := DownloadCoreFileIndex()
45-
parseTask := coreIndexParse(index, verbosity)
45+
parseTask := coreIndexParse(index)
4646

47-
result := corruptedIndexFixResults(downloadTask, parseTask, verbosity)
47+
result := corruptedIndexFixResults(downloadTask, parseTask)
4848

4949
return result[1].Result.(cores.StatusContext), result[1].Error
5050
}
5151

5252
// coreIndexParse pretty prints info about parsing an index file of libraries.
53-
func coreIndexParse(index cores.Index, verbosity int) task.Wrapper {
53+
func coreIndexParse(index cores.Index) task.Wrapper {
5454
ret := indexParseWrapperSkeleton()
5555
ret.Task = task.Task(func() task.Result {
5656
err := cores.LoadIndex(&index) // I try again

cmd/pretty_print/pretty_print_lib.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,18 +40,18 @@ func DownloadLibFileIndex() task.Wrapper {
4040
}
4141

4242
// CorruptedLibIndexFix pretty prints messages regarding corrupted index fixes of libraries.
43-
func CorruptedLibIndexFix(index libraries.Index, verbosity int) (libraries.StatusContext, error) {
43+
func CorruptedLibIndexFix(index libraries.Index) (libraries.StatusContext, error) {
4444
downloadTask := DownloadLibFileIndex()
45-
parseTask := libIndexParse(index, verbosity)
45+
parseTask := libIndexParse(index)
4646

47-
result := corruptedIndexFixResults(downloadTask, parseTask, verbosity)
47+
result := corruptedIndexFixResults(downloadTask, parseTask)
4848
ret, _ := result[1].Result.(libraries.StatusContext)
4949
err := result[1].Error
5050
return ret, err
5151
}
5252

5353
// libIndexParse pretty prints info about parsing an index file of libraries.
54-
func libIndexParse(index libraries.Index, verbosity int) task.Wrapper {
54+
func libIndexParse(index libraries.Index) task.Wrapper {
5555
ret := indexParseWrapperSkeleton()
5656
ret.Task = func() task.Result {
5757
err := libraries.LoadIndex(&index)

common/paths.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -140,8 +140,8 @@ func GetDownloadCacheFolder(item string) (string, error) {
140140
}
141141

142142
// ExecUpdateIndex is a generic procedure to update an index file.
143-
func ExecUpdateIndex(updateTask task.Wrapper, verbosity int) {
144-
updateTask.Execute(verbosity)
143+
func ExecUpdateIndex(updateTask task.Wrapper) {
144+
updateTask.Execute()
145145
}
146146

147147
// IndexPath returns the path of the specified index file.

0 commit comments

Comments
 (0)