summaryrefslogtreecommitdiff
path: root/cmd/podman
diff options
context:
space:
mode:
Diffstat (limited to 'cmd/podman')
-rw-r--r--cmd/podman/containers/rm.go13
-rw-r--r--cmd/podman/images/diff.go9
-rw-r--r--cmd/podman/inspect/inspect.go49
-rw-r--r--cmd/podman/play/kube.go1
-rw-r--r--cmd/podman/pods/inspect.go24
5 files changed, 65 insertions, 31 deletions
diff --git a/cmd/podman/containers/rm.go b/cmd/podman/containers/rm.go
index f8f12234d..a7739b3ba 100644
--- a/cmd/podman/containers/rm.go
+++ b/cmd/podman/containers/rm.go
@@ -57,13 +57,12 @@ func rmFlags(flags *pflag.FlagSet) {
flags.BoolVarP(&rmOptions.All, "all", "a", false, "Remove all containers")
flags.BoolVarP(&rmOptions.Ignore, "ignore", "i", false, "Ignore errors when a specified container is missing")
flags.BoolVarP(&rmOptions.Force, "force", "f", false, "Force removal of a running or unusable container. The default is false")
- flags.BoolVar(&rmOptions.Storage, "storage", false, "Remove container from storage library")
flags.BoolVarP(&rmOptions.Volumes, "volumes", "v", false, "Remove anonymous volumes associated with the container")
flags.StringArrayVarP(&rmOptions.CIDFiles, "cidfile", "", nil, "Read the container ID from the file")
- if registry.IsRemote() {
- _ = flags.MarkHidden("ignore")
- _ = flags.MarkHidden("cidfile")
+ if !registry.IsRemote() {
+ // This option is deprecated, but needs to still exists for backwards compatibility
+ flags.Bool("storage", false, "Remove container from storage library")
_ = flags.MarkHidden("storage")
}
}
@@ -97,12 +96,6 @@ func removeContainers(namesOrIDs []string, rmOptions entities.RmOptions, setExit
var (
errs utils.OutputErrors
)
- // Storage conflicts with --all/--latest/--volumes/--cidfile/--ignore
- if rmOptions.Storage {
- if rmOptions.All || rmOptions.Ignore || rmOptions.Latest || rmOptions.Volumes || rmOptions.CIDFiles != nil {
- return errors.Errorf("--storage conflicts with --volumes, --all, --latest, --ignore and --cidfile")
- }
- }
responses, err := registry.ContainerEngine().ContainerRm(context.Background(), namesOrIDs, rmOptions)
if err != nil {
if setExit {
diff --git a/cmd/podman/images/diff.go b/cmd/podman/images/diff.go
index 26147345e..05a05fa04 100644
--- a/cmd/podman/images/diff.go
+++ b/cmd/podman/images/diff.go
@@ -1,6 +1,7 @@
package images
import (
+ "github.com/containers/podman/v2/cmd/podman/parse"
"github.com/containers/podman/v2/cmd/podman/registry"
"github.com/containers/podman/v2/cmd/podman/report"
"github.com/containers/podman/v2/pkg/domain/entities"
@@ -49,11 +50,11 @@ func diff(cmd *cobra.Command, args []string) error {
return err
}
- switch diffOpts.Format {
- case "":
- return report.ChangesToTable(results)
- case "json":
+ switch {
+ case parse.MatchesJSONFormat(diffOpts.Format):
return report.ChangesToJSON(results)
+ case diffOpts.Format == "":
+ return report.ChangesToTable(results)
default:
return errors.New("only supported value for '--format' is 'json'")
}
diff --git a/cmd/podman/inspect/inspect.go b/cmd/podman/inspect/inspect.go
index f29527412..658463650 100644
--- a/cmd/podman/inspect/inspect.go
+++ b/cmd/podman/inspect/inspect.go
@@ -4,10 +4,14 @@ import (
"context"
"fmt"
"os"
+ "regexp"
"strings"
+ "text/tabwriter"
+ "text/template"
- "github.com/containers/buildah/pkg/formats"
+ "github.com/containers/podman/v2/cmd/podman/parse"
"github.com/containers/podman/v2/cmd/podman/registry"
+ "github.com/containers/podman/v2/cmd/podman/report"
"github.com/containers/podman/v2/cmd/podman/validate"
"github.com/containers/podman/v2/pkg/domain/entities"
"github.com/pkg/errors"
@@ -24,6 +28,9 @@ const (
AllType = "all"
)
+// Pull in configured json library
+var json = registry.JSONLibrary()
+
// AddInspectFlagSet takes a command and adds the inspect flags and returns an
// InspectOptions object.
func AddInspectFlagSet(cmd *cobra.Command) *entities.InspectOptions {
@@ -80,7 +87,7 @@ func newInspector(options entities.InspectOptions) (*inspector, error) {
// inspect inspects the specified container/image names or IDs.
func (i *inspector) inspect(namesOrIDs []string) error {
// data - dumping place for inspection results.
- var data []interface{} //nolint
+ var data []interface{} // nolint
var errs []error
ctx := context.Background()
@@ -134,15 +141,19 @@ func (i *inspector) inspect(namesOrIDs []string) error {
data = []interface{}{}
}
- var out formats.Writer
- if i.options.Format == "json" || i.options.Format == "" { // "" for backwards compat
- out = formats.JSONStructArray{Output: data}
- } else {
- out = formats.StdoutTemplateArray{Output: data, Template: inspectFormat(i.options.Format)}
+ var err error
+ switch {
+ case parse.MatchesJSONFormat(i.options.Format) || i.options.Format == "":
+ err = printJSON(data)
+ default:
+ row := inspectNormalize(i.options.Format)
+ row = "{{range . }}" + report.NormalizeFormat(row) + "{{end}}"
+ err = printTmpl(tmpType, row, data)
}
- if err := out.Out(); err != nil {
+ if err != nil {
logrus.Errorf("Error printing inspect output: %v", err)
}
+
if len(errs) > 0 {
if len(errs) > 1 {
for _, err := range errs[1:] {
@@ -154,8 +165,22 @@ func (i *inspector) inspect(namesOrIDs []string) error {
return nil
}
+func printJSON(data []interface{}) error {
+ enc := json.NewEncoder(os.Stdout)
+ return enc.Encode(data)
+}
+
+func printTmpl(typ, row string, data []interface{}) error {
+ t, err := template.New(typ + " inspect").Parse(row)
+ if err != nil {
+ return err
+ }
+ w := tabwriter.NewWriter(os.Stdout, 8, 2, 2, ' ', 0)
+ return t.Execute(w, data)
+}
+
func (i *inspector) inspectAll(ctx context.Context, namesOrIDs []string) ([]interface{}, []error, error) {
- var data []interface{} //nolint
+ var data []interface{} // nolint
allErrs := []error{}
for _, name := range namesOrIDs {
ctrData, errs, err := i.containerEngine.ContainerInspect(ctx, []string{name}, i.options)
@@ -179,9 +204,11 @@ func (i *inspector) inspectAll(ctx context.Context, namesOrIDs []string) ([]inte
return data, allErrs, nil
}
-func inspectFormat(row string) string {
+func inspectNormalize(row string) string {
+ m := regexp.MustCompile(`{{\s*\.Id\s*}}`)
+ row = m.ReplaceAllString(row, "{{.ID}}")
+
r := strings.NewReplacer(
- "{{.Id}}", formats.IDString,
".Src", ".Source",
".Dst", ".Destination",
".ImageID", ".Image",
diff --git a/cmd/podman/play/kube.go b/cmd/podman/play/kube.go
index 54a6d0677..976d720ee 100644
--- a/cmd/podman/play/kube.go
+++ b/cmd/podman/play/kube.go
@@ -60,6 +60,7 @@ func init() {
flags.BoolVar(&kubeOptions.TLSVerifyCLI, "tls-verify", true, "Require HTTPS and verify certificates when contacting registries")
flags.StringVar(&kubeOptions.SignaturePolicy, "signature-policy", "", "`Pathname` of signature policy file (not usually used)")
flags.StringVar(&kubeOptions.SeccompProfileRoot, "seccomp-profile-root", defaultSeccompRoot, "Directory path for seccomp profiles")
+ flags.StringSliceVar(&kubeOptions.ConfigMaps, "configmap", []string{}, "`Pathname` of a YAML file containing a kubernetes configmap")
}
_ = flags.MarkHidden("signature-policy")
}
diff --git a/cmd/podman/pods/inspect.go b/cmd/podman/pods/inspect.go
index bc20352b0..cad15d10f 100644
--- a/cmd/podman/pods/inspect.go
+++ b/cmd/podman/pods/inspect.go
@@ -3,9 +3,13 @@ package pods
import (
"context"
"fmt"
+ "os"
+ "text/tabwriter"
+ "text/template"
- "github.com/containers/buildah/pkg/formats"
+ "github.com/containers/podman/v2/cmd/podman/parse"
"github.com/containers/podman/v2/cmd/podman/registry"
+ "github.com/containers/podman/v2/cmd/podman/report"
"github.com/containers/podman/v2/cmd/podman/validate"
"github.com/containers/podman/v2/pkg/domain/entities"
"github.com/pkg/errors"
@@ -57,11 +61,19 @@ func inspect(cmd *cobra.Command, args []string) error {
if err != nil {
return err
}
- var data interface{} = responses
- var out formats.Writer = formats.JSONStruct{Output: data}
- if inspectOptions.Format != "json" {
- out = formats.StdoutTemplate{Output: data, Template: inspectOptions.Format}
+
+ if parse.MatchesJSONFormat(inspectOptions.Format) {
+ enc := json.NewEncoder(os.Stdout)
+ return enc.Encode(responses)
+ }
+
+ row := report.NormalizeFormat(inspectOptions.Format)
+
+ t, err := template.New("pod inspect").Parse(row)
+ if err != nil {
+ return err
}
- return out.Out()
+ w := tabwriter.NewWriter(os.Stdout, 8, 2, 2, ' ', 0)
+ return t.Execute(w, *responses)
}