@@ -21,7 +21,7 @@ var addCmd = &cobra.Command{
21
21
//init struct project
22
22
var project Project
23
23
24
- if args == nil && args [0 ] == "" && args [1 ] == "" || len (args ) > 2 {
24
+ if args == nil && args [0 ] == "" && args [1 ] == "" || len (args ) > 2 || len ( args ) < 2 {
25
25
log .Fatal ("Command error" )
26
26
} else if args [0 ] != "" && args [1 ] == "." {
27
27
project .name = args [0 ]
@@ -53,27 +53,26 @@ func addProjectActually(project *Project) {
53
53
func addProject (project * Project ) {
54
54
//the environment variable is stored in a variable in order to create and find the path.json file in the directory where the app is located
55
55
filEnv := os .Getenv ("goproject" )
56
- _ , errr := os .OpenFile (filEnv + "/path.json" , os .O_APPEND | os .O_WRONLY | os .O_CREATE , 0600 )
57
- if errr != nil {
58
- panic (errr )
56
+ _ , errs := os .OpenFile (filEnv + "/path.json" , os .O_APPEND | os .O_WRONLY | os .O_CREATE , 0600 )
57
+ if errs != nil {
58
+ panic (errs )
59
59
}
60
60
61
- vp := viper .New ()
62
- vp .SetConfigName ("path" )
63
- vp .SetConfigType ("json" )
64
- vp .AddConfigPath (filEnv )
65
- err := vp .ReadInConfig ()
61
+ viper .SetConfigName ("path" )
62
+ viper .SetConfigType ("json" )
63
+ viper .AddConfigPath (filEnv )
64
+ err := viper .ReadInConfig ()
66
65
if err != nil {
67
66
fmt .Println (err )
68
67
}
69
68
70
- vp .Set (project .name , project .path )
71
- vp .WriteConfig ()
69
+ viper .Set (project .name , project .path )
70
+ viper .WriteConfig ()
72
71
73
- vp .OnConfigChange (func (in fsnotify.Event ) {
74
- fmt .Printf ("le projet %s ete ajouter" , in . Name )
72
+ viper .OnConfigChange (func (in fsnotify.Event ) {
73
+ fmt .Printf ("project add" )
75
74
})
76
- vp .WatchConfig ()
75
+ viper .WatchConfig ()
77
76
}
78
77
79
78
func init () {
0 commit comments