diff --git a/cmd/command.go b/cmd/command.go index aa66d24..ab0e0fa 100644 --- a/cmd/command.go +++ b/cmd/command.go @@ -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 +} diff --git a/cmd/main.go b/cmd/main.go index 6031846..c0c60f8 100644 --- a/cmd/main.go +++ b/cmd/main.go @@ -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()