11package cmd
22
33import (
4- "fmt"
54"github.com/newclarity/scribeHelpers/loadTools"
65"github.com/newclarity/scribeHelpers/toolSelfUpdate"
76"github.com/newclarity/scribeHelpers/ux"
87"github.com/spf13/cobra"
9- "github.com/spf13/viper"
108"github.com/wplib/deploywp/defaults"
119"github.com/wplib/deploywp/deploywp"
1210)
@@ -35,8 +33,8 @@ const DefaultTemplateFile = `{{ BuildDeployWp .Json .Exec.Args }}`
3533
3634var CmdSelfUpdate * toolSelfUpdate.TypeSelfUpdate
3735var CmdScribe * loadTools.TypeScribeArgs
38- var ConfigFile string
39- const flagConfigFile = "config"
36+ // var ConfigFile string
37+ // const flagConfigFile = "config"
4038
4139
4240var rootCmd = & cobra.Command {
@@ -49,10 +47,11 @@ var rootCmd = &cobra.Command{
4947
5048func init () {
5149SetCmd ()
52- cobra .OnInitialize (initConfig )
53-
54- rootCmd .PersistentFlags ().StringVar (& ConfigFile , flagConfigFile , fmt .Sprintf ("%s-config.json" , defaults .BinaryName ), ux .SprintfBlue ("%s: config file." , defaults .BinaryName ))
55- _ = rootCmd .PersistentFlags ().MarkHidden (flagConfigFile )
50+ //cobra.OnInitialize(initConfig)
51+ //cobra.EnableCommandSorting = false
52+ //
53+ //rootCmd.PersistentFlags().StringVar(&ConfigFile, flagConfigFile, fmt.Sprintf("%s-config.json", defaults.BinaryName), ux.SprintfBlue("%s: config file.", defaults.BinaryName))
54+ //_ = rootCmd.PersistentFlags().MarkHidden(flagConfigFile)
5655
5756//rootCmd.PersistentFlags().StringVarP(&CmdScribe.Json.File, loadTools.FlagJsonFile, "j", DefaultJsonFile, ux.SprintfBlue("Alternative JSON file."))
5857//rootCmd.PersistentFlags().StringVarP(&CmdScribe.Template.File, loadTools.FlagTemplateFile, "t", DefaultTemplateFile, ux.SprintfBlue("Alternative template file."))
@@ -76,29 +75,29 @@ func init() {
7675
7776
7877// initConfig reads in config file and ENV variables if set.
79- func initConfig () {
80- if ConfigFile != "" {
81- // Use config file from the flag.
82- viper .SetConfigFile (ConfigFile )
83- } else {
84- // Find home directory.
85- //home, err := homedir.Dir()
86- //if err != nil {
87- // fmt.Println(err)
88- // os.Exit(1)
89- //}
90-
91- viper .AddConfigPath ("." )
92- viper .SetConfigName (defaults .BinaryName + "-config" )
93- }
94-
95- viper .AutomaticEnv () // read in environment variables that match
96-
97- // If a config file is found, read it in.
98- if err := viper .ReadInConfig (); err == nil {
99- fmt .Println ("Using config file:" , viper .ConfigFileUsed ())
100- }
101- }
78+ // func initConfig() {
79+ // if ConfigFile != "" {
80+ // // Use config file from the flag.
81+ // viper.SetConfigFile(ConfigFile)
82+ // } else {
83+ // // Find home directory.
84+ // //home, err := homedir.Dir()
85+ // //if err != nil {
86+ // // fmt.Println(err)
87+ // // os.Exit(1)
88+ // //}
89+ //
90+ // viper.AddConfigPath(".")
91+ // viper.SetConfigName(defaults.BinaryName + "-config")
92+ // }
93+ //
94+ // viper.AutomaticEnv() // read in environment variables that match
95+ //
96+ // // If a config file is found, read it in.
97+ // if err := viper.ReadInConfig(); err == nil {
98+ // fmt.Println("Using config file:", viper.ConfigFileUsed())
99+ // }
100+ // }
102101
103102
104103func SetCmd () {
@@ -121,6 +120,11 @@ func SetCmd() {
121120break
122121}
123122
123+ CmdScribe .AddConfigOption (false , false )
124+ if CmdScribe .State .IsNotOk () {
125+ break
126+ }
127+
124128// This executable is based on Scribe, but we are going to disable some things that we don't need.
125129CmdScribe .FlagHide (loadTools .FlagScribeFile )
126130CmdScribe .FlagSetDefault (loadTools .FlagJsonFile , DefaultJsonFile )
@@ -200,7 +204,31 @@ func Execute() *ux.State {
200204CmdScribe .State .SetError (err )
201205break
202206}
207+
208+ CmdScribe .State = CheckReturns ()
203209}
204210
205211return CmdScribe .State
206212}
213+
214+
215+ func CheckReturns () * ux.State {
216+ astate := CmdScribe .State
217+ for range onlyOnce {
218+ if CmdScribe .State .IsNotOk () {
219+ state = CmdScribe .State
220+ break
221+ }
222+
223+ if CmdSelfUpdate .State .IsNotOk () {
224+ state = CmdSelfUpdate .State
225+ break
226+ }
227+
228+ //if CobraHelp.State.IsNotOk() {
229+ // state = CobraHelp.State
230+ // break
231+ //}
232+ }
233+ return state
234+ }
0 commit comments