Files
hanko/backend/cmd/root.go
lfleischmann e963f26239 refactor(cmd): rework config initalization
Config initialization is done in the root command but some commands
do not require a config. If these commands are executed locally in the
checked out repo they work fine, but they will fail if they are
executed e.g. using the Docker image. I would have to provide
a config file path to the container and mount the referenced
file into the container even though it is not needed for the command.

This commit changes this by making those commands that require a
config load it themselves. It also pulls down the config flag to
the individual commands that require it instead of using a persistent
flag on the root level.
2023-04-11 16:56:12 +02:00

42 lines
940 B
Go

/*
Copyright © 2022 Hanko GmbH <developers@hanko.io>
*/
package cmd
import (
"github.com/spf13/cobra"
"github.com/teamhanko/hanko/backend/cmd/isready"
"github.com/teamhanko/hanko/backend/cmd/jwk"
"github.com/teamhanko/hanko/backend/cmd/jwt"
"github.com/teamhanko/hanko/backend/cmd/migrate"
"github.com/teamhanko/hanko/backend/cmd/serve"
"github.com/teamhanko/hanko/backend/cmd/version"
"log"
)
func NewRootCmd() *cobra.Command {
cmd := &cobra.Command{
Use: "hanko",
}
migrate.RegisterCommands(cmd)
serve.RegisterCommands(cmd)
isready.RegisterCommands(cmd)
jwk.RegisterCommands(cmd)
jwt.RegisterCommands(cmd)
version.RegisterCommands(cmd)
return cmd
}
// Execute adds all child commands to the root command and sets flags appropriately.
// This is called by main.main(). It only needs to happen once to the rootCmd.
func Execute() {
cmd := NewRootCmd()
err := cmd.Execute()
if err != nil {
log.Fatal(err)
}
}