Add method to validate configuration
This commit is contained in:
parent
b9e98679a1
commit
c3495ac57a
@ -1,6 +1,7 @@
|
||||
package lumecmd
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"flag"
|
||||
"fmt"
|
||||
"strconv"
|
||||
@ -92,3 +93,12 @@ func GetCommand(name string) (Command, bool) {
|
||||
cmd, ok := commandRegistry[name]
|
||||
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
|
||||
}
|
||||
|
||||
if config.AccessToken == "" {
|
||||
err = errors.New("fatal: access token is not set")
|
||||
return ExitError, err
|
||||
if err = config.Validate(); err != nil {
|
||||
return ExitError, fmt.Errorf("fatal: %s", err)
|
||||
}
|
||||
|
||||
flag.Parse()
|
||||
|
Loading…
Reference in New Issue
Block a user