diff options
Diffstat (limited to 'cmd')
-rw-r--r-- | cmd/podman/common/create.go | 3 | ||||
-rw-r--r-- | cmd/podman/common/create_opts.go | 2 | ||||
-rw-r--r-- | cmd/podman/containers/create.go | 7 | ||||
-rw-r--r-- | cmd/podman/containers/logs.go | 3 | ||||
-rw-r--r-- | cmd/podman/main.go | 64 | ||||
-rw-r--r-- | cmd/podman/pods/logs.go | 2 |
6 files changed, 61 insertions, 20 deletions
diff --git a/cmd/podman/common/create.go b/cmd/podman/common/create.go index afaa1942e..8a3f02036 100644 --- a/cmd/podman/common/create.go +++ b/cmd/podman/common/create.go @@ -348,8 +348,7 @@ func DefineCreateFlags(cmd *cobra.Command, cf *entities.ContainerCreateOptions, ) oomScoreAdjFlagName := "oom-score-adj" - createFlags.IntVar( - &cf.OOMScoreAdj, + createFlags.Int( oomScoreAdjFlagName, 0, "Tune the host's OOM preferences (-1000 to 1000)", ) diff --git a/cmd/podman/common/create_opts.go b/cmd/podman/common/create_opts.go index e5a2a0da3..ad6b3870a 100644 --- a/cmd/podman/common/create_opts.go +++ b/cmd/podman/common/create_opts.go @@ -286,7 +286,7 @@ func ContainerCreateToContainerCLIOpts(cc handlers.CreateContainerConfig, rtc *c LogDriver: cc.HostConfig.LogConfig.Type, LogOptions: stringMaptoArray(cc.HostConfig.LogConfig.Config), Name: cc.Name, - OOMScoreAdj: cc.HostConfig.OomScoreAdj, + OOMScoreAdj: &cc.HostConfig.OomScoreAdj, Arch: "", OS: "", Variant: "", diff --git a/cmd/podman/containers/create.go b/cmd/podman/containers/create.go index de1a41e25..bbc449a1e 100644 --- a/cmd/podman/containers/create.go +++ b/cmd/podman/containers/create.go @@ -238,6 +238,13 @@ func CreateInit(c *cobra.Command, vals entities.ContainerCreateOptions, isInfra vals.GroupAdd = groups } + if c.Flags().Changed("oom-score-adj") { + val, err := c.Flags().GetInt("oom-score-adj") + if err != nil { + return vals, err + } + vals.OOMScoreAdj = &val + } if c.Flags().Changed("pids-limit") { val := c.Flag("pids-limit").Value.String() // Convert -1 to 0, so that -1 maps to unlimited pids limit diff --git a/cmd/podman/containers/logs.go b/cmd/podman/containers/logs.go index 8b08a6313..374bf6b1c 100644 --- a/cmd/podman/containers/logs.go +++ b/cmd/podman/containers/logs.go @@ -64,6 +64,7 @@ var ( ValidArgsFunction: logsCommand.ValidArgsFunction, Example: `podman container logs ctrID podman container logs --names ctrID1 ctrID2 + podman container logs --color --names ctrID1 ctrID2 podman container logs --tail 2 mywebserver podman container logs --follow=true --since 10m ctrID podman container logs mywebserver mydbserver`, @@ -112,7 +113,9 @@ func logsFlags(cmd *cobra.Command) { _ = cmd.RegisterFlagCompletionFunc(tailFlagName, completion.AutocompleteNone) flags.BoolVarP(&logsOptions.Timestamps, "timestamps", "t", false, "Output the timestamps in the log") + flags.BoolVarP(&logsOptions.Colors, "color", "", false, "Output the containers with different colors in the log.") flags.BoolVarP(&logsOptions.Names, "names", "n", false, "Output the container name in the log") + flags.SetInterspersed(false) _ = flags.MarkHidden("details") } diff --git a/cmd/podman/main.go b/cmd/podman/main.go index 4f8131653..8f580601e 100644 --- a/cmd/podman/main.go +++ b/cmd/podman/main.go @@ -3,7 +3,6 @@ package main import ( "fmt" "os" - "strings" _ "github.com/containers/podman/v4/cmd/podman/completion" _ "github.com/containers/podman/v4/cmd/podman/containers" @@ -20,6 +19,7 @@ import ( _ "github.com/containers/podman/v4/cmd/podman/system" _ "github.com/containers/podman/v4/cmd/podman/system/connection" _ "github.com/containers/podman/v4/cmd/podman/volumes" + "github.com/containers/podman/v4/pkg/domain/entities" "github.com/containers/podman/v4/pkg/rootless" "github.com/containers/podman/v4/pkg/terminal" "github.com/containers/storage/pkg/reexec" @@ -44,7 +44,29 @@ func parseCommands() *cobra.Command { cfg := registry.PodmanConfig() for _, c := range registry.Commands { if supported, found := c.Command.Annotations[registry.EngineMode]; found { - if !strings.Contains(cfg.EngineMode.String(), supported) { + if cfg.EngineMode.String() != supported { + var client string + switch cfg.EngineMode { + case entities.TunnelMode: + client = "remote" + case entities.ABIMode: + client = "local" + } + + // add error message to the command so the user knows that this command is not supported with local/remote + c.Command.RunE = func(cmd *cobra.Command, args []string) error { + return fmt.Errorf("cannot use command %q with the %s podman client", cmd.CommandPath(), client) + } + // turn of flag parsing to make we do not get flag errors + c.Command.DisableFlagParsing = true + + // mark command as hidden so it is not shown in --help + c.Command.Hidden = true + + // overwrite persistent pre/post function to skip setup + c.Command.PersistentPostRunE = noop + c.Command.PersistentPreRunE = noop + addCommand(c) continue } } @@ -65,22 +87,9 @@ func parseCommands() *cobra.Command { } } } - - parent := rootCmd - if c.Parent != nil { - parent = c.Parent - } - parent.AddCommand(c.Command) - - c.Command.SetFlagErrorFunc(flagErrorFuncfunc) - - // - templates need to be set here, as PersistentPreRunE() is - // not called when --help is used. - // - rootCmd uses cobra default template not ours - c.Command.SetHelpTemplate(helpTemplate) - c.Command.SetUsageTemplate(usageTemplate) - c.Command.DisableFlagsInUseLine = true + addCommand(c) } + if err := terminal.SetConsole(); err != nil { logrus.Error(err) os.Exit(1) @@ -94,3 +103,24 @@ func flagErrorFuncfunc(c *cobra.Command, e error) error { e = fmt.Errorf("%w\nSee '%s --help'", e, c.CommandPath()) return e } + +func addCommand(c registry.CliCommand) { + parent := rootCmd + if c.Parent != nil { + parent = c.Parent + } + parent.AddCommand(c.Command) + + c.Command.SetFlagErrorFunc(flagErrorFuncfunc) + + // - templates need to be set here, as PersistentPreRunE() is + // not called when --help is used. + // - rootCmd uses cobra default template not ours + c.Command.SetHelpTemplate(helpTemplate) + c.Command.SetUsageTemplate(usageTemplate) + c.Command.DisableFlagsInUseLine = true +} + +func noop(cmd *cobra.Command, args []string) error { + return nil +} diff --git a/cmd/podman/pods/logs.go b/cmd/podman/pods/logs.go index e35b48bed..28e7b7a43 100644 --- a/cmd/podman/pods/logs.go +++ b/cmd/podman/pods/logs.go @@ -89,6 +89,8 @@ func logsFlags(cmd *cobra.Command) { flags.BoolVarP(&logsPodOptions.Names, "names", "n", false, "Output container names instead of container IDs in the log") flags.BoolVarP(&logsPodOptions.Timestamps, "timestamps", "t", false, "Output the timestamps in the log") + flags.BoolVarP(&logsPodOptions.Colors, "color", "", false, "Output the containers within a pod with different colors in the log") + flags.SetInterspersed(false) _ = flags.MarkHidden("details") } |