Files
upstream-ory-kratos/cmd/root.go
upstream-mirror c60cc7ca75
Some checks failed
CI / Run tests and lints (push) Failing after 29s
CI / Build CLI docs (push) Has been skipped
CI / Run Playwright end-to-end tests (mysql) (push) Failing after 3s
CI / Run Playwright end-to-end tests (postgres) (push) Failing after 2s
CI / Run Playwright end-to-end tests (sqlite) (push) Failing after 3s
CodeQL / Analyze (go) (push) Failing after 4s
CodeQL / Analyze (javascript) (push) Failing after 3s
Docker Image Scanners / scanners (push) Failing after 4s
Synchronize Issue Labels / Synchronize Issue Labels (push) Has been skipped
CI / Run end-to-end tests (postgres) (push) Failing after 19s
CI / Run end-to-end tests (sqlite) (push) Failing after 2s
CI / Run Playwright end-to-end tests (cockroach) (push) Failing after 2s
CI / Draft newsletter (push) Has been skipped
CI / Generate release (push) Has been skipped
CI / Pending approval Slack notification (push) Has been skipped
CI / Send newsletter (push) Has been skipped
snapshot of https://github.com/ory/kratos.git (master, 2026-09-15; blobs > 131072B omitted)
2026-09-15 21:19:12 +05:00

73 lines
2.0 KiB
Go

// Copyright © 2023 Ory Corp
// SPDX-License-Identifier: Apache-2.0
package cmd
import (
"errors"
"fmt"
"runtime"
"github.com/spf13/cobra"
"github.com/ory/kratos/cmd/cleanup"
"github.com/ory/kratos/cmd/courier"
"github.com/ory/kratos/cmd/hashers"
"github.com/ory/kratos/cmd/identities"
"github.com/ory/kratos/cmd/jsonnet"
"github.com/ory/kratos/cmd/migrate"
"github.com/ory/kratos/cmd/remote"
"github.com/ory/kratos/cmd/serve"
"github.com/ory/kratos/driver"
"github.com/ory/kratos/driver/config"
"github.com/ory/x/cmdx"
"github.com/ory/x/jsonnetsecure"
"github.com/ory/x/profilex"
)
func NewRootCmd(driverOpts ...driver.RegistryOption) (cmd *cobra.Command) {
cmd = &cobra.Command{
Use: "kratos",
}
cmdx.EnableUsageTemplating(cmd)
courier.RegisterCommandRecursive(cmd, driverOpts)
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, driverOpts)
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() int {
defer profilex.Profile().Stop()
jsonnetPool := jsonnetsecure.NewProcessPool(runtime.GOMAXPROCS(0))
defer jsonnetPool.Close()
c := NewRootCmd(driver.WithJsonnetPool(jsonnetPool))
if err := c.Execute(); err != nil {
if !errors.Is(err, cmdx.ErrNoPrintButFail) {
_, _ = fmt.Fprintln(c.ErrOrStderr(), err)
}
return 1
}
return 0
}