Allow selecting clients.json file by parameter
This commit is contained in:
parent
11a186a98e
commit
b42f31d4be
|
@ -6,33 +6,37 @@ package cmd
|
|||
|
||||
import (
|
||||
"github.com/spf13/cobra"
|
||||
"log"
|
||||
)
|
||||
|
||||
// serverCmd represents the server command
|
||||
var serverCmd = &cobra.Command{
|
||||
Use: "server",
|
||||
Short: "A brief description of your command",
|
||||
Long: `A longer description that spans multiple lines and likely contains examples
|
||||
and usage of using your command. For example:
|
||||
|
||||
Cobra is a CLI library for Go that empowers applications.
|
||||
This application is a tool to generate the needed files
|
||||
to quickly create a Cobra application.`,
|
||||
Short: "Tiamat Server",
|
||||
Long: `Tiamat Server including the C2 server and the Web server`,
|
||||
Run: func(cmd *cobra.Command, args []string) {
|
||||
|
||||
if err := setServerParameters(cmd); err != nil {
|
||||
log.Fatalf("Error happened trying to set parameters: %v\n", err)
|
||||
}
|
||||
|
||||
Server()
|
||||
},
|
||||
}
|
||||
|
||||
func init() {
|
||||
rootCmd.AddCommand(serverCmd)
|
||||
|
||||
// Here you will define your flags and configuration settings.
|
||||
|
||||
// Cobra supports Persistent Flags which will work for this command
|
||||
// and all subcommands, e.g.:
|
||||
// serverCmd.PersistentFlags().String("foo", "", "A help for foo")
|
||||
|
||||
// Cobra supports local flags which will only run when this command
|
||||
// is called directly, e.g.:
|
||||
// serverCmd.Flags().BoolP("toggle", "t", false, "Help message for toggle")
|
||||
serverCmd.PersistentFlags().StringP("clients", "c", "", "File to recover clients from")
|
||||
}
|
||||
|
||||
func setServerParameters(cmd *cobra.Command) error {
|
||||
parameterClients, err := cmd.Flags().GetString("clients")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if parameterClients != "" {
|
||||
isUsingJSONParameter = true
|
||||
clientJSONPath = parameterClients
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue