carapace-sh / carapace-bin

multi-shell multi-command argument completer
https://carapace.sh
MIT License
845 stars 46 forks source link

docker rmi: not showing images in Nushell #2255

Closed giggio closed 6 months ago

giggio commented 6 months ago

Current Behavior

docker rmi

show nothing.

Expected Behavior

docker rmi

Shows images available.

Steps To Reproduce

  1. Install carapace and docker
  2. Start nushell or PowerShell Core
  3. build or download a docker image
  4. docker rmi

Version

0.30.1

OS

Shell

Anything else?

I've tested in both Windows and Linux, got the same result.

docker container rm works in every scenario (OS/shell).

rsteube commented 6 months ago

Top level commands like rmi are considered legacy and I removed support for these a while ago.

They can be hidden with DOCKER_HIDE_LEGACY_COMMANDS

When set, Docker hides "legacy" top-level commands (such as docker rm, and docker pull) in docker help output, and only Management commands per object-type (e.g., docker container) are printed. This may become the default in a future release.

The working alternative to rmi is image rm.

giggio commented 6 months ago

I'm aware, is there a way to add them back? I like them, as they are so short, and there is some muscle memory there.

rsteube commented 6 months ago

Since they are just aliases you could override the completion with an overlay:

# yaml-language-server: $schema=https://carapace.sh/schemas/command.json
name: docker
commands:
  - name: rmi
    parsing: disabled
    completion:
      positionalany: ["$carapace.bridge.CarapaceBin([docker, image, remove])"]

But that has some implications as it implicitly enables lenient mode.

What might be better is to define a custom command with run (see user spec):

# yaml-language-server: $schema=https://carapace.sh/schemas/command.json
name: d
commands:
  - name: rmi
    run: "[docker, image, remove]"
rsteube commented 6 months ago

Ah, seems run works fine in overlays as well, so the first one can be simplified:

# yaml-language-server: $schema=https://carapace.sh/schemas/command.json
name: docker
commands:
  - name: rmi
    run: "[docker, image, remove]"
giggio commented 6 months ago

Yes, overlay works fine! Thanks, that helped!

giggio commented 6 months ago

This works for docker rmi, but not for docker run. I checked the logs, it seems to go into a loop, and the terminal locks for more than a minute. This is the config for the overlay:

# yaml-language-server: $schema=https://carapace.sh/schemas/command.json
name: docker
commands:
  - name: rmi
    run: "[docker, image, remove]"
  - name: tag
    run: "[docker, image, tag]"
  - name: run
    run: "[docker, container, run]"
  - name: rm
    run: "[docker, container, remove]"
  - name: logs
    run: "[docker, container, logs]"
  - name: stats
    run: "[docker, container, stats]"
  - name: start
    run: "[docker, container, start]"
  - name: stop
    run: "[docker, container, stop]"
  - name: top
    run: "[docker, container, top]"
  - name: attach
    run: "[docker, container, attach]"

These are the logs for docker container run:

2024/02/20 23:00:04.418689 nushell []string{"carapace", "_carapace", "export", "docker", "container", "run", ""}
2024/02/20 23:00:04.418799 nushell patching args to []string{"export", "docker", "container", "run", ""}
2024/02/20 23:00:04.418809 nushell traverse called for "docker" with args []string{"container", "run", ""}
2024/02/20 23:00:04.418815 nushell executing PreRun for "docker" with args []string{"container", "run", ""}
2024/02/20 23:00:04.418823 nushell allowing unknown flags
2024/02/20 23:00:04.418843 nushell arg "container" is a positional
2024/02/20 23:00:04.418848 nushell arg "run" is a positional
2024/02/20 23:00:04.418871 nushell parsing flags for "docker" with args []string{"container", "run"}
2024/02/20 23:00:04.418878 nushell completing positionals and subcommands for arg ""
{"version":"v0.49.1","messages":[],"nospace":"","usage":"","values":[]}
[{"value":"alpine:","display":"alpine:","style":{"fg":"yellow"}},{"value":"envoyproxy/envoy:","display":"envoyproxy/envoy:","style":{"fg":"yellow"}},{"value":"ghcr.io/rancher-sandbox/rancher-desktop/rdx-proxy:","display":"ghcr.io/rancher-sandbox/rancher-desktop/rdx-proxy:","style":{"fg":"yellow"}},{"value":"giggio/pgbouncer:","display":"giggio/pgbouncer:","style":{"fg":"yellow"}},{"value":"giggio/rinhabackend-2401:","display":"giggio/rinhabackend-2401:","style":{"fg":"yellow"}},{"value":"mcr.microsoft.com/dotnet/runtime-deps:","display":"mcr.microsoft.com/dotnet/runtime-deps:","style":{"fg":"yellow"}},{"value":"mcr.microsoft.com/dotnet/sdk:","display":"mcr.microsoft.com/dotnet/sdk:","style":{"fg":"yellow"}},{"value":"nginx:","display":"nginx:","style":{"fg":"yellow"}},{"value":"pgbouncer:","display":"pgbouncer:","style":{"fg":"yellow"}},{"value":"postgres:","display":"postgres:","style":{"fg":"yellow"}},{"value":"temp:","display":"temp:","style":{"fg":"yellow"}},{"value":"tempinter:","display":"tempinter:","style":{"fg":"yellow"}},{"value":"ubuntu:","display":"ubuntu:","style":{"fg":"yellow"}}]

