add basic operational commands

This commit is contained in:
Samuel Lorch 2021-09-08 10:54:20 +02:00
parent 64c878c9d5
commit 219c451098
12 changed files with 898 additions and 0 deletions

38
cmd/configure.go Normal file
View file

@ -0,0 +1,38 @@
package cmd
import (
"fmt"
"github.com/spf13/cobra"
"github.com/spf13/viper"
)
// configureCmd represents the configure command
var configureCmd = &cobra.Command{
Use: "configure",
Short: "configure saves the provided global flags to the config file",
Long: `configure saves the provided global flags to the config file.
this makes using the cli easier as they don't have to be specifed all the time.`,
RunE: func(cmd *cobra.Command, args []string) error {
if viper.ConfigFileUsed() == "" {
err := viper.SafeWriteConfig()
if err != nil {
return fmt.Errorf("Writing Config: %w", err)
}
} else {
err := viper.WriteConfig()
if err != nil {
return fmt.Errorf("Writing Config: %w", err)
}
}
if viper.GetBool("debug") {
fmt.Printf("Saved: %+v\n", viper.AllSettings())
}
return nil
},
}
func init() {
rootCmd.AddCommand(configureCmd)
}