Remove config init commands
This commit is contained in:
@@ -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
|
|
||||||
},
|
|
||||||
}
|
|
||||||
@@ -75,7 +75,6 @@ func Execute() {
|
|||||||
configPath := filepath.Join(dir, "config.toml")
|
configPath := filepath.Join(dir, "config.toml")
|
||||||
|
|
||||||
cobra.OnInitialize(initConfig)
|
cobra.OnInitialize(initConfig)
|
||||||
rootCmd.AddCommand(initCmd)
|
|
||||||
rootCmd.PersistentFlags().StringVarP(&cfgFile, "config", "c", configPath, "config file")
|
rootCmd.PersistentFlags().StringVarP(&cfgFile, "config", "c", configPath, "config file")
|
||||||
rootCmd.PersistentFlags().StringP("loglevel", "l", "info", "Log level")
|
rootCmd.PersistentFlags().StringP("loglevel", "l", "info", "Log level")
|
||||||
rootCmd.PersistentFlags().BoolP("json", "j", false, "Output logs in JSON format")
|
rootCmd.PersistentFlags().BoolP("json", "j", false, "Output logs in JSON format")
|
||||||
|
|||||||
@@ -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
|
|
||||||
},
|
|
||||||
}
|
|
||||||
@@ -36,7 +36,7 @@ func Execute() {
|
|||||||
|
|
||||||
cobra.OnInitialize(initConfig)
|
cobra.OnInitialize(initConfig)
|
||||||
rootCmd.SetUsageTemplate(rootUsage)
|
rootCmd.SetUsageTemplate(rootUsage)
|
||||||
rootCmd.AddCommand(initCmd, runCmd, serviceCmd)
|
rootCmd.AddCommand(runCmd, serviceCmd)
|
||||||
|
|
||||||
home, err := homedir.Dir()
|
home, err := homedir.Dir()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
2
go.mod
2
go.mod
@@ -19,7 +19,7 @@ require (
|
|||||||
github.com/inconshreveable/mousetrap v1.0.0 // indirect
|
github.com/inconshreveable/mousetrap v1.0.0 // indirect
|
||||||
github.com/magiconair/properties v1.8.5 // indirect
|
github.com/magiconair/properties v1.8.5 // indirect
|
||||||
github.com/mitchellh/mapstructure v1.4.3 // 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/pkg/errors v0.9.1
|
||||||
github.com/spf13/afero v1.8.0 // indirect
|
github.com/spf13/afero v1.8.0 // indirect
|
||||||
github.com/spf13/cast v1.4.1 // indirect
|
github.com/spf13/cast v1.4.1 // indirect
|
||||||
|
|||||||
Reference in New Issue
Block a user