summaryrefslogtreecommitdiff
path: root/cmd/podman/system/connection/list.go
diff options
context:
space:
mode:
authorDaniel J Walsh <dwalsh@redhat.com>2022-09-09 09:06:18 -0400
committerDaniel J Walsh <dwalsh@redhat.com>2022-09-15 08:17:15 -0400
commit3508bd22fe355630453d497d905e480974a84b96 (patch)
tree42874103bb7d0329796598fc251e6e8f4fac1bdc /cmd/podman/system/connection/list.go
parent4fc18d07a6b206476421ed134f0eeec1221936c2 (diff)
downloadpodman-3508bd22fe355630453d497d905e480974a84b96.tar.gz
podman-3508bd22fe355630453d497d905e480974a84b96.tar.bz2
podman-3508bd22fe355630453d497d905e480974a84b96.zip
Add support for podman context as alias to podman system connection
Alias podman --context -> podman --connection podman context use -> podman system connection default podman context rm -> podman system connection rm podman context create -> podman system connection add podman context ls ->podman system connection ls podman context inspect ->podman system connection ls --json (For specified connections) Podman context is a hidden command, but can be used for existing scripts that assume Docker under the covers. Signed-off-by: Daniel J Walsh <dwalsh@redhat.com>
Diffstat (limited to 'cmd/podman/system/connection/list.go')
-rw-r--r--cmd/podman/system/connection/list.go56
1 files changed, 51 insertions, 5 deletions
diff --git a/cmd/podman/system/connection/list.go b/cmd/podman/system/connection/list.go
index 2c5f6a310..190a68d52 100644
--- a/cmd/podman/system/connection/list.go
+++ b/cmd/podman/system/connection/list.go
@@ -8,6 +8,7 @@ import (
"github.com/containers/common/pkg/completion"
"github.com/containers/common/pkg/config"
"github.com/containers/common/pkg/report"
+ "github.com/containers/common/pkg/util"
"github.com/containers/podman/v4/cmd/podman/common"
"github.com/containers/podman/v4/cmd/podman/registry"
"github.com/containers/podman/v4/cmd/podman/system"
@@ -29,16 +30,36 @@ var (
RunE: list,
TraverseChildren: false,
}
+ inspectCmd = &cobra.Command{
+ Use: "inspect [options] [CONTEXT] [CONTEXT...]",
+ Short: "Inspect destination for a Podman service(s)",
+ ValidArgsFunction: completion.AutocompleteNone,
+ RunE: inspect,
+ }
)
func init() {
+ initFlags := func(cmd *cobra.Command) {
+ cmd.Flags().StringP("format", "f", "", "Custom Go template for printing connections")
+ _ = cmd.RegisterFlagCompletionFunc("format", common.AutocompleteFormat(&namedDestination{}))
+ cmd.Flags().BoolP("quiet", "q", false, "Custom Go template for printing connections")
+ }
+
+ registry.Commands = append(registry.Commands, registry.CliCommand{
+ Command: listCmd,
+ Parent: system.ContextCmd,
+ })
registry.Commands = append(registry.Commands, registry.CliCommand{
Command: listCmd,
Parent: system.ConnectionCmd,
})
+ initFlags(listCmd)
- listCmd.Flags().String("format", "", "Custom Go template for printing connections")
- _ = listCmd.RegisterFlagCompletionFunc("format", common.AutocompleteFormat(&namedDestination{}))
+ registry.Commands = append(registry.Commands, registry.CliCommand{
+ Command: inspectCmd,
+ Parent: system.ContextCmd,
+ })
+ initFlags(inspectCmd)
}
type namedDestination struct {
@@ -48,13 +69,34 @@ type namedDestination struct {
}
func list(cmd *cobra.Command, _ []string) error {
+ return inspect(cmd, nil)
+}
+
+func inspect(cmd *cobra.Command, args []string) error {
cfg, err := config.ReadCustomConfig()
if err != nil {
return err
}
+ format := cmd.Flag("format").Value.String()
+ if format == "" && args != nil {
+ format = "json"
+ }
+
+ quiet, err := cmd.Flags().GetBool("quiet")
+ if err != nil {
+ return err
+ }
rows := make([]namedDestination, 0)
for k, v := range cfg.Engine.ServiceDestinations {
+ if args != nil && !util.StringInSlice(k, args) {
+ continue
+ }
+
+ if quiet {
+ fmt.Println(k)
+ continue
+ }
def := false
if k == cfg.Engine.ActiveService {
def = true
@@ -71,6 +113,10 @@ func list(cmd *cobra.Command, _ []string) error {
rows = append(rows, r)
}
+ if quiet {
+ return nil
+ }
+
sort.Slice(rows, func(i, j int) bool {
return rows[i].Name < rows[j].Name
})
@@ -78,7 +124,7 @@ func list(cmd *cobra.Command, _ []string) error {
rpt := report.New(os.Stdout, cmd.Name())
defer rpt.Flush()
- if report.IsJSON(cmd.Flag("format").Value.String()) {
+ if report.IsJSON(format) {
buf, err := registry.JSONLibrary().MarshalIndent(rows, "", " ")
if err == nil {
fmt.Println(string(buf))
@@ -86,8 +132,8 @@ func list(cmd *cobra.Command, _ []string) error {
return err
}
- if cmd.Flag("format").Changed {
- rpt, err = rpt.Parse(report.OriginUser, cmd.Flag("format").Value.String())
+ if format != "" {
+ rpt, err = rpt.Parse(report.OriginUser, format)
} else {
rpt, err = rpt.Parse(report.OriginPodman,
"{{range .}}{{.Name}}\t{{.URI}}\t{{.Identity}}\t{{.Default}}\n{{end -}}")