-
Notifications
You must be signed in to change notification settings - Fork 143
/
root.go
85 lines (72 loc) · 2.75 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
80
81
82
83
84
85
// SPDX-License-Identifier: Apache-2.0
// SPDX-FileCopyrightText: 2021-Present The Zarf Authors
// Package cmd contains the CLI commands for Zarf.
package cmd
import (
"fmt"
"os"
"strings"
"github.com/defenseunicorns/zarf/src/cmd/common"
"github.com/defenseunicorns/zarf/src/cmd/tools"
"github.com/defenseunicorns/zarf/src/config"
"github.com/defenseunicorns/zarf/src/config/lang"
"github.com/defenseunicorns/zarf/src/pkg/layout"
"github.com/defenseunicorns/zarf/src/pkg/message"
"github.com/defenseunicorns/zarf/src/types"
"github.com/spf13/cobra"
)
var (
// Default global config for the packager
pkgConfig = types.PackagerConfig{}
)
var rootCmd = &cobra.Command{
Use: "zarf COMMAND",
PersistentPreRun: func(cmd *cobra.Command, _ []string) {
// Skip for vendor-only commands
if common.CheckVendorOnlyFromPath(cmd) {
return
}
// Don't log the help command
if cmd.Parent() == nil {
config.SkipLogFile = true
}
common.SetupCLI()
},
Short: lang.RootCmdShort,
Long: lang.RootCmdLong,
Args: cobra.MaximumNArgs(1),
Run: func(cmd *cobra.Command, args []string) {
zarfLogo := message.GetLogo()
_, _ = fmt.Fprintln(os.Stderr, zarfLogo)
cmd.Help()
if len(args) > 0 {
if strings.Contains(args[0], config.ZarfPackagePrefix) || strings.Contains(args[0], "zarf-init") {
message.Warnf(lang.RootCmdDeprecatedDeploy, args[0])
}
if args[0] == layout.ZarfYAML {
message.Warn(lang.RootCmdDeprecatedCreate)
}
}
},
}
// Execute is the entrypoint for the CLI.
func Execute() {
cobra.CheckErr(rootCmd.Execute())
}
func init() {
// Add the tools commands
tools.Include(rootCmd)
// Skip for vendor-only commands
if common.CheckVendorOnlyFromArgs() {
return
}
v := common.InitViper()
rootCmd.PersistentFlags().StringVarP(&common.LogLevelCLI, "log-level", "l", v.GetString(common.VLogLevel), lang.RootCmdFlagLogLevel)
rootCmd.PersistentFlags().StringVarP(&config.CLIArch, "architecture", "a", v.GetString(common.VArchitecture), lang.RootCmdFlagArch)
rootCmd.PersistentFlags().BoolVar(&config.SkipLogFile, "no-log-file", v.GetBool(common.VNoLogFile), lang.RootCmdFlagSkipLogFile)
rootCmd.PersistentFlags().BoolVar(&message.NoProgress, "no-progress", v.GetBool(common.VNoProgress), lang.RootCmdFlagNoProgress)
rootCmd.PersistentFlags().BoolVar(&config.NoColor, "no-color", v.GetBool(common.VNoColor), lang.RootCmdFlagNoColor)
rootCmd.PersistentFlags().StringVar(&config.CommonOptions.CachePath, "zarf-cache", v.GetString(common.VZarfCache), lang.RootCmdFlagCachePath)
rootCmd.PersistentFlags().StringVar(&config.CommonOptions.TempDirectory, "tmpdir", v.GetString(common.VTmpDir), lang.RootCmdFlagTempDir)
rootCmd.PersistentFlags().BoolVar(&config.CommonOptions.Insecure, "insecure", v.GetBool(common.VInsecure), lang.RootCmdFlagInsecure)
}