Skip to content
This repository was archived by the owner on Jan 25, 2022. It is now read-only.

Commit 5f238d5

Browse files
committed
Better help
1 parent bdc7af7 commit 5f238d5

File tree

4 files changed

+131
-75
lines changed

4 files changed

+131
-75
lines changed

.idea/workspace.xml

Lines changed: 33 additions & 31 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

cmd/root.go

Lines changed: 59 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,10 @@
11
package cmd
22

33
import (
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

3634
var CmdSelfUpdate *toolSelfUpdate.TypeSelfUpdate
3735
var CmdScribe *loadTools.TypeScribeArgs
38-
var ConfigFile string
39-
const flagConfigFile = "config"
36+
//var ConfigFile string
37+
//const flagConfigFile = "config"
4038

4139

4240
var rootCmd = &cobra.Command{
@@ -49,10 +47,11 @@ var rootCmd = &cobra.Command{
4947

5048
func init() {
5149
SetCmd()
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

104103
func SetCmd() {
@@ -121,6 +120,11 @@ func SetCmd() {
121120
break
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.
125129
CmdScribe.FlagHide(loadTools.FlagScribeFile)
126130
CmdScribe.FlagSetDefault(loadTools.FlagJsonFile, DefaultJsonFile)
@@ -200,7 +204,31 @@ func Execute() *ux.State {
200204
CmdScribe.State.SetError(err)
201205
break
202206
}
207+
208+
CmdScribe.State = CheckReturns()
203209
}
204210

205211
return 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+
}

go.mod

Lines changed: 21 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -35,24 +35,32 @@ replace github.com/newclarity/scribeHelpers/toolGhr => ../scribeHelpers/toolGhr
3535
require (
3636
github.com/fsnotify/fsnotify v1.4.9 // indirect
3737
github.com/jinzhu/copier v0.0.0-20190924061706-b57f9002281a
38-
github.com/mitchellh/mapstructure v1.3.1
39-
github.com/newclarity/scribeHelpers/loadTools v0.0.0-00010101000000-000000000000
40-
github.com/newclarity/scribeHelpers/toolCopy v0.0.0-00010101000000-000000000000
41-
github.com/newclarity/scribeHelpers/toolExec v0.0.0-20200604000029-dbb313f0fedc
42-
github.com/newclarity/scribeHelpers/toolGit v0.0.0-00010101000000-000000000000
43-
github.com/newclarity/scribeHelpers/toolPath v0.0.0-20200611181056-b2e5f7fd5978
44-
github.com/newclarity/scribeHelpers/toolPrompt v0.0.0-20200611181056-b2e5f7fd5978
45-
github.com/newclarity/scribeHelpers/toolRuntime v0.0.0-20200611181056-b2e5f7fd5978
46-
github.com/newclarity/scribeHelpers/toolSelfUpdate v0.0.0-00010101000000-000000000000
47-
github.com/newclarity/scribeHelpers/toolTypes v0.0.0-20200611181056-b2e5f7fd5978
48-
github.com/newclarity/scribeHelpers/ux v0.0.0-20200611181056-b2e5f7fd5978
38+
github.com/mitchellh/mapstructure v1.3.2
39+
github.com/mitchellh/reflectwalk v1.0.1 // indirect
40+
github.com/newclarity/scribeHelpers/loadTools v0.0.0-20200622120433-71e52f9004e9
41+
github.com/newclarity/scribeHelpers/toolCopy v0.0.0-20200622120433-71e52f9004e9
42+
github.com/newclarity/scribeHelpers/toolExec v0.0.0-20200622120433-71e52f9004e9
43+
github.com/newclarity/scribeHelpers/toolGhr v0.0.0-20200622120433-71e52f9004e9 // indirect
44+
github.com/newclarity/scribeHelpers/toolGit v0.0.0-20200622120433-71e52f9004e9
45+
github.com/newclarity/scribeHelpers/toolGitHub v0.0.0-20200622120433-71e52f9004e9 // indirect
46+
github.com/newclarity/scribeHelpers/toolPath v0.0.0-20200622120433-71e52f9004e9
47+
github.com/newclarity/scribeHelpers/toolPrompt v0.0.0-20200622120433-71e52f9004e9
48+
github.com/newclarity/scribeHelpers/toolRuntime v0.0.0-20200622120433-71e52f9004e9
49+
github.com/newclarity/scribeHelpers/toolSelfUpdate v0.0.0-20200622120433-71e52f9004e9
50+
github.com/newclarity/scribeHelpers/toolService v0.0.0-20200622120433-71e52f9004e9 // indirect
51+
github.com/newclarity/scribeHelpers/toolSystem v0.0.0-20200622120433-71e52f9004e9 // indirect
52+
github.com/newclarity/scribeHelpers/toolTypes v0.0.0-20200622120433-71e52f9004e9
53+
github.com/newclarity/scribeHelpers/toolUx v0.0.0-20200622120433-71e52f9004e9 // indirect
54+
github.com/newclarity/scribeHelpers/ux v0.0.0-20200622120433-71e52f9004e9
4955
github.com/pelletier/go-toml v1.8.0 // indirect
50-
github.com/spf13/afero v1.2.2 // indirect
56+
github.com/spf13/afero v1.3.0 // indirect
5157
github.com/spf13/cast v1.3.1 // indirect
5258
github.com/spf13/cobra v1.0.0
5359
github.com/spf13/jwalterweatherman v1.1.0 // indirect
5460
github.com/spf13/pflag v1.0.5 // indirect
5561
github.com/spf13/viper v1.7.0
56-
golang.org/x/crypto v0.0.0-20200604202706-70a84ac30bf9 // indirect
62+
golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9 // indirect
63+
golang.org/x/sys v0.0.0-20200622214017-ed371f2e16b4 // indirect
64+
golang.org/x/text v0.3.3 // indirect
5765
gopkg.in/ini.v1 v1.57.0 // indirect
5866
)

0 commit comments

Comments
 (0)