43 lines
1.4 KiB
Go
43 lines
1.4 KiB
Go
package cmd
|
|
|
|
import (
|
|
"fmt"
|
|
"kontor-api-gin/internal/config"
|
|
"log/slog"
|
|
"os"
|
|
|
|
"github.com/spf13/cobra"
|
|
"github.com/spf13/viper"
|
|
)
|
|
|
|
// rootCmd represents the base command when called without any subcommands
|
|
var rootCmd = &cobra.Command{
|
|
Use: "kontor-cli",
|
|
TraverseChildren: true,
|
|
Short: "A brief description of your application",
|
|
Long: ``,
|
|
// Uncomment the following line if your bare application
|
|
// has an action associated with it:
|
|
Run: func(cmd *cobra.Command, args []string) {
|
|
cmd.Help()
|
|
slog.Info("Verbosity level", "level", config.Verbose)
|
|
},
|
|
}
|
|
|
|
func Execute() {
|
|
if err := rootCmd.Execute(); err != nil {
|
|
fmt.Fprintf(os.Stderr, "Oops. An error while executing Zero '%s'\n", err)
|
|
os.Exit(1)
|
|
}
|
|
}
|
|
|
|
func init() {
|
|
rootCmd.PersistentFlags().StringVarP(&config.CfgFile, "config", "c", "/home/tpeetz/.config/kli.yaml", "config file")
|
|
rootCmd.PersistentFlags().CountVarP(&config.Verbose, "verbose", "v", "increase verbosity (-v, -vv, -vvv)")
|
|
viper.BindPFlag("config", rootCmd.PersistentFlags().Lookup("config"))
|
|
exportCmd.Flags().StringVarP(&config.ServerName, "servername", "s", "local", "Define server to get Kontor items")
|
|
updateTitleCmd.Flags().StringVarP(&config.ServerName, "servername", "s", "local", "Define server to get Kontor items")
|
|
viper.BindPFlag("server", exportCmd.PersistentFlags().Lookup("server"))
|
|
cobra.OnInitialize(config.InitCliConfig)
|
|
}
|