2023-04-24 17:41:10 +08:00
|
|
|
package buildflags
|
|
|
|
|
|
|
|
import (
|
2024-04-13 08:36:49 +08:00
|
|
|
"strconv"
|
2023-04-24 17:41:10 +08:00
|
|
|
"strings"
|
|
|
|
|
|
|
|
controllerapi "github.com/docker/buildx/controller/pb"
|
|
|
|
"github.com/pkg/errors"
|
2024-06-28 11:31:23 +08:00
|
|
|
"github.com/tonistiigi/go-csvvalue"
|
2023-04-24 17:41:10 +08:00
|
|
|
)
|
|
|
|
|
2024-08-13 20:13:32 +08:00
|
|
|
const defaultCallFunc = "build"
|
2024-06-04 01:29:40 +08:00
|
|
|
|
2024-08-13 20:13:32 +08:00
|
|
|
func ParseCallFunc(str string) (*controllerapi.CallFunc, error) {
|
2024-06-04 03:09:40 +08:00
|
|
|
if str == "" {
|
2023-04-24 17:41:10 +08:00
|
|
|
return nil, nil
|
|
|
|
}
|
2024-05-31 04:41:04 +08:00
|
|
|
|
2024-06-28 11:31:23 +08:00
|
|
|
fields, err := csvvalue.Fields(str, nil)
|
2023-04-24 17:41:10 +08:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
2024-08-13 20:13:32 +08:00
|
|
|
f := &controllerapi.CallFunc{}
|
2023-04-24 17:41:10 +08:00
|
|
|
for _, field := range fields {
|
|
|
|
parts := strings.SplitN(field, "=", 2)
|
|
|
|
if len(parts) == 2 {
|
2024-04-13 08:36:49 +08:00
|
|
|
switch parts[0] {
|
|
|
|
case "format":
|
2023-04-24 17:41:10 +08:00
|
|
|
f.Format = parts[1]
|
2024-04-13 08:36:49 +08:00
|
|
|
case "ignorestatus":
|
|
|
|
v, err := strconv.ParseBool(parts[1])
|
|
|
|
if err != nil {
|
|
|
|
return nil, errors.Wrapf(err, "invalid ignorestatus print value: %s", parts[1])
|
|
|
|
}
|
|
|
|
f.IgnoreStatus = v
|
|
|
|
default:
|
2023-04-24 17:41:10 +08:00
|
|
|
return nil, errors.Errorf("invalid print field: %s", field)
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if f.Name != "" {
|
|
|
|
return nil, errors.Errorf("invalid print value: %s", str)
|
|
|
|
}
|
|
|
|
f.Name = field
|
|
|
|
}
|
|
|
|
}
|
2024-06-04 03:09:40 +08:00
|
|
|
|
|
|
|
// "check" has been added as an alias for "lint",
|
|
|
|
// in order to maintain backwards compatibility
|
|
|
|
// we need to convert it.
|
|
|
|
if f.Name == "check" {
|
|
|
|
f.Name = "lint"
|
|
|
|
}
|
|
|
|
|
2024-08-13 20:13:32 +08:00
|
|
|
if f.Name == defaultCallFunc {
|
2024-06-04 03:09:40 +08:00
|
|
|
return nil, nil
|
|
|
|
}
|
|
|
|
|
2023-04-24 17:41:10 +08:00
|
|
|
return f, nil
|
|
|
|
}
|