mirror of https://github.com/containers/podman.git
Merge pull request #14330 from Luap99/completion3
cmd/podman/common/completion.go: fix FIXMEs
This commit is contained in:
commit
0f5c06dac5
|
@ -7,6 +7,7 @@ import (
|
||||||
"reflect"
|
"reflect"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
|
"unicode"
|
||||||
|
|
||||||
libimageDefine "github.com/containers/common/libimage/define"
|
libimageDefine "github.com/containers/common/libimage/define"
|
||||||
"github.com/containers/common/libnetwork/types"
|
"github.com/containers/common/libnetwork/types"
|
||||||
|
@ -17,6 +18,7 @@ import (
|
||||||
"github.com/containers/podman/v4/libpod/events"
|
"github.com/containers/podman/v4/libpod/events"
|
||||||
"github.com/containers/podman/v4/pkg/domain/entities"
|
"github.com/containers/podman/v4/pkg/domain/entities"
|
||||||
"github.com/containers/podman/v4/pkg/rootless"
|
"github.com/containers/podman/v4/pkg/rootless"
|
||||||
|
"github.com/containers/podman/v4/pkg/signal"
|
||||||
systemdDefine "github.com/containers/podman/v4/pkg/systemd/define"
|
systemdDefine "github.com/containers/podman/v4/pkg/systemd/define"
|
||||||
"github.com/containers/podman/v4/pkg/util"
|
"github.com/containers/podman/v4/pkg/util"
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
|
@ -601,7 +603,9 @@ func AutocompleteRunlabelCommand(cmd *cobra.Command, args []string, toComplete s
|
||||||
return nil, cobra.ShellCompDirectiveNoFileComp
|
return nil, cobra.ShellCompDirectiveNoFileComp
|
||||||
}
|
}
|
||||||
if len(args) == 0 {
|
if len(args) == 0 {
|
||||||
// FIXME: What labels can we recommend here?
|
// This is unfortunate because the argument order is label followed by image.
|
||||||
|
// If it would be the other way around we could inspect the first arg and get
|
||||||
|
// all labels from it to suggest them.
|
||||||
return nil, cobra.ShellCompDirectiveNoFileComp
|
return nil, cobra.ShellCompDirectiveNoFileComp
|
||||||
}
|
}
|
||||||
if len(args) == 1 {
|
if len(args) == 1 {
|
||||||
|
@ -806,8 +810,7 @@ func AutocompleteLogDriver(cmd *cobra.Command, args []string, toComplete string)
|
||||||
// AutocompleteLogOpt - Autocomplete log-opt options.
|
// AutocompleteLogOpt - Autocomplete log-opt options.
|
||||||
// -> "path=", "tag="
|
// -> "path=", "tag="
|
||||||
func AutocompleteLogOpt(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
|
func AutocompleteLogOpt(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
|
||||||
// FIXME: are these the only one? the man page states these but in the current shell completion they are more options
|
logOptions := []string{"path=", "tag=", "max-size="}
|
||||||
logOptions := []string{"path=", "tag="}
|
|
||||||
if strings.HasPrefix(toComplete, "path=") {
|
if strings.HasPrefix(toComplete, "path=") {
|
||||||
return nil, cobra.ShellCompDirectiveDefault
|
return nil, cobra.ShellCompDirectiveDefault
|
||||||
}
|
}
|
||||||
|
@ -846,10 +849,26 @@ func AutocompleteSecurityOption(cmd *cobra.Command, args []string, toComplete st
|
||||||
}
|
}
|
||||||
|
|
||||||
// AutocompleteStopSignal - Autocomplete stop signal options.
|
// AutocompleteStopSignal - Autocomplete stop signal options.
|
||||||
// -> "SIGHUP", "SIGINT", "SIGKILL", "SIGTERM"
|
// Autocompletes signals both lower or uppercase depending on the user input.
|
||||||
func AutocompleteStopSignal(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
|
func AutocompleteStopSignal(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
|
||||||
// FIXME: add more/different signals?
|
// convertCase will convert a string to lowercase only if the user input is lowercase
|
||||||
stopSignals := []string{"SIGHUP", "SIGINT", "SIGKILL", "SIGTERM"}
|
convertCase := func(s string) string { return s }
|
||||||
|
if len(toComplete) > 0 && unicode.IsLower(rune(toComplete[0])) {
|
||||||
|
convertCase = strings.ToLower
|
||||||
|
}
|
||||||
|
|
||||||
|
prefix := ""
|
||||||
|
// if input starts with "SI" we have to add SIG in front
|
||||||
|
// since the signal map does not have this prefix but the option
|
||||||
|
// allows signals with and without SIG prefix
|
||||||
|
if strings.HasPrefix(toComplete, convertCase("SI")) {
|
||||||
|
prefix = "SIG"
|
||||||
|
}
|
||||||
|
|
||||||
|
stopSignals := make([]string, 0, len(signal.SignalMap))
|
||||||
|
for sig := range signal.SignalMap {
|
||||||
|
stopSignals = append(stopSignals, convertCase(prefix+sig))
|
||||||
|
}
|
||||||
return stopSignals, cobra.ShellCompDirectiveNoFileComp
|
return stopSignals, cobra.ShellCompDirectiveNoFileComp
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -17,7 +17,7 @@ func ParseSignal(rawSignal string) (syscall.Signal, error) {
|
||||||
}
|
}
|
||||||
return syscall.Signal(s), nil
|
return syscall.Signal(s), nil
|
||||||
}
|
}
|
||||||
sig, ok := signalMap[strings.TrimPrefix(strings.ToUpper(rawSignal), "SIG")]
|
sig, ok := SignalMap[strings.TrimPrefix(strings.ToUpper(rawSignal), "SIG")]
|
||||||
if !ok {
|
if !ok {
|
||||||
return -1, fmt.Errorf("invalid signal: %s", rawSignal)
|
return -1, fmt.Errorf("invalid signal: %s", rawSignal)
|
||||||
}
|
}
|
||||||
|
@ -32,7 +32,7 @@ func ParseSignalNameOrNumber(rawSignal string) (syscall.Signal, error) {
|
||||||
if err == nil {
|
if err == nil {
|
||||||
return s, nil
|
return s, nil
|
||||||
}
|
}
|
||||||
for k, v := range signalMap {
|
for k, v := range SignalMap {
|
||||||
if k == strings.ToUpper(basename) {
|
if k == strings.ToUpper(basename) {
|
||||||
return v, nil
|
return v, nil
|
||||||
}
|
}
|
||||||
|
|
|
@ -23,8 +23,8 @@ const (
|
||||||
SIGWINCH = syscall.SIGWINCH // For cross-compilation with Windows
|
SIGWINCH = syscall.SIGWINCH // For cross-compilation with Windows
|
||||||
)
|
)
|
||||||
|
|
||||||
// signalMap is a map of Linux signals.
|
// SignalMap is a map of Linux signals.
|
||||||
var signalMap = map[string]syscall.Signal{
|
var SignalMap = map[string]syscall.Signal{
|
||||||
"ABRT": unix.SIGABRT,
|
"ABRT": unix.SIGABRT,
|
||||||
"ALRM": unix.SIGALRM,
|
"ALRM": unix.SIGALRM,
|
||||||
"BUS": unix.SIGBUS,
|
"BUS": unix.SIGBUS,
|
||||||
|
@ -94,8 +94,8 @@ var signalMap = map[string]syscall.Signal{
|
||||||
|
|
||||||
// CatchAll catches all signals and relays them to the specified channel.
|
// CatchAll catches all signals and relays them to the specified channel.
|
||||||
func CatchAll(sigc chan os.Signal) {
|
func CatchAll(sigc chan os.Signal) {
|
||||||
handledSigs := make([]os.Signal, 0, len(signalMap))
|
handledSigs := make([]os.Signal, 0, len(SignalMap))
|
||||||
for _, s := range signalMap {
|
for _, s := range SignalMap {
|
||||||
handledSigs = append(handledSigs, s)
|
handledSigs = append(handledSigs, s)
|
||||||
}
|
}
|
||||||
signal.Notify(sigc, handledSigs...)
|
signal.Notify(sigc, handledSigs...)
|
||||||
|
|
|
@ -24,8 +24,8 @@ const (
|
||||||
SIGWINCH = syscall.SIGWINCH
|
SIGWINCH = syscall.SIGWINCH
|
||||||
)
|
)
|
||||||
|
|
||||||
// signalMap is a map of Linux signals.
|
// SignalMap is a map of Linux signals.
|
||||||
var signalMap = map[string]syscall.Signal{
|
var SignalMap = map[string]syscall.Signal{
|
||||||
"ABRT": unix.SIGABRT,
|
"ABRT": unix.SIGABRT,
|
||||||
"ALRM": unix.SIGALRM,
|
"ALRM": unix.SIGALRM,
|
||||||
"BUS": unix.SIGBUS,
|
"BUS": unix.SIGBUS,
|
||||||
|
@ -95,8 +95,8 @@ var signalMap = map[string]syscall.Signal{
|
||||||
|
|
||||||
// CatchAll catches all signals and relays them to the specified channel.
|
// CatchAll catches all signals and relays them to the specified channel.
|
||||||
func CatchAll(sigc chan os.Signal) {
|
func CatchAll(sigc chan os.Signal) {
|
||||||
handledSigs := make([]os.Signal, 0, len(signalMap))
|
handledSigs := make([]os.Signal, 0, len(SignalMap))
|
||||||
for _, s := range signalMap {
|
for _, s := range SignalMap {
|
||||||
handledSigs = append(handledSigs, s)
|
handledSigs = append(handledSigs, s)
|
||||||
}
|
}
|
||||||
signal.Notify(sigc, handledSigs...)
|
signal.Notify(sigc, handledSigs...)
|
||||||
|
|
|
@ -16,12 +16,12 @@ const (
|
||||||
SIGWINCH = syscall.SIGWINCH
|
SIGWINCH = syscall.SIGWINCH
|
||||||
)
|
)
|
||||||
|
|
||||||
// signalMap is a map of Linux signals.
|
// SignalMap is a map of Linux signals.
|
||||||
// These constants are sourced from the Linux version of golang.org/x/sys/unix
|
// These constants are sourced from the Linux version of golang.org/x/sys/unix
|
||||||
// (I don't see much risk of this changing).
|
// (I don't see much risk of this changing).
|
||||||
// This should work as long as Podman only runs containers on Linux, which seems
|
// This should work as long as Podman only runs containers on Linux, which seems
|
||||||
// a safe assumption for now.
|
// a safe assumption for now.
|
||||||
var signalMap = map[string]syscall.Signal{
|
var SignalMap = map[string]syscall.Signal{
|
||||||
"ABRT": syscall.Signal(0x6),
|
"ABRT": syscall.Signal(0x6),
|
||||||
"ALRM": syscall.Signal(0xe),
|
"ALRM": syscall.Signal(0xe),
|
||||||
"BUS": syscall.Signal(0x7),
|
"BUS": syscall.Signal(0x7),
|
||||||
|
|
|
@ -16,12 +16,12 @@ const (
|
||||||
SIGWINCH = syscall.Signal(0xff)
|
SIGWINCH = syscall.Signal(0xff)
|
||||||
)
|
)
|
||||||
|
|
||||||
// signalMap is a map of Linux signals.
|
// SignalMap is a map of Linux signals.
|
||||||
// These constants are sourced from the Linux version of golang.org/x/sys/unix
|
// These constants are sourced from the Linux version of golang.org/x/sys/unix
|
||||||
// (I don't see much risk of this changing).
|
// (I don't see much risk of this changing).
|
||||||
// This should work as long as Podman only runs containers on Linux, which seems
|
// This should work as long as Podman only runs containers on Linux, which seems
|
||||||
// a safe assumption for now.
|
// a safe assumption for now.
|
||||||
var signalMap = map[string]syscall.Signal{
|
var SignalMap = map[string]syscall.Signal{
|
||||||
"ABRT": syscall.Signal(0x6),
|
"ABRT": syscall.Signal(0x6),
|
||||||
"ALRM": syscall.Signal(0xe),
|
"ALRM": syscall.Signal(0xe),
|
||||||
"BUS": syscall.Signal(0x7),
|
"BUS": syscall.Signal(0x7),
|
||||||
|
|
Loading…
Reference in New Issue