forked from ory/kratos
-
Notifications
You must be signed in to change notification settings - Fork 0
/
root.go
67 lines (54 loc) · 1.73 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
61
62
63
64
65
66
67
// Copyright © 2023 Ory Corp
// SPDX-License-Identifier: Apache-2.0
package cmd
import (
"errors"
"fmt"
"os"
"github.com/ory/kratos/cmd/cleanup"
"github.com/ory/kratos/driver/config"
"github.com/ory/x/jsonnetsecure"
"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"
)
func NewRootCmd() (cmd *cobra.Command) {
cmd = &cobra.Command{
Use: "kratos",
}
cmdx.EnableUsageTemplating(cmd)
courier.RegisterCommandRecursive(cmd, nil, nil)
cmd.AddCommand(identities.NewGetCmd())
cmd.AddCommand(identities.NewDeleteCmd())
cmd.AddCommand(jsonnet.NewFormatCmd())
hashers.RegisterCommandRecursive(cmd)
cmd.AddCommand(identities.NewImportCmd())
cmd.AddCommand(jsonnet.NewLintCmd())
cmd.AddCommand(identities.NewListCmd())
migrate.RegisterCommandRecursive(cmd)
serve.RegisterCommandRecursive(cmd, nil, nil)
cleanup.RegisterCommandRecursive(cmd)
remote.RegisterCommandRecursive(cmd)
cmd.AddCommand(identities.NewValidateCmd())
cmd.AddCommand(cmdx.Version(&config.Version, &config.Commit, &config.Date))
// Registers a hidden "jsonnet" subcommand for process-isolated Jsonnet VMs.
cmd.AddCommand(jsonnetsecure.NewJsonnetCmd())
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)
}
}