Skip to content
This repository was archived by the owner on Nov 27, 2023. It is now read-only.
Merged
Show file tree
Hide file tree
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
2 changes: 2 additions & 0 deletions cli/metrics/commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ var commandFlags = []string{
// Generated with generatecommands/main.go
var managementCommands = []string{
"help",
"alpha",
"app",
"builder",
"buildx",
Expand Down Expand Up @@ -157,4 +158,5 @@ var commands = []string{
"validate",
"version",
"wait",
"watch",
}
33 changes: 6 additions & 27 deletions cli/metrics/docker_command.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,11 @@ func NewDockerCLIEvent(cmd CmdResult) *DockerCLIEvent {
subcommand = strings.Join(subcommandParts, "-")
}

cmdOrPlugin := cmdPath[1]
if cmdOrPlugin.plugin && subcommand == "" {
return nil
}

var usage bool
for _, arg := range cmd.Args {
// TODO(milas): also support `docker help build` syntax
Expand All @@ -81,7 +86,7 @@ func NewDockerCLIEvent(cmd CmdResult) *DockerCLIEvent {
}

event := &DockerCLIEvent{
Command: cmdPath[1].name,
Command: cmdOrPlugin.name,
Subcommand: subcommand,
ExitCode: int32(cmd.ExitCode),
Usage: usage,
Expand Down Expand Up @@ -161,32 +166,6 @@ var cmdHierarchy = &cmdNode{
{name: "dryrun"},
},
},
{name: "build"},
{name: "config"},
{name: "convert"},
{name: "cp"},
{name: "create"},
{name: "down"},
{name: "events"},
{name: "exec"},
{name: "images"},
{name: "kill"},
{name: "logs"},
{name: "ls"},
{name: "pause"},
{name: "port"},
{name: "ps"},
{name: "pull"},
{name: "push"},
{name: "restart"},
{name: "rm"},
{name: "run"},
{name: "start"},
{name: "stop"},
{name: "top"},
{name: "unpause"},
{name: "up"},
{name: "version"},
},
},
},
Expand Down
19 changes: 12 additions & 7 deletions cli/metrics/docker_command_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,30 +43,35 @@ func TestCmdCompose(t *testing.T) {
{
name: "Compose - Base",
input: "docker compose",
expected: &DockerCLIEvent{Command: "compose"},
expected: nil,
},
{
name: "Compose - Ignored",
input: "docker compose up",
expected: nil,
},
{
name: "Compose - Root Args",
input: "docker --host 127.0.0.1 --debug=true compose ls",
input: "docker --host 127.0.0.1 --debug=true compose alpha watch",
expected: &DockerCLIEvent{
Command: "compose",
Subcommand: "ls",
Subcommand: "alpha-watch",
},
},
{
name: "Compose - Base Args",
input: "docker compose -p myproject build myservice",
input: "docker compose -p myproject alpha watch myservice",
expected: &DockerCLIEvent{
Command: "compose",
Subcommand: "build",
Subcommand: "alpha-watch",
},
},
{
name: "Compose - Usage",
input: "docker compose --file=mycompose.yaml up --help myservice",
input: "docker compose --file=mycompose.yaml alpha watch --help myservice",
expected: &DockerCLIEvent{
Command: "compose",
Subcommand: "up",
Subcommand: "alpha-watch",
Usage: true,
},
},
Expand Down