Add parameters
This commit is contained in:
parent
4c1216d293
commit
4665a1caa7
27
cmd/root.go
27
cmd/root.go
|
@ -5,9 +5,11 @@ package cmd
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"log"
|
||||||
|
"os"
|
||||||
|
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
"github.com/spf13/viper"
|
"github.com/spf13/viper"
|
||||||
"os"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
var cfgFile string
|
var cfgFile string
|
||||||
|
@ -20,6 +22,9 @@ var rootCmd = &cobra.Command{
|
||||||
// Uncomment the following line if your bare application
|
// Uncomment the following line if your bare application
|
||||||
// has an action associated with it:
|
// has an action associated with it:
|
||||||
Run: func(cmd *cobra.Command, args []string) {
|
Run: func(cmd *cobra.Command, args []string) {
|
||||||
|
if err := setClientParameters(cmd); err != nil {
|
||||||
|
log.Fatalf("Error occurred setting parameters: %v\n", err)
|
||||||
|
}
|
||||||
tune()
|
tune()
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
@ -45,6 +50,8 @@ func init() {
|
||||||
// Cobra also supports local flags, which will only run
|
// Cobra also supports local flags, which will only run
|
||||||
// when this action is called directly.
|
// when this action is called directly.
|
||||||
rootCmd.Flags().BoolP("toggle", "t", false, "Help message for toggle")
|
rootCmd.Flags().BoolP("toggle", "t", false, "Help message for toggle")
|
||||||
|
rootCmd.PersistentFlags().StringP("file", "f", "", "File to play")
|
||||||
|
rootCmd.PersistentFlags().StringP("directory", "d", "", "Directory to look for files to play")
|
||||||
}
|
}
|
||||||
|
|
||||||
// initConfig reads in config file and ENV variables if set.
|
// initConfig reads in config file and ENV variables if set.
|
||||||
|
@ -70,3 +77,21 @@ func initConfig() {
|
||||||
fmt.Fprintln(os.Stderr, "Using config file:", viper.ConfigFileUsed())
|
fmt.Fprintln(os.Stderr, "Using config file:", viper.ConfigFileUsed())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func setClientParameters(cmd *cobra.Command) error {
|
||||||
|
parameterFile, err := cmd.Flags().GetString("file")
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
if parameterFile != "" {
|
||||||
|
playIndividualFile = true
|
||||||
|
filePath = parameterFile
|
||||||
|
}
|
||||||
|
parameterDir, err := cmd.Flags().GetString("directory")
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
if parameterDir != "" {
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue