snapshot of https://github.com/ory/keto.git (master, 2026-09-16; blobs > 131072B omitted)
Some checks failed
CI / Run lints and checks (push) Failing after 47s
CI / Run tests (push) Failing after 1s
CI / Run race tests (push) Failing after 5s
CI / Build CLI docs (push) Has been skipped
CI / Run buf actions (push) Failing after 5s
CodeQL / Analyze (go) (push) Failing after 3s
CodeQL / Analyze (javascript) (push) Failing after 2s
Docker Image Scanners / scanners (push) Failing after 3s
Format / format (push) Failing after 3s
Synchronize Issue Labels / Synchronize Issue Labels (push) Has been skipped
CI / Generate release (push) Has been skipped
CI / Draft newsletter (push) Has been skipped
CI / Pending approval Slack notification (push) Has been skipped
CI / Send newsletter (push) Has been skipped
Some checks failed
CI / Run lints and checks (push) Failing after 47s
CI / Run tests (push) Failing after 1s
CI / Run race tests (push) Failing after 5s
CI / Build CLI docs (push) Has been skipped
CI / Run buf actions (push) Failing after 5s
CodeQL / Analyze (go) (push) Failing after 3s
CodeQL / Analyze (javascript) (push) Failing after 2s
Docker Image Scanners / scanners (push) Failing after 3s
Format / format (push) Failing after 3s
Synchronize Issue Labels / Synchronize Issue Labels (push) Has been skipped
CI / Generate release (push) Has been skipped
CI / Draft newsletter (push) Has been skipped
CI / Pending approval Slack notification (push) Has been skipped
CI / Send newsletter (push) Has been skipped
This commit is contained in:
74
cmd/root.go
Normal file
74
cmd/root.go
Normal file
@@ -0,0 +1,74 @@
|
||||
// Copyright © 2023 Ory Corp
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
package cmd
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"runtime"
|
||||
|
||||
"github.com/spf13/cobra"
|
||||
|
||||
"github.com/ory/x/cmdx"
|
||||
"github.com/ory/x/configx"
|
||||
|
||||
"github.com/ory/keto/cmd/check"
|
||||
"github.com/ory/keto/cmd/expand"
|
||||
"github.com/ory/keto/cmd/migrate"
|
||||
"github.com/ory/keto/cmd/namespace"
|
||||
"github.com/ory/keto/cmd/relationtuple"
|
||||
"github.com/ory/keto/cmd/server"
|
||||
"github.com/ory/keto/cmd/status"
|
||||
"github.com/ory/keto/internal/driver/config"
|
||||
"github.com/ory/keto/ketoctx"
|
||||
)
|
||||
|
||||
func NewRootCmd(opts ...ketoctx.Option) *cobra.Command {
|
||||
cmd := &cobra.Command{
|
||||
Use: "keto",
|
||||
Short: "Global and consistent permission and authorization server",
|
||||
}
|
||||
|
||||
configx.RegisterConfigFlag(cmd.PersistentFlags(), []string{filepath.Join(userHomeDir(), "keto.yml")})
|
||||
|
||||
relationtuple.RegisterCommandsRecursive(cmd)
|
||||
namespace.RegisterCommandsRecursive(cmd, opts)
|
||||
migrate.RegisterCommandsRecursive(cmd, opts)
|
||||
server.RegisterCommandsRecursive(cmd, opts)
|
||||
check.RegisterCommandsRecursive(cmd)
|
||||
expand.RegisterCommandsRecursive(cmd)
|
||||
status.RegisterCommandRecursive(cmd)
|
||||
|
||||
cmd.AddCommand(cmdx.Version(&config.Version, &config.Commit, &config.Date))
|
||||
|
||||
return cmd
|
||||
}
|
||||
|
||||
// Execute adds all child commands to the root command sets flags appropriately.
|
||||
// This is called by main.main(). It only needs to happen once to the rootCmd.
|
||||
func Execute() {
|
||||
ctx, cancel := context.WithCancel(context.Background())
|
||||
defer cancel()
|
||||
|
||||
if err := NewRootCmd().ExecuteContext(ctx); err != nil {
|
||||
if !errors.Is(err, cmdx.ErrNoPrintButFail) {
|
||||
fmt.Println(err)
|
||||
}
|
||||
os.Exit(-1)
|
||||
}
|
||||
}
|
||||
|
||||
func userHomeDir() string {
|
||||
if runtime.GOOS == "windows" {
|
||||
home := os.Getenv("HOMEDRIVE") + os.Getenv("HOMEPATH")
|
||||
if home == "" {
|
||||
home = os.Getenv("USERPROFILE")
|
||||
}
|
||||
return home
|
||||
}
|
||||
return os.Getenv("HOME")
|
||||
}
|
||||
Reference in New Issue
Block a user