🎨 Added commands
Added commands and error handling.
This commit is contained in:
parent
b04c374124
commit
f02e9035a1
@ -1,12 +1,13 @@
|
|||||||
package commands
|
package commands
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
|
|
||||||
"github.com/fatih/color"
|
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
|
|
||||||
"git.tcp.direct/perp/shogo/cmd/shogo/commands/alert"
|
"git.tcp.direct/perp/shogo/cmd/shogo/commands/alert"
|
||||||
|
"git.tcp.direct/perp/shogo/cmd/shogo/commands/scan"
|
||||||
"git.tcp.direct/perp/shogo/internal/utils"
|
"git.tcp.direct/perp/shogo/internal/utils"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -17,7 +18,7 @@ var rootCmd = &cobra.Command{
|
|||||||
Run: func(cmd *cobra.Command, _ []string) {
|
Run: func(cmd *cobra.Command, _ []string) {
|
||||||
utils.CheckColor()
|
utils.CheckColor()
|
||||||
if err := cmd.Help(); err != nil {
|
if err := cmd.Help(); err != nil {
|
||||||
color.Red("Error: %s", err.Error())
|
fmt.Printf("%s: %s\n", utils.Red("Error"), err.Error())
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
@ -37,16 +38,20 @@ func init() {
|
|||||||
rootCmd.AddCommand(infoCmd)
|
rootCmd.AddCommand(infoCmd)
|
||||||
rootCmd.AddCommand(myIPCmd)
|
rootCmd.AddCommand(myIPCmd)
|
||||||
rootCmd.AddCommand(searchCmd)
|
rootCmd.AddCommand(searchCmd)
|
||||||
|
rootCmd.AddCommand(statsCmd)
|
||||||
rootCmd.AddCommand(versionCmd)
|
rootCmd.AddCommand(versionCmd)
|
||||||
|
|
||||||
// Add subcommands
|
// Add subcommands
|
||||||
rootCmd.AddCommand(alert.AlertCmd)
|
rootCmd.AddCommand(alert.AlertCmd)
|
||||||
|
rootCmd.AddCommand(scan.ScanCmd)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Execute command
|
// Execute command
|
||||||
func Execute() {
|
func Execute() {
|
||||||
if err := rootCmd.Execute(); err != nil {
|
if err := rootCmd.Execute(); err != nil {
|
||||||
color.Red("Error: %s", err.Error())
|
fmt.Printf("%s: %s\n", utils.Red("Error"), err.Error())
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Todo: Make mutliple arguments threaded
|
||||||
|
Loading…
Reference in New Issue
Block a user