@@ -15,7 +15,7 @@ import (
1515 "strings"
1616)
1717
18- var AppVersion = "0.2.2 "
18+ var AppVersion = "0.2.3 "
1919
2020func main () {
2121 cliConfigDir , err := GetCLIConfigDir ()
@@ -50,18 +50,21 @@ func main() {
5050 }
5151 }
5252
53- // Define a set of commands that do not require KeyHolder initialisation.
54- skipKeyHolderCommands := map [string ]struct {}{"version" : {}, "docs" : {}, "help" : {}}
53+ // Define a set of commands that do not require KeyHolder or cli initialisation.
54+ skipInitCommands := map [string ]struct {}{"version" : {}, "docs" : {}, "help" : {}}
5555
5656 var keyHolder * secrets.KeyHolder
57-
5857 // Only initialise KeyHolder if the command isn't in the skip list.
58+ shouldInit := len (os .Args ) > 1
5959 if len (os .Args ) > 1 {
60- if _ , skip := skipKeyHolderCommands [os .Args [1 ]]; ! skip {
61- keyHolder = secrets . NewKeyHolder ( secrets . GetOrCreateClISecret ())
60+ if _ , skip := skipInitCommands [os .Args [1 ]]; skip {
61+ shouldInit = false
6262 }
6363 }
6464
65+ if shouldInit {
66+ keyHolder = secrets .NewKeyHolder (secrets .GetOrCreateClISecret ())
67+ }
6568 ctrl := pkg.ClICtrl {
6669 Client : api .NewClient (api.Params {
6770 Debug : viper .GetBool ("log.http" ),
@@ -71,16 +74,10 @@ func main() {
7174 KeyHolder : keyHolder ,
7275 }
7376
74- err = ctrl . Init ()
75- if err != nil {
76- panic ( err )
77+ if len ( os . Args ) == 1 {
78+ // If no arguments are passed, show help
79+ os . Args = append ( os . Args , "help" )
7780 }
78- defer func () {
79- if err := db .Close (); err != nil {
80- panic (err )
81- }
82- }()
83-
8481 if len (os .Args ) == 2 && os .Args [1 ] == "docs" {
8582 log .Println ("Generating docs" )
8683 err = cmd .GenerateDocs ()
@@ -89,9 +86,16 @@ func main() {
8986 }
9087 return
9188 }
92- if len (os .Args ) == 1 {
93- // If no arguments are passed, show help
94- os .Args = append (os .Args , "help" )
89+ if shouldInit {
90+ err = ctrl .Init ()
91+ if err != nil {
92+ panic (err )
93+ }
94+ defer func () {
95+ if err := db .Close (); err != nil {
96+ panic (err )
97+ }
98+ }()
9599 }
96100 if os .Args [1 ] == "version" && viper .GetString ("endpoint.api" ) != constants .EnteApiUrl {
97101 log .Printf ("Custom endpoint: %s\n " , viper .GetString ("endpoint.api" ))
@@ -120,10 +124,10 @@ func initConfig(cliConfigDir string) {
120124func GetCLIConfigDir () (string , error ) {
121125 var configDir = os .Getenv ("ENTE_CLI_CONFIG_DIR" )
122126
123- if configDir == "" {
124- // for backward compatibility, check for ENTE_CLI_CONFIG_PATH
125- configDir = os .Getenv ("ENTE_CLI_CONFIG_PATH" )
126- }
127+ if configDir == "" {
128+ // for backward compatibility, check for ENTE_CLI_CONFIG_PATH
129+ configDir = os .Getenv ("ENTE_CLI_CONFIG_PATH" )
130+ }
127131
128132 if configDir != "" {
129133 // remove trailing slash (for all OS)
0 commit comments