Add method to validate configuration
This commit is contained in:
parent
e024b45e0a
commit
f0b8828af9
@ -1,6 +1,7 @@
|
|||||||
package lumecmd
|
package lumecmd
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"errors"
|
||||||
"flag"
|
"flag"
|
||||||
"fmt"
|
"fmt"
|
||||||
"strconv"
|
"strconv"
|
||||||
@ -92,3 +93,12 @@ func GetCommand(name string) (Command, bool) {
|
|||||||
cmd, ok := commandRegistry[name]
|
cmd, ok := commandRegistry[name]
|
||||||
return cmd, ok
|
return cmd, ok
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Validate configuration struct
|
||||||
|
func (c *Config) Validate() error {
|
||||||
|
var err error
|
||||||
|
if c.AccessToken == "" {
|
||||||
|
err = errors.New("access_token is not set")
|
||||||
|
}
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
@ -33,9 +33,8 @@ func Main(args []string) (int, error) {
|
|||||||
config.AccessToken = envAccessToken
|
config.AccessToken = envAccessToken
|
||||||
}
|
}
|
||||||
|
|
||||||
if config.AccessToken == "" {
|
if err = config.Validate(); err != nil {
|
||||||
err = errors.New("fatal: access token is not set")
|
return ExitError, fmt.Errorf("fatal: %s", err)
|
||||||
return ExitError, err
|
|
||||||
}
|
}
|
||||||
|
|
||||||
flag.Parse()
|
flag.Parse()
|
||||||
|
Loading…
Reference in New Issue
Block a user