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