@@ -85,6 +85,10 @@ Examples:
8585 Name : "memory" ,
8686 Usage : "Memory limit for builder VM in MB (default 2048)" ,
8787 },
88+ & cli.StringSliceFlag {
89+ Name : "tag" ,
90+ Usage : "Set build tag key-value pair (KEY=VALUE, can be repeated)" ,
91+ },
8892 },
8993 Commands : []* cli.Command {
9094 & buildListCmd ,
@@ -186,6 +190,17 @@ func handleBuild(ctx context.Context, cmd *cli.Command) error {
186190 if cmd .IsSet ("memory" ) {
187191 params .MemoryMB = hypeman .Opt (int64 (cmd .Int ("memory" )))
188192 }
193+ tags , malformedTags := parseKeyValueSpecs (cmd .StringSlice ("tag" ))
194+ for _ , malformed := range malformedTags {
195+ fmt .Fprintf (os .Stderr , "Warning: ignoring malformed tag: %s\n " , malformed )
196+ }
197+ if len (tags ) > 0 {
198+ tagsJSON , err := marshalStringMap (tags )
199+ if err != nil {
200+ return fmt .Errorf ("failed to encode tags: %w" , err )
201+ }
202+ params .Tags = hypeman .Opt (tagsJSON )
203+ }
189204
190205 // Start build
191206 build , err := client .Builds .New (ctx , params , opts ... )
@@ -359,24 +374,28 @@ var buildListCmd = cli.Command{
359374 Aliases : []string {"q" },
360375 Usage : "Only display build IDs" ,
361376 },
377+ & cli.StringSliceFlag {
378+ Name : "tag" ,
379+ Usage : "Filter by tag key-value pair (KEY=VALUE, can be repeated)" ,
380+ },
362381 },
363382 Action : handleBuildList ,
364383 HideHelpCommand : true ,
365384}
366385
367386var buildGetCmd = cli.Command {
368- Name : "get" ,
369- Usage : "Get build details" ,
370- ArgsUsage : "<id>" ,
371- Action : handleBuildGet ,
387+ Name : "get" ,
388+ Usage : "Get build details" ,
389+ ArgsUsage : "<id>" ,
390+ Action : handleBuildGet ,
372391 HideHelpCommand : true ,
373392}
374393
375394var buildCancelCmd = cli.Command {
376- Name : "cancel" ,
377- Usage : "Cancel a build" ,
378- ArgsUsage : "<id>" ,
379- Action : handleBuildCancel ,
395+ Name : "cancel" ,
396+ Usage : "Cancel a build" ,
397+ ArgsUsage : "<id>" ,
398+ Action : handleBuildCancel ,
380399 HideHelpCommand : true ,
381400}
382401
@@ -390,19 +409,27 @@ func handleBuildList(ctx context.Context, cmd *cli.Command) error {
390409
391410 format := cmd .Root ().String ("format" )
392411 transform := cmd .Root ().String ("transform" )
412+ params := hypeman.BuildListParams {}
413+ tags , malformedTags := parseKeyValueSpecs (cmd .StringSlice ("tag" ))
414+ for _ , malformed := range malformedTags {
415+ fmt .Fprintf (os .Stderr , "Warning: ignoring malformed tag filter: %s\n " , malformed )
416+ }
417+ if len (tags ) > 0 {
418+ params .Tags = tags
419+ }
393420
394421 if format != "auto" {
395422 var res []byte
396423 opts = append (opts , option .WithResponseBodyInto (& res ))
397- _ , err := client .Builds .List (ctx , opts ... )
424+ _ , err := client .Builds .List (ctx , params , opts ... )
398425 if err != nil {
399426 return err
400427 }
401428 obj := gjson .ParseBytes (res )
402429 return ShowJSON (os .Stdout , "build list" , obj , format , transform )
403430 }
404431
405- builds , err := client .Builds .List (ctx , opts ... )
432+ builds , err := client .Builds .List (ctx , params , opts ... )
406433 if err != nil {
407434 return err
408435 }
0 commit comments