These are the logs for docker run:

2024/02/20 22:57:58.075582 nushell []string{"/usr/bin/carapace", "_carapace", "export", "docker", "container", "run", ""}
2024/02/20 22:57:58.077068 nushell patching args to []string{"export", "docker", "container", "run", ""}
2024/02/20 22:57:58.077103 nushell traverse called for "" with args []string{"container", "run", ""}
2024/02/20 22:57:58.077107 nushell executing PreRun for "" with args []string{"container", "run", ""}
2024/02/20 22:57:58.077114 nushell allowing unknown flags
2024/02/20 22:57:58.077125 nushell arg "container" is a positional
2024/02/20 22:57:58.077128 nushell arg "run" is a positional
2024/02/20 22:57:58.077145 nushell parsing flags for "" with args []string{"container", "run"}
2024/02/20 22:57:58.077150 nushell completing positionals and subcommands for arg ""
{"version":"v0.49.1","messages":[],"nospace":"","usage":"","values":[]}
{"version":"v0.49.1","messages":[],"nospace":":","usage":"run [OPTIONS] IMAGE [COMMAND] [ARG...]","values":[{"value":"alpine:","display":"alpine:","style":"yellow","tag":"repositories"},{"value":"envoyproxy/envoy:","display":"envoyproxy/envoy:","style":"yellow","tag":"repositories"},{"value":"ghcr.io/rancher-sandbox/rancher-desktop/rdx-proxy:","display":"ghcr.io/rancher-sandbox/rancher-desktop/rdx-proxy:","style":"yellow","tag":"repositories"},{"value":"giggio/pgbouncer:","display":"giggio/pgbouncer:","style":"yellow","tag":"repositories"},{"value":"giggio/rinhabackend-2401:","display":"giggio/rinhabackend-2401:","style":"yellow","tag":"repositories"},{"value":"mcr.microsoft.com/dotnet/runtime-deps:","display":"mcr.microsoft.com/dotnet/runtime-deps:","style":"yellow","tag":"repositories"},{"value":"mcr.microsoft.com/dotnet/sdk:","display":"mcr.microsoft.com/dotnet/sdk:","style":"yellow","tag":"repositories"},{"value":"nginx:","display":"nginx:","style":"yellow","tag":"repositories"},{"value":"pgbouncer:","display":"pgbouncer:","style":"yellow","tag":"repositories"},{"value":"postgres:","display":"postgres:","style":"yellow","tag":"repositories"},{"value":"temp:","display":"temp:","style":"yellow","tag":"repositories"},{"value":"tempinter:","display":"tempinter:","style":"yellow","tag":"repositories"},{"value":"ubuntu:","display":"ubuntu:","style":"yellow","tag":"repositories"}]}

This last line then repeats more than a hundred times.

Any idea of what could be happening?

rsteube commented 6 months ago

Loops are indeed possible in some situations. Not sure what causes it here exactly yet though.

Might be that run is still a top level command and something causing a re-invocation of docker run . That should be an alias though and it's also missing positional completion at the moment.

Need to have a closer look.