update durpcli

This commit is contained in:
2023-05-27 11:43:24 -05:00
parent f13224733f
commit ca21cb9811
18 changed files with 193 additions and 157 deletions

View File

@@ -1,38 +1,24 @@
/*
Copyright © 2022 NAME HERE <EMAIL ADDRESS>
*/
package cmd
import (
"fmt"
"os"
"github.com/DeveloperDurp/GoCLI/cmd/info"
"github.com/DeveloperDurp/GoCLI/cmd/net"
"github.com/spf13/cobra"
"github.com/spf13/viper"
"gitlab.com/DeveloperDurp/DurpCLI/cmd/auth"
"gitlab.com/DeveloperDurp/DurpCLI/cmd/cfg"
"gitlab.com/DeveloperDurp/DurpCLI/cmd/net"
)
var cfgFile string
// rootCmd represents the base command when called without any subcommands
var rootCmd = &cobra.Command{
Use: "GoCLI",
Short: "A brief description of your application",
Long: `A longer description that spans multiple lines and likely contains
examples and usage of using your application. 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.`,
// Uncomment the following line if your bare application
// has an action associated with it:
// Run: func(cmd *cobra.Command, args []string) { },
Use: "DurpCLI",
Short: "CLI Tool made for Durp",
Long: ``,
}
// Execute adds all child commands to the root command and sets flags appropriately.
// This is called by main.main(). It only needs to happen once to the rootCmd.
func Execute() {
err := rootCmd.Execute()
if err != nil {
@@ -41,7 +27,11 @@ func Execute() {
}
func setDefaults() {
viper.SetDefault("port", "8080")
viper.SetDefault("auth.url", "https://authentik.durp.info/application/o/token/")
viper.SetDefault("auth.grantType", "client_credentials")
viper.SetDefault("auth.clientID", "")
viper.SetDefault("auth.username", "")
viper.SetDefault("auth.password", "")
}
func init() {
@@ -49,45 +39,32 @@ func init() {
setDefaults()
err := viper.WriteConfigAs("GoCLI.backup.yaml")
err := viper.WriteConfigAs(".DurpCLI.yaml")
if err != nil {
fmt.Println(err)
}
// Here you will define your flags and configuration settings.
// Cobra supports persistent flags, which, if defined here,
// will be global for your application.
// Add my subcommand palette
rootCmd.AddCommand(info.InfoCmd)
rootCmd.AddCommand(net.NetCmd)
rootCmd.PersistentFlags().StringVar(&cfgFile, "config", "", "config file (default is $HOME/.toolbox.yaml)")
rootCmd.AddCommand(auth.AuthCmd)
rootCmd.AddCommand(cfg.Cfgcmd)
rootCmd.PersistentFlags().StringVar(&cfgFile, "config", "", "config file (default is $HOME/.DurpCLI.yaml)")
// Cobra also supports local flags, which will only run
// when this action is called directly.
rootCmd.Flags().BoolP("toggle", "t", false, "Help message for toggle")
}
// initConfig reads in config file and ENV variables if set.
func initConfig() {
if cfgFile != "" {
// Use config file from the flag.
viper.SetConfigFile(cfgFile)
} else {
// Find home directory.
home, err := os.UserHomeDir()
cobra.CheckErr(err)
// Search config in home directory with name ".toolbox" (without extension).
viper.AddConfigPath(home)
viper.SetConfigType("yaml")
viper.SetConfigName(".toolbox")
viper.SetConfigName(".DurpCLI")
}
viper.AutomaticEnv() // read in environment variables that match
viper.AutomaticEnv()
viper.ReadInConfig()
// If a config file is found, read it in.
if err := viper.ReadInConfig(); err == nil {
fmt.Fprintln(os.Stderr, "Using config file:", viper.ConfigFileUsed())
}
}