Skip to content

Commit

Permalink
Merge pull request #5546 from jwhonce/wip/entities
Browse files Browse the repository at this point in the history
V2 podman command
  • Loading branch information
openshift-merge-robot authored Mar 19, 2020
2 parents b43e249 + fbe7435 commit 093d9ef
Show file tree
Hide file tree
Showing 39 changed files with 2,195 additions and 2 deletions.
33 changes: 33 additions & 0 deletions cmd/podmanV2/containers/container.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package containers

import (
"github.com/containers/libpod/cmd/podmanV2/registry"
"github.com/containers/libpod/pkg/domain/entities"
"github.com/spf13/cobra"
)

var (
// Command: podman _container_
containerCmd = &cobra.Command{
Use: "container",
Short: "Manage containers",
Long: "Manage containers",
TraverseChildren: true,
PersistentPreRunE: preRunE,
RunE: registry.SubCommandExists,
}
)

func init() {
registry.Commands = append(registry.Commands, registry.CliCommand{
Mode: []entities.EngineMode{entities.ABIMode, entities.TunnelMode},
Command: containerCmd,
})
containerCmd.SetHelpTemplate(registry.HelpTemplate())
containerCmd.SetUsageTemplate(registry.UsageTemplate())
}

func preRunE(cmd *cobra.Command, args []string) error {
_, err := registry.NewContainerEngine(cmd, args)
return err
}
42 changes: 42 additions & 0 deletions cmd/podmanV2/containers/inspect.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package containers

import (
"github.com/containers/libpod/cmd/podmanV2/registry"
"github.com/containers/libpod/pkg/domain/entities"
"github.com/spf13/cobra"
)

var (
// podman container _inspect_
inspectCmd = &cobra.Command{
Use: "inspect [flags] CONTAINER",
Short: "Display the configuration of a container",
Long: `Displays the low-level information on a container identified by name or ID.`,
PreRunE: inspectPreRunE,
RunE: inspect,
Example: `podman container inspect myCtr
podman container inspect -l --format '{{.Id}} {{.Config.Labels}}'`,
}
)

func init() {
registry.Commands = append(registry.Commands, registry.CliCommand{
Mode: []entities.EngineMode{entities.ABIMode, entities.TunnelMode},
Command: inspectCmd,
Parent: containerCmd,
})
}

func inspectPreRunE(cmd *cobra.Command, args []string) (err error) {
err = preRunE(cmd, args)
if err != nil {
return
}

_, err = registry.NewImageEngine(cmd, args)
return err
}

func inspect(cmd *cobra.Command, args []string) error {
return nil
}
34 changes: 34 additions & 0 deletions cmd/podmanV2/containers/list.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package containers

import (
"github.com/containers/libpod/cmd/podmanV2/registry"
"github.com/containers/libpod/pkg/domain/entities"
"github.com/spf13/cobra"
)

var (
// podman container _list_
listCmd = &cobra.Command{
Use: "list",
Aliases: []string{"ls"},
Args: cobra.NoArgs,
Short: "List containers",
Long: "Prints out information about the containers",
RunE: containers,
Example: `podman container list -a
podman container list -a --format "{{.ID}} {{.Image}} {{.Labels}} {{.Mounts}}"
podman container list --size --sort names`,
}
)

func init() {
registry.Commands = append(registry.Commands, registry.CliCommand{
Mode: []entities.EngineMode{entities.ABIMode, entities.TunnelMode},
Command: listCmd,
Parent: containerCmd,
})
}

func containers(cmd *cobra.Command, args []string) error {
return nil
}
29 changes: 29 additions & 0 deletions cmd/podmanV2/containers/ps.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package containers

import (
"strings"

"github.com/containers/libpod/cmd/podmanV2/registry"
"github.com/containers/libpod/pkg/domain/entities"
"github.com/spf13/cobra"
)

var (
// podman _ps_
psCmd = &cobra.Command{
Use: "ps",
Args: cobra.NoArgs,
Short: listCmd.Short,
Long: listCmd.Long,
PersistentPreRunE: preRunE,
RunE: containers,
Example: strings.Replace(listCmd.Example, "container list", "ps", -1),
}
)

func init() {
registry.Commands = append(registry.Commands, registry.CliCommand{
Mode: []entities.EngineMode{entities.ABIMode, entities.TunnelMode},
Command: psCmd,
})
}
79 changes: 79 additions & 0 deletions cmd/podmanV2/images/history.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
package images

import (
"context"
"fmt"
"os"
"text/tabwriter"
"text/template"

"github.com/containers/libpod/cmd/podmanV2/registry"
"github.com/containers/libpod/cmd/podmanV2/report"
"github.com/containers/libpod/pkg/domain/entities"
"github.com/pkg/errors"
"github.com/spf13/cobra"
)

var (
long = `Displays the history of an image.
The information can be printed out in an easy to read, or user specified format, and can be truncated.`

// podman _history_
historyCmd = &cobra.Command{
Use: "history [flags] IMAGE",
Short: "Show history of a specified image",
Long: long,
Example: "podman history quay.io/fedora/fedora",
Args: cobra.ExactArgs(1),
PersistentPreRunE: preRunE,
RunE: history,
}
)

var cmdFlags = struct {
Human bool
NoTrunc bool
Quiet bool
Format string
}{}

