1
1
package cli
2
2
3
3
import (
4
- "errors"
5
4
"flag"
6
5
"fmt"
7
6
"net/url"
@@ -15,7 +14,7 @@ import (
15
14
"github.com/peterbourgon/ff/v3"
16
15
)
17
16
18
- func validateFlags (flags * types.CliFlags ) error {
17
+ func ValidateFlags (flags * types.CliFlags ) error {
19
18
if ! utils .IsSupportedPlatformArch (flags .Platform , flags .Architecture ) {
20
19
return fmt .Errorf (
21
20
"invalid combination of platform+architecture detected: %s+%s" ,
@@ -30,8 +29,6 @@ func validateFlags(flags *types.CliFlags) error {
30
29
}
31
30
if manifestURL .Scheme == "https" {
32
31
flags .ManifestURL = true
33
- } else if len (flags .ExecCommand ) == 0 {
34
- return errors .New ("invalid path/url to manifest file" )
35
32
}
36
33
}
37
34
if info , err := os .Stat (flags .DownloadPath ); ! (err == nil && info .IsDir ()) {
@@ -47,38 +44,12 @@ func validateFlags(flags *types.CliFlags) error {
47
44
// with useful values set after parsing the same.
48
45
func GetCliFlags (buildFlags types.BuildFlags ) (types.CliFlags , error ) {
49
46
cliFlags := types.CliFlags {}
50
- args := []string {}
51
- // Handle post-exec string
52
- for i , arg := range os .Args [1 :] {
53
- if arg == "--" {
54
- cliFlags .ExecCommand = os .Args [i + 2 :]
55
- break
56
- }
57
- args = append (args , arg )
58
- }
47
+
59
48
flag .Set ("logtostderr" , "true" )
60
49
vFlag := flag .Lookup ("v" )
61
50
fs := flag .NewFlagSet (constants .AppName , flag .ExitOnError )
62
51
63
- goos := runtime .GOOS
64
- if os .Getenv ("GOOS" ) != "" {
65
- goos = os .Getenv ("GOOS" )
66
- }
67
-
68
- goarch := runtime .GOARCH
69
- if os .Getenv ("GOARCH" ) != "" {
70
- goarch = os .Getenv ("GOARCH" )
71
- }
72
-
73
- fs .StringVar (& cliFlags .Verbosity , "v" , "3" , "Log verbosity. Integer value from 0 to 9" )
74
- fs .StringVar (& cliFlags .Platform , "platform" , goos , "One of linux/windows/darwin" )
75
- fs .StringVar (& cliFlags .Architecture , "architecture" , goarch , "System architecture (amd64/arm64)" )
76
- fs .StringVar (& cliFlags .DownloadPath , "path" , fmt .Sprintf (".%sbin" , string (os .PathSeparator )), "Path to store binaries" )
77
- fs .StringVar (& cliFlags .ManifestFile , "manifest" , "manifest.yaml" , "Path (or URL) to manifest yaml file" )
78
- fs .BoolVar (& cliFlags .SkipDownloaded , "skip-downloaded" , false , "Skip already downloaded archive (if found)" )
79
- fs .BoolVar (& cliFlags .Cleanup , "cleanup" , true , "Cleanup downloaded archives after extraction" )
80
- fs .BoolVar (& cliFlags .UpdateManifest , "update-manifest" , false , "Update the manifest file commit shas from releases prior to downloading" )
81
- fs .BoolVar (& cliFlags .Download , "download" , true , "Actually do a download. Only useful for -update-manifest=true -download=false" )
52
+ AddDownloaderFlags (fs , & cliFlags )
82
53
83
54
version := fs .Bool ("version" , false , "Get version information" )
84
55
@@ -88,18 +59,40 @@ func GetCliFlags(buildFlags types.BuildFlags) (types.CliFlags, error) {
88
59
}
89
60
90
61
ff .Parse (
91
- fs , args ,
92
- ff .WithConfigFileFlag ("config" ),
62
+ fs , os .Args [1 :],
93
63
ff .WithConfigFileParser (ff .PlainParser ),
94
64
ff .WithEnvVarPrefix ("CATALYST_DOWNLOADER" ),
95
65
ff .WithEnvVarSplit ("," ),
96
66
)
97
67
flag .CommandLine .Parse (nil )
98
68
vFlag .Value .Set (cliFlags .Verbosity )
99
69
100
- err := validateFlags (& cliFlags )
70
+ err := ValidateFlags (& cliFlags )
101
71
if err != nil {
102
72
glog .Fatal (err )
103
73
}
104
74
return cliFlags , err
105
75
}
76
+
77
+ // Populate a provided flagset with downloader flags
78
+ func AddDownloaderFlags (fs * flag.FlagSet , cliFlags * types.CliFlags ) {
79
+ goos := runtime .GOOS
80
+ if os .Getenv ("GOOS" ) != "" {
81
+ goos = os .Getenv ("GOOS" )
82
+ }
83
+
84
+ goarch := runtime .GOARCH
85
+ if os .Getenv ("GOARCH" ) != "" {
86
+ goarch = os .Getenv ("GOARCH" )
87
+ }
88
+
89
+ fs .StringVar (& cliFlags .Verbosity , "v" , "3" , "Log verbosity. Integer value from 0 to 9" )
90
+ fs .StringVar (& cliFlags .Platform , "platform" , goos , "One of linux/windows/darwin" )
91
+ fs .StringVar (& cliFlags .Architecture , "architecture" , goarch , "System architecture (amd64/arm64)" )
92
+ fs .StringVar (& cliFlags .DownloadPath , "path" , fmt .Sprintf (".%sbin" , string (os .PathSeparator )), "Path to store binaries" )
93
+ fs .StringVar (& cliFlags .ManifestFile , "manifest" , "manifest.yaml" , "Path (or URL) to manifest yaml file" )
94
+ fs .BoolVar (& cliFlags .SkipDownloaded , "skip-downloaded" , false , "Skip already downloaded archive (if found)" )
95
+ fs .BoolVar (& cliFlags .Cleanup , "cleanup" , true , "Cleanup downloaded archives after extraction" )
96
+ fs .BoolVar (& cliFlags .UpdateManifest , "update-manifest" , false , "Update the manifest file commit shas from releases prior to downloading" )
97
+ fs .BoolVar (& cliFlags .Download , "download" , true , "Actually do a download. Only useful for -update-manifest=true -download=false" )
98
+ }
0 commit comments