Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 8 additions & 19 deletions cli/command/container/opts.go
Original file line number Diff line number Diff line change
Expand Up @@ -425,19 +425,12 @@ func parse(flags *pflag.FlagSet, copts *containerOptions, serverOS string) (*con
entrypoint = []string{""}
}

publishOpts := copts.publish.GetSlice()
var (
ports map[container.PortRangeProto]struct{}
portBindings map[container.PortRangeProto][]container.PortBinding
convertedOpts []string
)

convertedOpts, err = convertToStandardNotation(publishOpts)
convertedOpts, err := convertToStandardNotation(copts.publish.GetSlice())
if err != nil {
return nil, err
}

ports, portBindings, err = nat.ParsePortSpecs(convertedOpts)
ports, portBindings, err := nat.ParsePortSpecs(convertedOpts)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -471,23 +464,19 @@ func parse(flags *pflag.FlagSet, copts *containerOptions, serverOS string) (*con
// device path (as opposed to during flag parsing), as at the time we are
// parsing flags, we haven't yet sent a _ping to the daemon to determine
// what operating system it is.
deviceMappings := []container.DeviceMapping{}
var cdiDeviceNames []string
for _, device := range copts.devices.GetSlice() {
var (
validated string
deviceMapping container.DeviceMapping
err error
)
devices := copts.devices.GetSlice()
deviceMappings := make([]container.DeviceMapping, 0, len(devices))
cdiDeviceNames := make([]string, 0, len(devices))
Comment on lines +468 to +469
Copy link

Copilot AI Oct 6, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider using nil initialization for these slices instead of pre-allocating with capacity. Since you're only appending selectively (CDI devices to cdiDeviceNames, validated devices to deviceMappings), the actual usage may be much less than the full capacity, making pre-allocation potentially wasteful.

Suggested change
deviceMappings := make([]container.DeviceMapping, 0, len(devices))
cdiDeviceNames := make([]string, 0, len(devices))
var deviceMappings []container.DeviceMapping
var cdiDeviceNames []string

Copilot uses AI. Check for mistakes.
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LOL; go fight that battle with the linter, CoPilot, I changed it because the linter didn't like your suggestion 😜

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah always have to read through these to understand if the feedback is anything worth actually actioning or not.

for _, device := range devices {
if cdi.IsQualifiedName(device) {
cdiDeviceNames = append(cdiDeviceNames, device)
continue
}
validated, err = validateDevice(device, serverOS)
validated, err := validateDevice(device, serverOS)
if err != nil {
return nil, err
}
deviceMapping, err = parseDevice(validated, serverOS)
deviceMapping, err := parseDevice(validated, serverOS)
if err != nil {
return nil, err
}
Expand Down
Loading