Skip to content

Commit c644a53

Browse files
committed
Code refactoring
1 parent 0fa18ba commit c644a53

1 file changed

Lines changed: 18 additions & 34 deletions

File tree

cli/cli.go

Lines changed: 18 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -140,12 +140,7 @@ func Run(gitRev string, gomod []byte) {
140140
args, errs := options.Parse(optMap)
141141

142142
if len(errs) != 0 {
143-
printError("Arguments parsing errors:")
144-
145-
for _, err := range errs {
146-
printError(" %v", err)
147-
}
148-
143+
printError(errs[0].Error())
149144
os.Exit(1)
150145
}
151146

@@ -154,17 +149,18 @@ func Run(gitRev string, gomod []byte) {
154149

155150
switch {
156151
case options.Has(OPT_COMPLETION):
157-
os.Exit(genCompletion())
152+
os.Exit(printCompletion())
158153
case options.Has(OPT_GENERATE_MAN):
159-
os.Exit(genMan())
154+
printMan()
155+
os.Exit(0)
160156
case options.GetB(OPT_VER):
161-
showAbout(gitRev)
157+
genAbout(gitRev).Print()
162158
os.Exit(0)
163159
case options.GetB(OPT_VERB_VER):
164160
support.Print(APP, VER, gitRev, gomod)
165161
os.Exit(0)
166162
case options.GetB(OPT_HELP) || len(args) == 0:
167-
showUsage()
163+
genUsage().Print()
168164
os.Exit(0)
169165
}
170166

@@ -622,30 +618,8 @@ func printError(f string, a ...interface{}) {
622618

623619
// ////////////////////////////////////////////////////////////////////////////////// //
624620

625-
// showUsage prints usage info
626-
func showUsage() {
627-
genUsage().Print()
628-
}
629-
630-
// showAbout prints info about version
631-
func showAbout(gitRev string) {
632-
genAbout(gitRev).Print()
633-
}
634-
635-
// genMan generates man page
636-
func genMan() int {
637-
fmt.Println(
638-
man.Generate(
639-
genUsage(),
640-
genAbout(""),
641-
),
642-
)
643-
644-
return 0
645-
}
646-
647-
// genCompletion generates completion for different shells
648-
func genCompletion() int {
621+
// printCompletion prints completion for given shell
622+
func printCompletion() int {
649623
info := genUsage()
650624

651625
switch options.GetS(OPT_COMPLETION) {
@@ -662,6 +636,16 @@ func genCompletion() int {
662636
return 0
663637
}
664638

639+
// printMan prints man page
640+
func printMan() {
641+
fmt.Println(
642+
man.Generate(
643+
genUsage(),
644+
genAbout(""),
645+
),
646+
)
647+
}
648+
665649
// genUsage generates usage info
666650
func genUsage() *usage.Info {
667651
info := usage.NewInfo("", "host…")

0 commit comments

Comments
 (0)