mirror of https://github.com/helm/helm.git
rename to time format flag
Signed-off-by: Abhilash Gnan <abhilashgnan@gmail.com>
This commit is contained in:
parent
190e0b4a81
commit
c5e9732a9f
|
@ -105,17 +105,17 @@ func newListCmd(cfg *action.Configuration, out io.Writer) *cobra.Command {
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
default:
|
default:
|
||||||
return outfmt.Write(out, newReleaseListWriter(results, client.FormatTime))
|
return outfmt.Write(out, newReleaseListWriter(results, client.TimeFormat))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return outfmt.Write(out, newReleaseListWriter(results, client.FormatTime))
|
return outfmt.Write(out, newReleaseListWriter(results, client.TimeFormat))
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
f := cmd.Flags()
|
f := cmd.Flags()
|
||||||
f.BoolVarP(&client.Short, "short", "q", false, "output short (quiet) listing format")
|
f.BoolVarP(&client.Short, "short", "q", false, "output short (quiet) listing format")
|
||||||
f.BoolVar(&client.FormatTime, "format-time", false, "format time")
|
f.StringVar(&client.TimeFormat, "time-format", "", "format time. Example: --time-format 2009-11-17 20:34:10 +0000 UTC")
|
||||||
f.BoolVarP(&client.ByDate, "date", "d", false, "sort by release date")
|
f.BoolVarP(&client.ByDate, "date", "d", false, "sort by release date")
|
||||||
f.BoolVarP(&client.SortReverse, "reverse", "r", false, "reverse the sort order")
|
f.BoolVarP(&client.SortReverse, "reverse", "r", false, "reverse the sort order")
|
||||||
f.BoolVarP(&client.All, "all", "a", false, "show all releases without any filter applied")
|
f.BoolVarP(&client.All, "all", "a", false, "show all releases without any filter applied")
|
||||||
|
@ -149,7 +149,7 @@ type releaseListWriter struct {
|
||||||
releases []releaseElement
|
releases []releaseElement
|
||||||
}
|
}
|
||||||
|
|
||||||
func newReleaseListWriter(releases []*release.Release, formatTime bool) *releaseListWriter {
|
func newReleaseListWriter(releases []*release.Release, timeFormat string) *releaseListWriter {
|
||||||
// Initialize the array so no results returns an empty array instead of null
|
// Initialize the array so no results returns an empty array instead of null
|
||||||
elements := make([]releaseElement, 0, len(releases))
|
elements := make([]releaseElement, 0, len(releases))
|
||||||
for _, r := range releases {
|
for _, r := range releases {
|
||||||
|
@ -164,8 +164,8 @@ func newReleaseListWriter(releases []*release.Release, formatTime bool) *release
|
||||||
|
|
||||||
t := "-"
|
t := "-"
|
||||||
if tspb := r.Info.LastDeployed; !tspb.IsZero() {
|
if tspb := r.Info.LastDeployed; !tspb.IsZero() {
|
||||||
if formatTime {
|
if timeFormat != "" {
|
||||||
t = helmtime.Format(tspb)
|
t = helmtime.Format(tspb, timeFormat)
|
||||||
} else {
|
} else {
|
||||||
t = tspb.String()
|
t = tspb.String()
|
||||||
}
|
}
|
||||||
|
|
|
@ -122,7 +122,7 @@ type List struct {
|
||||||
// Filter is a filter that is applied to the results
|
// Filter is a filter that is applied to the results
|
||||||
Filter string
|
Filter string
|
||||||
Short bool
|
Short bool
|
||||||
FormatTime bool
|
TimeFormat string
|
||||||
Uninstalled bool
|
Uninstalled bool
|
||||||
Superseded bool
|
Superseded bool
|
||||||
Uninstalling bool
|
Uninstalling bool
|
||||||
|
|
|
@ -91,6 +91,6 @@ func (t Time) Truncate(d time.Duration) Time { return Time{Time: t.Time.Truncate
|
||||||
func (t Time) UTC() Time { return Time{Time: t.Time.UTC()} }
|
func (t Time) UTC() Time { return Time{Time: t.Time.UTC()} }
|
||||||
|
|
||||||
// Format formats time in custom output format
|
// Format formats time in custom output format
|
||||||
func Format(t Time) string {
|
func Format(t Time, format string) string {
|
||||||
return t.Format("2006-01-02 15:04:05 -0700 MST")
|
return t.Format(format)
|
||||||
}
|
}
|
||||||
|
|
|
@ -84,8 +84,15 @@ func TestZeroValueUnmarshal(t *testing.T) {
|
||||||
|
|
||||||
func TestFormat(t *testing.T) {
|
func TestFormat(t *testing.T) {
|
||||||
when := Date(2009, 11, 17, 20, 34, 58, 651387237, time.UTC)
|
when := Date(2009, 11, 17, 20, 34, 58, 651387237, time.UTC)
|
||||||
|
|
||||||
expected := "2009-11-17 20:34:58 +0000 UTC"
|
expected := "2009-11-17 20:34:58 +0000 UTC"
|
||||||
got := Format(when)
|
got := Format(when, "2006-01-02 15:04:05 -0700 MST")
|
||||||
|
if expected != got {
|
||||||
|
t.Errorf("expected %s, got %s", expected, got)
|
||||||
|
}
|
||||||
|
|
||||||
|
expected = "2009-11-17 20:34 +0000 UTC"
|
||||||
|
got = Format(when, "2006-01-02 15:04 -0700 MST")
|
||||||
if expected != got {
|
if expected != got {
|
||||||
t.Errorf("expected %s, got %s", expected, got)
|
t.Errorf("expected %s, got %s", expected, got)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue