Merge pull request #12356 from Luap99/pod-logs

fix duplicated logs command
This commit is contained in:
OpenShift Merge Robot
2021-11-19 10:43:13 +01:00
committed by GitHub
2 changed files with 13 additions and 25 deletions

View File

@ -27,11 +27,11 @@ type logsOptionsWrapper struct {
var ( var (
logsPodOptions logsOptionsWrapper logsPodOptions logsOptionsWrapper
logsPodDescription = `Displays logs for pod with one or more containers.` logsPodDescription = `Displays logs for pod with one or more containers.`
logsPodCommand = &cobra.Command{ podLogsCommand = &cobra.Command{
Use: "logs [options] POD", Use: "logs [options] POD",
Short: "Fetch logs for pod with one or more containers", Short: "Fetch logs for pod with one or more containers",
Long: logsPodDescription, Long: logsPodDescription,
// We dont want users to invoke latest and pod togather // We dont want users to invoke latest and pod together
Args: func(cmd *cobra.Command, args []string) error { Args: func(cmd *cobra.Command, args []string) error {
switch { switch {
case registry.IsRemote() && logsPodOptions.Latest: case registry.IsRemote() && logsPodOptions.Latest:
@ -53,35 +53,16 @@ var (
podman pod logs --follow=true --since 10m podID podman pod logs --follow=true --since 10m podID
podman pod logs mywebserver`, podman pod logs mywebserver`,
} }
containerLogsCommand = &cobra.Command{
Use: logsPodCommand.Use,
Short: logsPodCommand.Short,
Long: logsPodCommand.Long,
Args: logsPodCommand.Args,
RunE: logsPodCommand.RunE,
ValidArgsFunction: logsPodCommand.ValidArgsFunction,
Example: `podman pod logs podId
podman pod logs -c ctrname podName
podman pod logs --tail 2 mywebserver
podman pod logs --follow=true --since 10m podID`,
}
) )
func init() { func init() {
// pod logs
registry.Commands = append(registry.Commands, registry.CliCommand{ registry.Commands = append(registry.Commands, registry.CliCommand{
Command: logsPodCommand, Command: podLogsCommand,
})
logsFlags(logsPodCommand)
validate.AddLatestFlag(logsPodCommand, &logsPodOptions.Latest)
// container logs
registry.Commands = append(registry.Commands, registry.CliCommand{
Command: containerLogsCommand,
Parent: podCmd, Parent: podCmd,
}) })
logsFlags(containerLogsCommand) logsFlags(podLogsCommand)
validate.AddLatestFlag(containerLogsCommand, &logsPodOptions.Latest) validate.AddLatestFlag(podLogsCommand, &logsPodOptions.Latest)
} }
func logsFlags(cmd *cobra.Command) { func logsFlags(cmd *cobra.Command) {

View File

@ -242,6 +242,13 @@ sub podman_help {
if ($line =~ /^\s{1,4}(\S+)\s/) { if ($line =~ /^\s{1,4}(\S+)\s/) {
my $subcommand = $1; my $subcommand = $1;
print "> podman @_ $subcommand\n" if $debug; print "> podman @_ $subcommand\n" if $debug;
# check that the same subcommand is not listed twice (#12356)
if (exists $help{$subcommand}) {
warn "$ME: 'podman @_ help' lists '$subcommand' twice\n";
++$Errs;
}
$help{$subcommand} = podman_help(@_, $subcommand) $help{$subcommand} = podman_help(@_, $subcommand)
unless $subcommand eq 'help'; # 'help' not in man unless $subcommand eq 'help'; # 'help' not in man
} }