github.com/containers/libpod@v1.9.4-0.20220419124438-4284fd425507/cmd/podman/container.go (about)

     1  package main
     2  
     3  import (
     4  	"strings"
     5  
     6  	"github.com/containers/libpod/cmd/podman/cliconfig"
     7  	"github.com/spf13/cobra"
     8  )
     9  
    10  var (
    11  	containerDescription = "Manage containers"
    12  	containerCommand     = cliconfig.PodmanCommand{
    13  		Command: &cobra.Command{
    14  			Use:              "container",
    15  			Short:            "Manage Containers",
    16  			Long:             containerDescription,
    17  			TraverseChildren: true,
    18  			RunE:             commandRunE(),
    19  		},
    20  	}
    21  
    22  	contInspectSubCommand  cliconfig.InspectValues
    23  	_contInspectSubCommand = &cobra.Command{
    24  		Use:   strings.Replace(_inspectCommand.Use, "| IMAGE", "", 1),
    25  		Short: "Display the configuration of a container",
    26  		Long:  `Displays the low-level information on a container identified by name or ID.`,
    27  		RunE: func(cmd *cobra.Command, args []string) error {
    28  			contInspectSubCommand.InputArgs = args
    29  			contInspectSubCommand.GlobalFlags = MainGlobalOpts
    30  			return inspectCmd(&contInspectSubCommand)
    31  		},
    32  		Example: `podman container inspect myCtr
    33    podman container inspect -l --format '{{.Id}} {{.Config.Labels}}'`,
    34  	}
    35  
    36  	listSubCommand  cliconfig.PsValues
    37  	_listSubCommand = &cobra.Command{
    38  		Use:     strings.Replace(_psCommand.Use, "ps", "list", 1),
    39  		Args:    noSubArgs,
    40  		Short:   _psCommand.Short,
    41  		Long:    _psCommand.Long,
    42  		Aliases: []string{"ls"},
    43  		RunE: func(cmd *cobra.Command, args []string) error {
    44  			listSubCommand.InputArgs = args
    45  			listSubCommand.GlobalFlags = MainGlobalOpts
    46  			return psCmd(&listSubCommand)
    47  		},
    48  		Example: strings.Replace(_psCommand.Example, "podman ps", "podman container list", -1),
    49  	}
    50  
    51  	// Commands that are universally implemented.
    52  	containerCommands = []*cobra.Command{
    53  		_attachCommand,
    54  		_checkpointCommand,
    55  		_commitCommand,
    56  		_containerExistsCommand,
    57  		_contInspectSubCommand,
    58  		_diffCommand,
    59  		_execCommand,
    60  		_exportCommand,
    61  		_createCommand,
    62  		_initCommand,
    63  		_killCommand,
    64  		_listSubCommand,
    65  		_logsCommand,
    66  		_pauseCommand,
    67  		_portCommand,
    68  		_pruneContainersCommand,
    69  		_restartCommand,
    70  		_restoreCommand,
    71  		_runCommand,
    72  		_rmCommand,
    73  		_startCommand,
    74  		_stopCommand,
    75  		_topCommand,
    76  		_unpauseCommand,
    77  		_waitCommand,
    78  	}
    79  )
    80  
    81  func init() {
    82  	contInspectSubCommand.Command = _contInspectSubCommand
    83  	inspectInit(&contInspectSubCommand)
    84  
    85  	listSubCommand.Command = _listSubCommand
    86  	psInit(&listSubCommand)
    87  
    88  	containerCommand.AddCommand(containerCommands...)
    89  	containerCommand.AddCommand(getContainerSubCommands()...)
    90  	containerCommand.SetUsageTemplate(UsageTemplate())
    91  
    92  	rootCmd.AddCommand(containerCommand.Command)
    93  }