@@ -430,6 +430,77 @@ func PrepareArtifacts(artifactsSlice []string) (ArtifactsConfig, error) {
430430 return artifacts , nil
431431}
432432
433+ // parseFileCaptureSubOption parses file capture sub-options in the format '<sub-opt>=<value>'.
434+ // This is shared logic between the legacy capture flag and the new artifacts flag.
435+ func parseFileCaptureSubOption (option string , captureConfig * config.FileCaptureConfig ) error {
436+ optAndValue := strings .SplitN (option , "=" , 2 )
437+ if len (optAndValue ) != 2 || len (optAndValue [1 ]) == 0 {
438+ return errfmt .Errorf ("invalid file capture option format: %s" , option )
439+ }
440+ opt := optAndValue [0 ]
441+ value := optAndValue [1 ]
442+ switch opt {
443+ case "path" :
444+ if ! strings .HasSuffix (option , "*" ) {
445+ return errfmt .Errorf ("file path filter should end with *" )
446+ }
447+ pathPrefix := strings .TrimSuffix (value , "*" )
448+ if len (pathPrefix ) == 0 {
449+ return errfmt .Errorf ("capture path filter cannot be empty" )
450+ }
451+ captureConfig .PathFilter = append (captureConfig .PathFilter , pathPrefix )
452+ case "type" :
453+ typeFilter := strings .TrimPrefix (option , "type=" )
454+ filterFlag , err := parseFileCaptureType (typeFilter )
455+ if err != nil {
456+ return err
457+ }
458+ captureConfig .TypeFilter |= filterFlag
459+ case "fd" :
460+ typeFilter := strings .TrimPrefix (option , "fd=" )
461+ filterFlag , err := parseFileCaptureFDs (typeFilter )
462+ if err != nil {
463+ return err
464+ }
465+ captureConfig .TypeFilter |= filterFlag
466+ default :
467+ return errfmt .Errorf ("unrecognized file capture option: %s" , opt )
468+ }
469+
470+ return nil
471+ }
472+
473+ var captureFileTypeStringToFlag = map [string ]config.FileCaptureType {
474+ "pipe" : config .CapturePipeFiles ,
475+ "socket" : config .CaptureSocketFiles ,
476+ "regular" : config .CaptureRegularFiles ,
477+ "elf" : config .CaptureELFFiles ,
478+ }
479+
480+ // parseFileCaptureType parses file type string to its matching bit-flag value.
481+ func parseFileCaptureType (filter string ) (config.FileCaptureType , error ) {
482+ filterFlag , ok := captureFileTypeStringToFlag [filter ]
483+ if ok {
484+ return filterFlag , nil
485+ }
486+ return 0 , errfmt .Errorf ("unsupported file type filter value for capture - %s" , filter )
487+ }
488+
489+ var captureFDsStringToFlag = map [string ]config.FileCaptureType {
490+ "stdin" : config .CaptureStdinFiles ,
491+ "stdout" : config .CaptureStdoutFiles ,
492+ "stderr" : config .CaptureStderrFiles ,
493+ }
494+
495+ // parseFileCaptureFDs parses file standard FD string to its matching bit-flag value.
496+ func parseFileCaptureFDs (filter string ) (config.FileCaptureType , error ) {
497+ filterFlag , ok := captureFDsStringToFlag [filter ]
498+ if ok {
499+ return filterFlag , nil
500+ }
501+ return 0 , errfmt .Errorf ("unsupported file FD filter value for capture - %s" , filter )
502+ }
503+
433504// parseFileArtifactOptionWrite parses file-write artifact options.
434505func parseFileArtifactOptionWrite (fileConfig * FileWriteConfig , subOpt string ) error {
435506 if strings .HasPrefix (subOpt , filtersKey + "=" ) {
0 commit comments