summaryrefslogtreecommitdiff
path: root/cmd/podman/root.go
diff options
context:
space:
mode:
Diffstat (limited to 'cmd/podman/root.go')
-rw-r--r--cmd/podman/root.go48
1 files changed, 25 insertions, 23 deletions
diff --git a/cmd/podman/root.go b/cmd/podman/root.go
index 259e10c55..375faf8b1 100644
--- a/cmd/podman/root.go
+++ b/cmd/podman/root.go
@@ -9,6 +9,7 @@ import (
"strings"
"github.com/containers/libpod/cmd/podman/registry"
+ "github.com/containers/libpod/cmd/podman/validate"
"github.com/containers/libpod/pkg/domain/entities"
"github.com/containers/libpod/pkg/rootless"
"github.com/containers/libpod/pkg/tracing"
@@ -34,7 +35,7 @@ Description:
// UsageTemplate is the usage template for podman commands
// This blocks the displaying of the global options. The main podman
// command should not use this.
-const usageTemplate = `Usage(v2):{{if (and .Runnable (not .HasAvailableSubCommands))}}
+const usageTemplate = `Usage:{{if (and .Runnable (not .HasAvailableSubCommands))}}
{{.UseLine}}{{end}}{{if .HasAvailableSubCommands}}
{{.CommandPath}} [command]{{end}}{{if gt (len .Aliases) 0}}
@@ -60,7 +61,7 @@ var (
SilenceErrors: true,
TraverseChildren: true,
PersistentPreRunE: persistentPreRunE,
- RunE: registry.SubCommandExists,
+ RunE: validate.SubCommandExists,
PersistentPostRunE: persistentPostRunE,
Version: version.Version,
}
@@ -77,12 +78,16 @@ func init() {
syslogHook,
)
- rootFlags(registry.PodmanOptions, rootCmd.PersistentFlags())
+ rootFlags(registry.PodmanConfig(), rootCmd.PersistentFlags())
+
+ // "version" is a local flag to avoid collisions with sub-commands that use "-v"
+ var dummyVersion bool
+ rootCmd.Flags().BoolVarP(&dummyVersion, "version", "v", false, "Version of Podman")
}
func Execute() {
if err := rootCmd.ExecuteContext(registry.GetContextWithOptions()); err != nil {
- logrus.Error(err)
+ fmt.Fprintln(os.Stderr, "Error:", err.Error())
} else if registry.GetExitCode() == registry.ExecErrorCodeGeneric {
// The exitCode modified from registry.ExecErrorCodeGeneric,
// indicates an application
@@ -96,11 +101,9 @@ func Execute() {
func persistentPreRunE(cmd *cobra.Command, args []string) error {
// TODO: Remove trace statement in podman V2.1
- logrus.Debugf("Called %s.PersistentPreRunE()", cmd.Name())
+ logrus.Debugf("Called %s.PersistentPreRunE(%s)", cmd.Name(), strings.Join(os.Args, " "))
- // Update PodmanOptions now that we "know" more
- // TODO: pass in path overriding configuration file
- registry.PodmanOptions = registry.NewPodmanConfig()
+ cfg := registry.PodmanConfig()
// Prep the engines
if _, err := registry.NewImageEngine(cmd, args); err != nil {
@@ -111,10 +114,10 @@ func persistentPreRunE(cmd *cobra.Command, args []string) error {
}
if cmd.Flag("cpu-profile").Changed {
- f, err := os.Create(registry.PodmanOptions.CpuProfile)
+ f, err := os.Create(cfg.CpuProfile)
if err != nil {
return errors.Wrapf(err, "unable to create cpu profiling file %s",
- registry.PodmanOptions.CpuProfile)
+ cfg.CpuProfile)
}
if err := pprof.StartCPUProfile(f); err != nil {
return err
@@ -124,11 +127,11 @@ func persistentPreRunE(cmd *cobra.Command, args []string) error {
if cmd.Flag("trace").Changed {
tracer, closer := tracing.Init("podman")
opentracing.SetGlobalTracer(tracer)
- registry.PodmanOptions.SpanCloser = closer
+ cfg.SpanCloser = closer
- registry.PodmanOptions.Span = tracer.StartSpan("before-context")
- registry.PodmanOptions.SpanCtx = opentracing.ContextWithSpan(registry.Context(), registry.PodmanOptions.Span)
- opentracing.StartSpanFromContext(registry.PodmanOptions.SpanCtx, cmd.Name())
+ cfg.Span = tracer.StartSpan("before-context")
+ cfg.SpanCtx = opentracing.ContextWithSpan(registry.Context(), cfg.Span)
+ opentracing.StartSpanFromContext(cfg.SpanCtx, cmd.Name())
}
// Setup Rootless environment, IFF:
@@ -147,15 +150,19 @@ func persistentPreRunE(cmd *cobra.Command, args []string) error {
func persistentPostRunE(cmd *cobra.Command, args []string) error {
// TODO: Remove trace statement in podman V2.1
- logrus.Debugf("Called %s.PersistentPostRunE()", cmd.Name())
+ logrus.Debugf("Called %s.PersistentPostRunE(%s)", cmd.Name(), strings.Join(os.Args, " "))
+ cfg := registry.PodmanConfig()
if cmd.Flag("cpu-profile").Changed {
pprof.StopCPUProfile()
}
if cmd.Flag("trace").Changed {
- registry.PodmanOptions.Span.Finish()
- registry.PodmanOptions.SpanCloser.Close()
+ cfg.Span.Finish()
+ cfg.SpanCloser.Close()
}
+
+ registry.ImageEngine().Shutdown(registry.Context())
+ registry.ContainerEngine().Shutdown(registry.Context())
return nil
}
@@ -199,16 +206,11 @@ func syslogHook() {
}
}
-func rootFlags(opts entities.PodmanConfig, flags *pflag.FlagSet) {
+func rootFlags(opts *entities.PodmanConfig, flags *pflag.FlagSet) {
// V2 flags
flags.StringVarP(&opts.Uri, "remote", "r", "", "URL to access Podman service")
flags.StringSliceVar(&opts.Identities, "identity", []string{}, "path to SSH identity file")
- // Override default --help information of `--version` global flag
- // TODO: restore -v option for version without breaking -v for volumes
- var dummyVersion bool
- flags.BoolVar(&dummyVersion, "version", false, "Version of Podman")
-
cfg := opts.Config
flags.StringVar(&cfg.Engine.CgroupManager, "cgroup-manager", cfg.Engine.CgroupManager, opts.CGroupUsage)
flags.StringVar(&opts.CpuProfile, "cpu-profile", "", "Path for the cpu profiling results")