Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

\t was not being recognized as tab in --format #123

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion cmd/kpod/formats/formats.go
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
package formats

import (
"bytes"
"encoding/json"
"fmt"
"os"
"strings"
"text/tabwriter"
"text/template"

"bytes"
"github.com/ghodss/yaml"
"github.com/pkg/errors"
)
Expand Down
12 changes: 7 additions & 5 deletions cmd/kpod/history.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,10 +92,7 @@ func historyCmd(c *cli.Context) error {
}
defer runtime.Shutdown(false)

format := genHistoryFormat(c.Bool("quiet"))
if c.IsSet("format") {
format = c.String("format")
}
format := genHistoryFormat(c.String("format"), c.Bool("quiet"))

args := c.Args()
if len(args) == 0 {
Expand All @@ -121,7 +118,12 @@ func historyCmd(c *cli.Context) error {
return generateHistoryOutput(history, layers, imageID, opts)
}

func genHistoryFormat(quiet bool) (format string) {
func genHistoryFormat(format string, quiet bool) string {
if format != "" {
// "\t" from the command line is not being recognized as a tab
// replacing the string "\t" to a tab character if the user passes in "\t"
return strings.Replace(format, `\t`, "\t", -1)
}
if quiet {
return formats.IDString
}
Expand Down
16 changes: 8 additions & 8 deletions cmd/kpod/images.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,12 +93,7 @@ func imagesCmd(c *cli.Context) error {
}
defer runtime.Shutdown(false)

var format string
if c.IsSet("format") {
format = c.String("format")
} else {
format = genImagesFormat(c.Bool("quiet"), c.Bool("noheading"), c.Bool("digests"))
}
format := genImagesFormat(c.String("format"), c.Bool("quiet"), c.Bool("noheading"), c.Bool("digests"))

opts := imagesOptions{
quiet: c.Bool("quiet"),
Expand Down Expand Up @@ -137,7 +132,12 @@ func imagesCmd(c *cli.Context) error {
return generateImagesOutput(runtime, images, opts)
}

func genImagesFormat(quiet, noHeading, digests bool) (format string) {
func genImagesFormat(format string, quiet, noHeading, digests bool) string {
if format != "" {
// "\t" from the command line is not being recognized as a tab
// replacing the string "\t" to a tab character if the user passes in "\t"
return strings.Replace(format, `\t`, "\t", -1)
}
if quiet {
return formats.IDString
}
Expand All @@ -149,7 +149,7 @@ func genImagesFormat(quiet, noHeading, digests bool) (format string) {
format += "{{.Digest}}\t"
}
format += "{{.ID}}\t{{.Created}}\t{{.Size}}\t"
return
return format
}

// imagesToGeneric creates an empty array of interfaces for output
Expand Down
17 changes: 9 additions & 8 deletions cmd/kpod/ps.go
Original file line number Diff line number Diff line change
Expand Up @@ -160,10 +160,7 @@ func psCmd(c *cli.Context) error {
return errors.Errorf("too many arguments, ps takes no arguments")
}

format := genPsFormat(c.Bool("quiet"), c.Bool("size"), c.Bool("namespace"))
if c.IsSet("format") {
format = c.String("format")
}
format := genPsFormat(c.String("format"), c.Bool("quiet"), c.Bool("size"), c.Bool("namespace"))

opts := psOptions{
all: c.Bool("all"),
Expand Down Expand Up @@ -302,19 +299,23 @@ func generateContainerFilterFuncs(filter, filterValue string, runtime *libpod.Ru
}

// generate the template based on conditions given
func genPsFormat(quiet, size, namespace bool) (format string) {
func genPsFormat(format string, quiet, size, namespace bool) string {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This function needs some additional work, since I don't seem to be able to pass multiple options at the same time.
Are these exclusive options? Do I get and error if I pass --format --quiet --size --namespace together?

Probably not related to this PR, but I think this is a potential bug.

if format != "" {
// "\t" from the command line is not being recognized as a tab
// replacing the string "\t" to a tab character if the user passes in "\t"
return strings.Replace(format, `\t`, "\t", -1)
}
if quiet {
return formats.IDString
}
if namespace {
format = "table {{.ID}}\t{{.Names}}\t{{.PID}}\t{{.Cgroup}}\t{{.IPC}}\t{{.MNT}}\t{{.NET}}\t{{.PIDNS}}\t{{.User}}\t{{.UTS}}\t"
return
return "table {{.ID}}\t{{.Names}}\t{{.PID}}\t{{.Cgroup}}\t{{.IPC}}\t{{.MNT}}\t{{.NET}}\t{{.PIDNS}}\t{{.User}}\t{{.UTS}}\t"
}
format = "table {{.ID}}\t{{.Image}}\t{{.Command}}\t{{.CreatedAt}}\t{{.Status}}\t{{.Ports}}\t{{.Names}}\t"
if size {
format += "{{.Size}}\t"
}
return
return format
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice cleanup, missed this earlier.

}

func psToGeneric(templParams []psTemplateParams, JSONParams []psJSONParams) (genericParams []interface{}) {
Expand Down