func init() {
registry.Commands = append(registry.Commands, registry.CliCommand{
Mode: []entities.EngineMode{entities.ABIMode, entities.TunnelMode},
Command: historyCmd,
})

historyCmd.SetHelpTemplate(registry.HelpTemplate())
historyCmd.SetUsageTemplate(registry.UsageTemplate())
flags := historyCmd.Flags()
flags.StringVar(&cmdFlags.Format, "format", "", "Change the output to JSON or a Go template")
flags.BoolVarP(&cmdFlags.Human, "human", "H", true, "Display sizes and dates in human readable format")
flags.BoolVar(&cmdFlags.NoTrunc, "no-trunc", false, "Do not truncate the output")
flags.BoolVar(&cmdFlags.NoTrunc, "notruncate", false, "Do not truncate the output")
flags.BoolVarP(&cmdFlags.Quiet, "quiet", "q", false, "Display the numeric IDs only")
}

func history(cmd *cobra.Command, args []string) error {
results, err := registry.ImageEngine().History(context.Background(), args[0], entities.ImageHistoryOptions{})
if err != nil {
return err
}

row := "{{slice $x.ID 0 12}}\t{{toRFC3339 $x.Created}}\t{{ellipsis $x.CreatedBy 45}}\t{{$x.Size}}\t{{$x.Comment}}\n"
if cmdFlags.Human {
row = "{{slice $x.ID 0 12}}\t{{toHumanDuration $x.Created}}\t{{ellipsis $x.CreatedBy 45}}\t{{toHumanSize $x.Size}}\t{{$x.Comment}}\n"
}
format := "{{range $y, $x := . }}" + row + "{{end}}"

tmpl := template.Must(template.New("report").Funcs(report.PodmanTemplateFuncs()).Parse(format))
w := tabwriter.NewWriter(os.Stdout, 8, 2, 2, ' ', 0)

_, _ = w.Write(report.ReportHeader("id", "created", "created by", "size", "comment"))
err = tmpl.Execute(w, results.Layers)
if err != nil {
fmt.Fprintln(os.Stderr, errors.Wrapf(err, "Failed to print report"))
}
w.Flush()
return nil
}
33 changes: 33 additions & 0 deletions cmd/podmanV2/images/image.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package images

import (
"github.com/containers/libpod/cmd/podmanV2/registry"
"github.com/containers/libpod/pkg/domain/entities"
"github.com/spf13/cobra"
)

var (
// Command: podman _image_
imageCmd = &cobra.Command{
Use: "image",
Short: "Manage images",
Long: "Manage images",
TraverseChildren: true,
PersistentPreRunE: preRunE,
RunE: registry.SubCommandExists,
}
)

func init() {
registry.Commands = append(registry.Commands, registry.CliCommand{
Mode: []entities.EngineMode{entities.ABIMode, entities.TunnelMode},
Command: imageCmd,
})
imageCmd.SetHelpTemplate(registry.HelpTemplate())
imageCmd.SetUsageTemplate(registry.UsageTemplate())
}

func preRunE(cmd *cobra.Command, args []string) error {
_, err := registry.NewImageEngine(cmd, args)
return err
}
46 changes: 46 additions & 0 deletions cmd/podmanV2/images/images.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
package images

import (
"strings"

"github.com/containers/libpod/cmd/podmanV2/registry"
"github.com/containers/libpod/pkg/domain/entities"
"github.com/spf13/cobra"
)

var (
// podman _images_
imagesCmd = &cobra.Command{
Use: strings.Replace(listCmd.Use, "list", "images", 1),
Short: listCmd.Short,
Long: listCmd.Long,
PersistentPreRunE: preRunE,
RunE: images,
Example: strings.Replace(listCmd.Example, "podman image list", "podman images", -1),
}

imagesOpts = entities.ImageListOptions{}
)

func init() {
registry.Commands = append(registry.Commands, registry.CliCommand{
Mode: []entities.EngineMode{entities.ABIMode, entities.TunnelMode},
Command: imagesCmd,
})
imagesCmd.SetHelpTemplate(registry.HelpTemplate())
imagesCmd.SetUsageTemplate(registry.UsageTemplate())

flags := imagesCmd.Flags()
flags.BoolVarP(&imagesOpts.All, "all", "a", false, "Show all images (default hides intermediate images)")
flags.BoolVar(&imagesOpts.Digests, "digests", false, "Show digests")
flags.StringSliceVarP(&imagesOpts.Filter, "filter", "f", []string{}, "Filter output based on conditions provided (default [])")
flags.StringVar(&imagesOpts.Format, "format", "", "Change the output format to JSON or a Go template")
flags.BoolVarP(&imagesOpts.Noheading, "noheading", "n", false, "Do not print column headings")
// TODO Need to learn how to deal with second name being a string instead of a char.
// This needs to be "no-trunc, notruncate"
flags.BoolVar(&imagesOpts.NoTrunc, "no-trunc", false, "Do not truncate output")
flags.BoolVar(&imagesOpts.NoTrunc, "notruncate", false, "Do not truncate output")
flags.BoolVarP(&imagesOpts.Quiet, "quiet", "q", false, "Display only image IDs")
flags.StringVar(&imagesOpts.Sort, "sort", "created", "Sort by created, id, repository, size, or tag")
flags.BoolVarP(&imagesOpts.History, "history", "", false, "Display the image name history")
}
Loading

0 comments on commit 093d9ef

Please sign in to comment.