@@ -39,6 +39,7 @@ var kongVars = kong.Vars{
3939 "extract_target_dir_help" : `path to extract to. Default extracts to cache.` ,
4040 "checksums_dep_help" : `name of the dependency to update` ,
4141 "trust_cache_help" : `trust the cache contents and do not recheck existing downloads and extracts in the cache` ,
42+ "all_deps_help" : `select all dependencies` ,
4243}
4344
4445type rootCmd struct {
@@ -252,19 +253,37 @@ func (c fmtCmd) Run(ctx *runContext, cli *rootCmd) error {
252253
253254type installCmd struct {
254255 Force bool `kong:"help=${install_force_help}"`
255- Dependency []string `kong:"required=true,arg,help=${download_dependency_help},predictor=bin"`
256+ Dependency []string `kong:"arg,name=dependency,help=${download_dependency_help},predictor=bin"`
257+ All bool `kong:"help=${all_deps_help}"`
256258 TargetFile string `kong:"type=path,name=output,type=file,help=${install_target_file_help}"`
257259 System bindown.System `kong:"name=system,default=${system_default},help=${system_help},predictor=allSystems"`
258260 AllowMissingChecksum bool `kong:"name=allow-missing-checksum,help=${allow_missing_checksum}"`
259261}
260262
263+ func (d * installCmd ) BeforeApply (k * kong.Context ) error {
264+ optionalDependency (k )
265+ return nil
266+ }
267+
261268func (d * installCmd ) Run (ctx * runContext ) error {
262269 config , err := loadConfigFile (ctx , false )
263270 if err != nil {
264271 return err
265272 }
266- if len (d .Dependency ) > 1 && d .TargetFile != "" {
267- return fmt .Errorf ("cannot specify --output when installing multiple dependencies" )
273+ if d .All {
274+ if len (d .Dependency ) > 0 {
275+ return fmt .Errorf ("cannot specify dependencies when using --all" )
276+ }
277+ d .Dependency = allDependencies (config )
278+ }
279+ switch len (d .Dependency ) {
280+ case 0 :
281+ return fmt .Errorf ("must specify at least one dependency" )
282+ case 1 :
283+ default :
284+ if d .TargetFile != "" {
285+ return fmt .Errorf ("cannot specify --output when installing multiple dependencies" )
286+ }
268287 }
269288 for _ , dep := range d .Dependency {
270289 var pth string
@@ -284,15 +303,30 @@ func (d *installCmd) Run(ctx *runContext) error {
284303type downloadCmd struct {
285304 Force bool `kong:"help=${download_force_help}"`
286305 System bindown.System `kong:"name=system,default=${system_default},help=${system_help},predictor=allSystems"`
287- Dependency []string `kong:"required=true,arg,help=${download_dependency_help},predictor=bin"`
306+ Dependency []string `kong:"arg,help=${download_dependency_help},predictor=bin"`
307+ All bool `kong:"help=${all_deps_help}"`
288308 AllowMissingChecksum bool `kong:"name=allow-missing-checksum,help=${allow_missing_checksum}"`
289309}
290310
311+ func (d * downloadCmd ) BeforeApply (k * kong.Context ) error {
312+ optionalDependency (k )
313+ return nil
314+ }
315+
291316func (d * downloadCmd ) Run (ctx * runContext ) error {
292317 config , err := loadConfigFile (ctx , false )
293318 if err != nil {
294319 return err
295320 }
321+ if d .All {
322+ if len (d .Dependency ) > 0 {
323+ return fmt .Errorf ("cannot specify dependencies when using --all" )
324+ }
325+ d .Dependency = allDependencies (config )
326+ }
327+ if len (d .Dependency ) == 0 {
328+ return fmt .Errorf ("must specify at least one dependency" )
329+ }
296330 for _ , dep := range d .Dependency {
297331 var pth string
298332 pth , err = config .DownloadDependency (dep , d .System , & bindown.ConfigDownloadDependencyOpts {
@@ -309,15 +343,30 @@ func (d *downloadCmd) Run(ctx *runContext) error {
309343
310344type extractCmd struct {
311345 System bindown.System `kong:"name=system,default=${system_default},help=${system_help},predictor=allSystems"`
312- Dependency []string `kong:"required=true,arg,help=${extract_dependency_help},predictor=bin"`
346+ Dependency []string `kong:"arg,help=${extract_dependency_help},predictor=bin"`
347+ All bool `kong:"help=${all_deps_help}"`
313348 AllowMissingChecksum bool `kong:"name=allow-missing-checksum,help=${allow_missing_checksum}"`
314349}
315350
351+ func (d * extractCmd ) BeforeApply (k * kong.Context ) error {
352+ optionalDependency (k )
353+ return nil
354+ }
355+
316356func (d * extractCmd ) Run (ctx * runContext ) error {
317357 config , err := loadConfigFile (ctx , false )
318358 if err != nil {
319359 return err
320360 }
361+ if d .All {
362+ if len (d .Dependency ) > 0 {
363+ return fmt .Errorf ("cannot specify dependencies when using --all" )
364+ }
365+ d .Dependency = allDependencies (config )
366+ }
367+ if len (d .Dependency ) == 0 {
368+ return fmt .Errorf ("must specify at least one dependency" )
369+ }
321370 for _ , dep := range d .Dependency {
322371 var pth string
323372 pth , err = config .ExtractDependency (dep , d .System , & bindown.ConfigExtractDependencyOpts {
@@ -330,3 +379,13 @@ func (d *extractCmd) Run(ctx *runContext) error {
330379 }
331380 return nil
332381}
382+
383+ // optionalDependency sets dependency positional to optional. We do this because we want to allow --all to be
384+ // equivalent to specifying all dependencies but want the help output to indicate that a dependency is required.
385+ func optionalDependency (k * kong.Context ) {
386+ for _ , pos := range k .Selected ().Positional {
387+ if pos .Name == "dependency" {
388+ pos .Required = false
389+ }
390+ }
391+ }
0 commit comments