-
Notifications
You must be signed in to change notification settings - Fork 157
/
vendor.go
65 lines (55 loc) · 1.32 KB
/
vendor.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
// SPDX-License-Identifier: Apache-2.0
// SPDX-FileCopyrightText: 2021-Present The Zarf Authors
// Package common handles command configuration across all commands
package common
import (
"os"
"strings"
"slices"
"github.com/defenseunicorns/zarf/src/config"
"github.com/spf13/cobra"
)
var vendorCmds = []string{
"kubectl",
"k",
"syft",
"sbom",
"s",
"k9s",
"monitor",
"m",
"wait-for",
"wait",
"w",
"crane",
"registry",
"r",
"helm",
"h",
"yq",
}
// CheckVendorOnlyFromArgs checks if the command being run is a vendor-only command
func CheckVendorOnlyFromArgs() bool {
// Check for "zarf tools|t <cmd>" where <cmd> is in the vendorCmd list
return IsVendorCmd(os.Args, vendorCmds)
}
// CheckVendorOnlyFromPath checks if the cobra command is a vendor-only command
func CheckVendorOnlyFromPath(cmd *cobra.Command) bool {
args := strings.Split(cmd.CommandPath(), " ")
// Check for "zarf tools|t <cmd>" where <cmd> is in the vendorCmd list
return IsVendorCmd(args, vendorCmds)
}
// IsVendorCmd checks if the command is a vendor command.
func IsVendorCmd(args []string, vendoredCmds []string) bool {
if config.ActionsCommandZarfPrefix != "" {
args = args[1:]
}
if len(args) > 2 {
if args[1] == "tools" || args[1] == "t" {
if slices.Contains(vendoredCmds, args[2]) {
return true
}
}
}
return false
}