This repository has been archived by the owner on Apr 29, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 9
/
root.go
79 lines (61 loc) · 2 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
68
69
70
71
72
73
74
75
76
77
78
79
package main
import (
"context"
"github.com/caos/orbos/internal/helpers"
"github.com/caos/orbos/internal/git"
"github.com/spf13/cobra"
"github.com/caos/orbos/internal/orb"
"github.com/caos/orbos/mntr"
)
type RootValues func() (context.Context, mntr.Monitor, *orb.Orb, *git.Client, errFunc)
type errFunc func(cmd *cobra.Command) error
func curryErrFunc(rootCmd *cobra.Command, err error) errFunc {
return func(cmd *cobra.Command) error {
cmd.SetUsageFunc(func(_ *cobra.Command) error {
return rootCmd.Usage()
})
return err
}
}
func RootCommand() (*cobra.Command, RootValues) {
var (
verbose bool
orbConfigPath string
)
cmd := &cobra.Command{
Use: "orbctl [flags]",
Short: "Interact with your orbs",
Long: `orbctl launches orbiters and simplifies common tasks such as updating your kubeconfig.
Participate in our community on https://github.com/caos/orbos
and visit our website at https://caos.ch`,
Example: `$ mkdir -p ~/.orb
$ cat > ~/.orb/myorb << EOF
> url: git@github.com:me/my-orb.git
> masterkey: "$(gopass my-secrets/orbs/myorb/masterkey)"
> repokey: |
> $(cat ~/.ssh/myorbrepo | sed s/^/\ \ /g)
> EOF
$ orbctl -f ~/.orb/myorb [command]
`,
}
flags := cmd.PersistentFlags()
flags.StringVarP(&orbConfigPath, "orbconfig", "f", "~/.orb/config", "Path to the file containing the orbs git repo URL, deploy key and the master key for encrypting and decrypting secrets")
flags.BoolVar(&verbose, "verbose", false, "Print debug levelled logs")
return cmd, func() (context.Context, mntr.Monitor, *orb.Orb, *git.Client, errFunc) {
monitor := mntr.Monitor{
OnInfo: mntr.LogMessage,
OnChange: mntr.LogMessage,
OnError: mntr.LogError,
}
if verbose {
monitor = monitor.Verbose()
}
prunedPath := helpers.PruneHome(orbConfigPath)
orbConfig, err := orb.ParseOrbConfig(prunedPath)
if err != nil {
orbConfig = &orb.Orb{Path: prunedPath}
}
ctx := context.Background()
return ctx, monitor, orbConfig, git.New(ctx, monitor, "orbos", "orbos@caos.ch"), nil
}
}