Skip to content

Commit 19ebbbc

Browse files
committed
fix windows coloredcobra bug
1 parent 4d13284 commit 19ebbbc

3 files changed

Lines changed: 18 additions & 12 deletions

File tree

.idea/.name

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

cmd/rootCmd.go

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,16 @@ package cmd
22

33
import (
44
"errors"
5+
"os"
6+
"runtime"
7+
58
cc "github.com/ivanpirog/coloredcobra"
69
"github.com/shadowabi/Serverless_PortScan_rebuild/config"
710
"github.com/shadowabi/Serverless_PortScan_rebuild/define"
811
"github.com/shadowabi/Serverless_PortScan_rebuild/pkg"
912
"github.com/shadowabi/Serverless_PortScan_rebuild/utils/Error"
1013
"github.com/shadowabi/Serverless_PortScan_rebuild/utils/log"
1114
"github.com/spf13/cobra"
12-
"os"
1315
)
1416

1517
var RootCmd = &cobra.Command{
@@ -29,6 +31,8 @@ Serverless_PortScan is used to scan ports using cloud functions.
2931
`,
3032
PersistentPostRun: func(cmd *cobra.Command, args []string) {
3133
log.Init(logLevel)
34+
},
35+
Run: func(cmd *cobra.Command, args []string) {
3236
if define.Url != "" && define.File != "" {
3337
Error.HandleFatal(errors.New("参数不可以同时存在"))
3438
return
@@ -37,9 +41,6 @@ Serverless_PortScan is used to scan ports using cloud functions.
3741
Error.HandleFatal(errors.New("必选参数为空,请输入 -u 参数或 -f 参数"))
3842
return
3943
}
40-
},
41-
Run: func(cmd *cobra.Command, args []string) {
42-
cmd.Println(cmd.Long) // print title
4344

4445
if define.Port == "" {
4546
define.Port = config.C.PortList
@@ -76,14 +77,16 @@ func init() {
7677
}
7778

7879
func Execute() {
79-
cc.Init(&cc.Config{
80-
RootCmd: RootCmd,
81-
Headings: cc.HiGreen + cc.Underline,
82-
Commands: cc.Cyan + cc.Bold,
83-
Example: cc.Italic,
84-
ExecName: cc.Bold,
85-
Flags: cc.Cyan + cc.Bold,
86-
})
80+
if runtime.GOOS != "windows" {
81+
cc.Init(&cc.Config{
82+
RootCmd: RootCmd,
83+
Headings: cc.HiGreen + cc.Underline,
84+
Commands: cc.Cyan + cc.Bold,
85+
Example: cc.Italic,
86+
ExecName: cc.Bold,
87+
Flags: cc.Cyan + cc.Bold,
88+
})
89+
}
8790
err := RootCmd.Execute()
8891
if err != nil {
8992
os.Exit(1)

main/main.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package main
22

33
import (
44
"fmt"
5+
56
"github.com/shadowabi/Serverless_PortScan_rebuild/cmd"
67
"github.com/shadowabi/Serverless_PortScan_rebuild/config"
78
"github.com/shadowabi/Serverless_PortScan_rebuild/pkg"
@@ -18,5 +19,6 @@ func main() {
1819
return
1920
}
2021

22+
fmt.Println(cmd.RootCmd.Long)
2123
cmd.Execute()
2224
}

0 commit comments

Comments
 (0)