This repository has been archived by the owner on May 3, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 54
/
root.go
65 lines (57 loc) · 1.51 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
package main
import (
"fmt"
"io"
log "github.com/sirupsen/logrus"
"github.com/spf13/cobra"
)
var verbose bool
// newRootCmd builds the root duffle command
// - outputRedirect: Optional, specify to capture all command output (stderr and stdout)
func newRootCmd(outputRedirect io.Writer) *cobra.Command {
const usage = `The CNAB installer`
cmd := &cobra.Command{
Use: "duffle",
Short: usage,
SilenceUsage: true,
Long: usage,
PersistentPreRunE: func(cmd *cobra.Command, args []string) error {
if verbose {
log.SetLevel(log.DebugLevel)
}
if cmd.Name() == "init" || cmd.Name() == "version" {
return nil
}
err := autoInit(cmd.OutOrStdout(), false)
if err != nil {
fmt.Fprintf(cmd.OutOrStderr(), "pre-flight check failed: %s", err)
}
return err
},
}
cmd.SetOutput(outputRedirect)
outLog := cmd.OutOrStdout()
p := cmd.PersistentFlags()
p.StringVar(&duffleHome, "home", defaultDuffleHome(), "location of your Duffle config. Overrides $DUFFLE_HOME")
p.BoolVarP(&verbose, "verbose", "v", false, "enable verbose output")
cmd.AddCommand(
newBuildCmd(outLog),
newBundleCmd(outLog),
newInitCmd(outLog),
newShowCmd(outLog),
newListCmd(outLog),
newRelocateCmd(outLog),
newVersionCmd(outLog),
newInstallCmd(outLog),
newStatusCmd(outLog),
newUninstallCmd(outLog),
newUpgradeCmd(outLog),
newRunCmd(outLog),
newCredentialsCmd(outLog),
newClaimsCmd(outLog),
newExportCmd(outLog),
newImportCmd(outLog),
newCreateCmd(outLog),
)
return cmd
}