Skip to content

Commit 8528d7d

Browse files
committed
super versioning finished, @cmaglie check for complexity. version command has time complexity O(N^2) is requested verbose info. @mastrolinux
1 parent e6c7f42 commit 8528d7d

File tree

1 file changed

+12
-9
lines changed

1 file changed

+12
-9
lines changed

cmd/arduino.go

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -162,9 +162,14 @@ func initConfig() {
162162
}
163163

164164
func executeVersionCommand(cmd *cobra.Command, args []string) {
165-
versionsToPrint := make([]string, 0, 10)
166-
descendants := make([]*cobra.Command, 0, 10)
167-
versionsToPrint = append(versionsToPrint, cmd.Parent().Name())
165+
versionPrint(versionsToPrint(cmd, true)...)
166+
}
167+
168+
func versionsToPrint(cmd *cobra.Command, isRoot bool) []string {
169+
verToPrint := make([]string, 0, 10)
170+
if isRoot {
171+
verToPrint = append(verToPrint, cmd.Parent().Name())
172+
}
168173

169174
if GlobalFlags.Verbose > 0 {
170175
siblings := findSiblings(cmd)
@@ -173,17 +178,15 @@ func executeVersionCommand(cmd *cobra.Command, args []string) {
173178
for _, sibChild := range sibling.Commands() {
174179
//fmt.Println(sibling.Name(), " >", sibChild.Name())
175180
if sibChild.Name() == "version" {
176-
versionsToPrint = append(versionsToPrint, sibling.Name())
181+
verToPrint = append(verToPrint, sibling.Name())
182+
} else {
183+
verToPrint = append(verToPrint, versionsToPrint(sibChild, false)...)
177184
}
178185
}
179186
}
180187
}
181188

182-
versionPrint(versionsToPrint...)
183-
184-
for _, descendant := range descendants {
185-
executeVersionCommand(descendant, args)
186-
}
189+
return verToPrint
187190
}
188191

189192
// versionPrint formats and prints the version of the specified command.

0 commit comments

Comments
 (0)