🎨 Added commands

Added commands and error handling.
This commit is contained in:
perp 2023-08-02 05:06:24 +01:00
parent b04c374124
commit f02e9035a1

View File

@ -1,12 +1,13 @@
package commands
import (
"fmt"
"os"
"github.com/fatih/color"
"github.com/spf13/cobra"
"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"
)
@ -17,7 +18,7 @@ var rootCmd = &cobra.Command{
Run: func(cmd *cobra.Command, _ []string) {
utils.CheckColor()
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)
}
},
@ -37,16 +38,20 @@ func init() {
rootCmd.AddCommand(infoCmd)
rootCmd.AddCommand(myIPCmd)
rootCmd.AddCommand(searchCmd)
rootCmd.AddCommand(statsCmd)
rootCmd.AddCommand(versionCmd)
// Add subcommands
rootCmd.AddCommand(alert.AlertCmd)
rootCmd.AddCommand(scan.ScanCmd)
}
// Execute command
func Execute() {
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)
}
}
// Todo: Make mutliple arguments threaded