diff options
| author | Clement Michaud <clement.michaud34@gmail.com> | 2019-12-08 16:51:12 +0100 | 
|---|---|---|
| committer | Clément Michaud <clement.michaud34@gmail.com> | 2019-12-09 13:03:12 +0100 | 
| commit | b4a8c4f0ec69773e4667dbdabecb07d71f6dc6fe (patch) | |
| tree | f5e1c5b75642a1ee1f9ccd7d9165cbca0a1c0efe /cmd/authelia | |
| parent | 55460035f7671d7261e67ac0739ca6cf4e131db5 (diff) | |
Introduce version command to Authelia to check the version
The version command displays the tag and the commit hash of the
built commit along with the time when the build was done.
Diffstat (limited to 'cmd/authelia')
| -rw-r--r-- | cmd/authelia/constants.go | 5 | ||||
| -rw-r--r-- | cmd/authelia/main.go | 48 | 
2 files changed, 36 insertions, 17 deletions
diff --git a/cmd/authelia/constants.go b/cmd/authelia/constants.go new file mode 100644 index 000000000..2317e6c38 --- /dev/null +++ b/cmd/authelia/constants.go @@ -0,0 +1,5 @@ +package main + +var BuildTag = "__BUILD_TAG__" +var BuildCommit = "__BUILD_COMMIT__" +var BuildTime = "__BUILD_TIME__" diff --git a/cmd/authelia/main.go b/cmd/authelia/main.go index a5ceb3b96..629e168c7 100644 --- a/cmd/authelia/main.go +++ b/cmd/authelia/main.go @@ -2,7 +2,7 @@ package main  import (  	"errors" -	"flag" +	"fmt"  	"log"  	"os" @@ -18,33 +18,24 @@ import (  	"github.com/clems4ever/authelia/internal/storage"  	"github.com/clems4ever/authelia/internal/utils"  	"github.com/sirupsen/logrus" +	"github.com/spf13/cobra"  ) -func tryExtractConfigPath() (string, error) { -	configPtr := flag.String("config", "", "The path to a configuration file.") -	flag.Parse() +var configPathFlag string -	if *configPtr == "" { -		return "", errors.New("No config file path provided") +func startServer() { +	if configPathFlag == "" { +		log.Fatal(errors.New("No config file path provided"))  	} -	return *configPtr, nil -} - -func main() {  	if os.Getenv("ENVIRONMENT") == "dev" {  		logging.Logger().Info("===> Authelia is running in development mode. <===")  	} -	configPath, err := tryExtractConfigPath() -	if err != nil { -		logging.Logger().Error(err) -	} - -	config, errs := configuration.Read(configPath) +	config, errs := configuration.Read(configPathFlag)  	if len(errs) > 0 { -		for _, err = range errs { +		for _, err := range errs {  			logging.Logger().Error(err)  		}  		panic(errors.New("Some errors have been reported")) @@ -109,3 +100,26 @@ func main() {  	}  	server.StartServer(*config, providers)  } + +func main() { +	rootCmd := &cobra.Command{ +		Use: "authelia", +		Run: func(cmd *cobra.Command, args []string) { +			startServer() +		}, +	} + +	rootCmd.Flags().StringVar(&configPathFlag, "config", "", "Configuration file") + +	versionCmd := &cobra.Command{ +		Use: "version", +		Run: func(cmd *cobra.Command, args []string) { +			fmt.Printf("build git tag: %s\n", BuildTag) +			fmt.Printf("build git commit: %s\n", BuildCommit) +			fmt.Printf("build time: %s\n", BuildTime) +		}, +	} + +	rootCmd.AddCommand(versionCmd) +	rootCmd.Execute() +}  | 
