This commit is contained in:
2020-10-11 07:50:18 -07:00
commit 3338f9d53d
8 changed files with 269 additions and 0 deletions

21
cmd/info.go Normal file
View File

@@ -0,0 +1,21 @@
package cmd
import (
"fmt"
"runtime/debug"
"github.com/spf13/cobra"
)
func init() {
rootCmd.AddCommand(infoCmd)
}
var infoCmd = &cobra.Command{
Use: "info",
Short: "Print tool info",
Run: func(cmd *cobra.Command, args []string) {
info, _ := debug.ReadBuildInfo()
fmt.Printf("%#v\n", info)
},
}

17
cmd/pwgen.go Normal file
View File

@@ -0,0 +1,17 @@
package cmd
import (
"github.com/spf13/cobra"
)
func init() {
rootCmd.AddCommand(pwgenCmd)
}
var pwgenCmd = &cobra.Command{
Use: "pwgen",
Short: "Print a randomly generated password",
Run: func(cmd *cobra.Command, args []string) {
panic("unimplemented")
},
}

52
cmd/root.go Normal file
View File

@@ -0,0 +1,52 @@
package cmd
import (
"fmt"
"os"
"github.com/mitchellh/go-homedir"
"github.com/spf13/cobra"
"github.com/spf13/viper"
)
var (
// Used for flags.
cfgFile string
userLicense string
rootCmd = &cobra.Command{
Use: "sn",
Short: "A shell utility program",
}
)
// Execute executes the root command.
func Execute() error {
return rootCmd.Execute()
}
func er(msg interface{}) {
fmt.Println("Error:", msg)
os.Exit(1)
}
func init() {
cobra.OnInitialize(initConfig)
}
func initConfig() {
home, err := homedir.Dir()
if err != nil {
er(err)
}
// Search config in home directory with name ".cobra" (without extension).
viper.AddConfigPath(home)
viper.SetConfigName(".sneak")
viper.AutomaticEnv()
if err := viper.ReadInConfig(); err == nil {
fmt.Println("Using config file:", viper.ConfigFileUsed())
}
}

20
cmd/version.go Normal file
View File

@@ -0,0 +1,20 @@
package cmd
import (
"fmt"
"github.com/spf13/cobra"
)
func init() {
rootCmd.AddCommand(versionCmd)
}
var versionCmd = &cobra.Command{
Use: "version",
Short: "Print the version number of Hugo",
Long: `All software has versions. This is Hugo's`,
Run: func(cmd *cobra.Command, args []string) {
fmt.Println("sn version")
},
}