mirror of
https://github.com/podman-container-tools/podman.git
synced 2026-08-26 18:27:53 +00:00
Allow automatic generation for shell completion scripts with the internal cobra functions (requires v1.0.0+). This should replace the handwritten completion scripts and even adds support for fish. With this approach it is less likley that completions and code are out of sync. We can now create the scripts with - podman completion bash - podman completion zsh - podman completion fish To test the completion run: source <(podman completion bash) The same works for podman-remote and podman --remote and it will complete your remote containers/images with the correct endpoints values from --url/--connection. The completion logic is written in go and provided by the cobra library. The completion functions lives in `cmd/podman/completion/completion.go`. The unit test at cmd/podman/shell_completion_test.go checks if each command and flag has an autocompletion function set. This prevents that commands and flags have no shell completion set. This commit does not replace the current autocompletion scripts. Closes #6440 Signed-off-by: Paul Holzinger <paul.holzinger@web.de>
73 lines
2.2 KiB
Go
73 lines
2.2 KiB
Go
package images
|
|
|
|
import (
|
|
"fmt"
|
|
|
|
"github.com/containers/podman/v2/cmd/podman/common"
|
|
"github.com/containers/podman/v2/cmd/podman/registry"
|
|
"github.com/containers/podman/v2/cmd/podman/utils"
|
|
"github.com/containers/podman/v2/pkg/domain/entities"
|
|
"github.com/pkg/errors"
|
|
"github.com/spf13/cobra"
|
|
"github.com/spf13/pflag"
|
|
)
|
|
|
|
var (
|
|
description = `Image storage increments a mount counter each time an image is mounted.
|
|
|
|
When an image is unmounted, the mount counter is decremented. The image's root filesystem is physically unmounted only when the mount counter reaches zero indicating no other processes are using the mount.
|
|
|
|
An unmount can be forced with the --force flag.
|
|
`
|
|
unmountCommand = &cobra.Command{
|
|
Use: "unmount [options] IMAGE [IMAGE...]",
|
|
Aliases: []string{"umount"},
|
|
Short: "Unmount an image's root filesystem",
|
|
Long: description,
|
|
RunE: unmount,
|
|
ValidArgsFunction: common.AutocompleteImages,
|
|
Example: `podman unmount imgID
|
|
podman unmount imgID1 imgID2 imgID3
|
|
podman unmount --all`,
|
|
}
|
|
)
|
|
|
|
var (
|
|
unmountOpts entities.ImageUnmountOptions
|
|
)
|
|
|
|
func unmountFlags(flags *pflag.FlagSet) {
|
|
flags.BoolVarP(&unmountOpts.All, "all", "a", false, "Unmount all of the currently mounted images")
|
|
flags.BoolVarP(&unmountOpts.Force, "force", "f", false, "Force the complete unmount of the specified mounted images")
|
|
}
|
|
|
|
func init() {
|
|
registry.Commands = append(registry.Commands, registry.CliCommand{
|
|
Mode: []entities.EngineMode{entities.ABIMode},
|
|
Parent: imageCmd,
|
|
Command: unmountCommand,
|
|
})
|
|
unmountFlags(unmountCommand.Flags())
|
|
}
|
|
|
|
func unmount(cmd *cobra.Command, args []string) error {
|
|
var errs utils.OutputErrors
|
|
if len(args) < 1 && !unmountOpts.All {
|
|
return errors.New("image name or ID must be specified")
|
|
}
|
|
if len(args) > 0 && unmountOpts.All {
|
|
return errors.New("when using the --all switch, you may not pass any image names or IDs")
|
|
}
|
|
reports, err := registry.ImageEngine().Unmount(registry.GetContext(), args, unmountOpts)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
for _, r := range reports {
|
|
if r.Err == nil {
|
|
fmt.Println(r.Id)
|
|
} else {
|
|
errs = append(errs, r.Err)
|
|
}
|
|
}
|
|
return errs.PrintErrors()
|
|
}
|