Remove config init commands

This commit is contained in:
2022-05-09 22:43:03 +02:00
parent 11b984cd3c
commit 19690dc0d5
5 changed files with 2 additions and 123 deletions

View File

@@ -1,59 +0,0 @@
package cli
import (
"fmt"
"os"
"path/filepath"
"github.com/apex/log"
"github.com/pelletier/go-toml"
"github.com/spf13/cobra"
"github.com/spf13/viper"
)
func init() {
initCmd.Flags().BoolP("print", "p", false, "Print default config to stdout")
}
var initCmd = &cobra.Command{
Use: "init",
Short: "Initialize portal",
RunE: func(cmd *cobra.Command, args []string) error {
print, err := cmd.Flags().GetBool("print")
if err != nil {
return err
}
if print {
c := viper.AllSettings()
bs, err := toml.Marshal(c)
if err != nil {
return fmt.Errorf("unable to marshal config: %v", err)
}
fmt.Println(string(bs))
return nil
}
dir := filepath.Dir(cfgFile)
if _, err := os.Stat(dir); os.IsNotExist(err) {
err = os.Mkdir(dir, 0755)
if err != nil {
return err
}
}
err = viper.SafeWriteConfigAs(cfgFile)
if err != nil {
if _, ok := err.(viper.ConfigFileAlreadyExistsError); !ok {
return fmt.Errorf("couldn't save config at \"%s\" (%s)", viper.ConfigFileUsed(), err)
}
} else {
log.Infof("Your config was saved at \"%s\"", viper.ConfigFileUsed())
return nil
}
log.Infof("Config already exists at \"%s\", no changes applied", viper.ConfigFileUsed())
return nil
},
}

View File

@@ -75,7 +75,6 @@ func Execute() {
configPath := filepath.Join(dir, "config.toml")
cobra.OnInitialize(initConfig)
rootCmd.AddCommand(initCmd)
rootCmd.PersistentFlags().StringVarP(&cfgFile, "config", "c", configPath, "config file")
rootCmd.PersistentFlags().StringP("loglevel", "l", "info", "Log level")
rootCmd.PersistentFlags().BoolP("json", "j", false, "Output logs in JSON format")

View File

@@ -1,61 +0,0 @@
package cli
import (
"fmt"
"os"
"path/filepath"
"github.com/apex/log"
"github.com/pelletier/go-toml"
"github.com/spf13/cobra"
"github.com/spf13/viper"
)
func init() {
initCmd.SetUsageTemplate(usage)
initCmd.Flags().BoolP("print", "p", false, "Print default config to stdout")
}
var initCmd = &cobra.Command{
Use: "init",
Short: "Initialize speedrun",
RunE: func(cmd *cobra.Command, args []string) error {
viper.SetDefault("gcp.projectid", "")
print, err := cmd.Flags().GetBool("print")
if err != nil {
return err
}
if print {
c := viper.AllSettings()
bs, err := toml.Marshal(c)
if err != nil {
return fmt.Errorf("unable to marshal config: %v", err)
}
fmt.Println(string(bs))
return nil
}
dir := filepath.Dir(cfgFile)
if _, err := os.Stat(dir); os.IsNotExist(err) {
err = os.Mkdir(dir, 0755)
if err != nil {
return err
}
}
err = viper.SafeWriteConfigAs(cfgFile)
if err != nil {
if _, ok := err.(viper.ConfigFileAlreadyExistsError); !ok {
return fmt.Errorf("couldn't save config at \"%s\" (%s)", viper.ConfigFileUsed(), err)
}
} else {
log.Infof("Your config was saved at \"%s\"", viper.ConfigFileUsed())
return nil
}
log.Infof("Config already exists at \"%s\", no changes applied", viper.ConfigFileUsed())
return nil
},
}

View File

@@ -36,7 +36,7 @@ func Execute() {
cobra.OnInitialize(initConfig)
rootCmd.SetUsageTemplate(rootUsage)
rootCmd.AddCommand(initCmd, runCmd, serviceCmd)
rootCmd.AddCommand(runCmd, serviceCmd)
home, err := homedir.Dir()
if err != nil {

2
go.mod
View File

@@ -19,7 +19,7 @@ require (
github.com/inconshreveable/mousetrap v1.0.0 // indirect
github.com/magiconair/properties v1.8.5 // indirect
github.com/mitchellh/mapstructure v1.4.3 // indirect
github.com/pelletier/go-toml v1.9.4
github.com/pelletier/go-toml v1.9.4 // indirect
github.com/pkg/errors v0.9.1
github.com/spf13/afero v1.8.0 // indirect
github.com/spf13/cast v1.4.1 // indirect