/
root.go
60 lines (49 loc) · 1.54 KB
/
root.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
package cmd
import (
"errors"
"fmt"
"os"
"github.com/ory/kratos/cmd/cleanup"
"github.com/ory/kratos/driver/config"
"github.com/ory/kratos/cmd/courier"
"github.com/ory/kratos/cmd/hashers"
"github.com/ory/kratos/cmd/remote"
"github.com/ory/kratos/cmd/identities"
"github.com/ory/kratos/cmd/jsonnet"
"github.com/ory/kratos/cmd/migrate"
"github.com/ory/kratos/cmd/serve"
"github.com/ory/x/cmdx"
"github.com/spf13/cobra"
)
// RootCmd represents the base command when called without any subcommands
func NewRootCmd() (cmd *cobra.Command) {
cmd = &cobra.Command{
Use: "kratos",
}
courier.RegisterCommandRecursive(cmd)
cmd.AddCommand(identities.NewGetCmd(cmd))
cmd.AddCommand(identities.NewDeleteCmd(cmd))
cmd.AddCommand(jsonnet.NewFormatCmd())
hashers.RegisterCommandRecursive(cmd)
cmd.AddCommand(identities.NewImportCmd(cmd))
cmd.AddCommand(jsonnet.NewLintCmd())
cmd.AddCommand(identities.NewListCmd(cmd))
migrate.RegisterCommandRecursive(cmd)
serve.RegisterCommandRecursive(cmd)
cleanup.RegisterCommandRecursive(cmd)
remote.RegisterCommandRecursive(cmd)
cmd.AddCommand(identities.NewValidateCmd())
cmd.AddCommand(cmdx.Version(&config.Version, &config.Commit, &config.Date))
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() {
c := NewRootCmd()
if err := c.Execute(); err != nil {
if !errors.Is(err, cmdx.ErrNoPrintButFail) {
_, _ = fmt.Fprintln(c.ErrOrStderr(), err)
}
os.Exit(1)
}
}