diff --git a/cmd/helm/search_repo.go b/cmd/helm/search_repo.go index 7664ccd89..88c497fa4 100644 --- a/cmd/helm/search_repo.go +++ b/cmd/helm/search_repo.go @@ -73,6 +73,7 @@ type searchRepoOptions struct { repoCacheDir string outputFormat output.Format failOnNoResult bool + withTimeStamps bool } func newSearchRepoCmd(out io.Writer) *cobra.Command { @@ -96,6 +97,7 @@ func newSearchRepoCmd(out io.Writer) *cobra.Command { f.StringVar(&o.version, "version", "", "search using semantic versioning constraints on repositories you have added") f.UintVar(&o.maxColWidth, "max-col-width", 50, "maximum column width for output table") f.BoolVar(&o.failOnNoResult, "fail-on-no-result", false, "search fails if no results are found") + f.BoolVar(&o.withTimeStamps, "with-timestamps", false, "print created timestamps on output table") bindOutputFlag(cmd, &o.outputFormat) @@ -127,7 +129,7 @@ func (o *searchRepoOptions) run(out io.Writer, args []string) error { return err } - return o.outputFormat.Write(out, &repoSearchWriter{data, o.maxColWidth, o.failOnNoResult}) + return o.outputFormat.Write(out, &repoSearchWriter{data, o.maxColWidth, o.failOnNoResult, o.withTimeStamps}) } func (o *searchRepoOptions) setupSearchedVersion() { @@ -205,12 +207,14 @@ type repoChartElement struct { Version string `json:"version"` AppVersion string `json:"app_version"` Description string `json:"description"` + Created string `json:"created"` } type repoSearchWriter struct { results []*search.Result columnWidth uint failOnNoResult bool + withTimestamps bool } func (r *repoSearchWriter) WriteTable(out io.Writer) error { @@ -228,9 +232,17 @@ func (r *repoSearchWriter) WriteTable(out io.Writer) error { } table := uitable.New() table.MaxColWidth = r.columnWidth - table.AddRow("NAME", "CHART VERSION", "APP VERSION", "DESCRIPTION", "CREATED") - for _, r := range r.results { - table.AddRow(r.Name, r.Chart.Version, r.Chart.AppVersion, r.Chart.Description, r.Chart.Created.Format(time.RFC3339)) + if r.withTimestamps { + table.AddRow("NAME", "CHART VERSION", "APP VERSION", "DESCRIPTION", "CREATED") + } else { + table.AddRow("NAME", "CHART VERSION", "APP VERSION", "DESCRIPTION") + } + for _, ret := range r.results { + if r.withTimestamps { + table.AddRow(ret.Name, ret.Chart.Version, ret.Chart.AppVersion, ret.Chart.Description, ret.Chart.Created.Format(time.RFC3339)) + } else { + table.AddRow(ret.Name, ret.Chart.Version, ret.Chart.AppVersion, ret.Chart.Description) + } } return output.EncodeTable(out, table) } @@ -253,7 +265,7 @@ func (r *repoSearchWriter) encodeByFormat(out io.Writer, format output.Format) e chartList := make([]repoChartElement, 0, len(r.results)) for _, r := range r.results { - chartList = append(chartList, repoChartElement{r.Name, r.Chart.Version, r.Chart.AppVersion, r.Chart.Description}) + chartList = append(chartList, repoChartElement{r.Name, r.Chart.Version, r.Chart.AppVersion, r.Chart.Description, r.Chart.Created.Format(time.RFC3339)}) } switch format { diff --git a/cmd/helm/search_repo_test.go b/cmd/helm/search_repo_test.go index 9039842f0..344f41bf9 100644 --- a/cmd/helm/search_repo_test.go +++ b/cmd/helm/search_repo_test.go @@ -86,6 +86,10 @@ func TestSearchRepositoriesCmd(t *testing.T) { name: "search for 'alpine', expect valid yaml output", cmd: "search repo alpine --output yaml", golden: "output/search-output-yaml.txt", + }, { + name: "search for 'alpine' with timestamps, expect valid table output with timestamps", + cmd: "search repo alpine --with-timestamps", + golden: "output/search-output-timestamps.txt", }} settings.Debug = true diff --git a/cmd/helm/testdata/output/search-output-json.txt b/cmd/helm/testdata/output/search-output-json.txt index 9b211e1b5..7e64d9ebc 100644 --- a/cmd/helm/testdata/output/search-output-json.txt +++ b/cmd/helm/testdata/output/search-output-json.txt @@ -1 +1 @@ -[{"name":"testing/mariadb","version":"0.3.0","app_version":"","description":"Chart for MariaDB"}] +[{"name":"testing/mariadb","version":"0.3.0","app_version":"","description":"Chart for MariaDB","created":"2018-04-23T08:20:27Z"}] diff --git a/cmd/helm/testdata/output/search-output-timestamps.txt b/cmd/helm/testdata/output/search-output-timestamps.txt new file mode 100644 index 000000000..17e310872 --- /dev/null +++ b/cmd/helm/testdata/output/search-output-timestamps.txt @@ -0,0 +1,2 @@ +NAME CHART VERSION APP VERSION DESCRIPTION CREATED +testing/alpine 0.2.0 2.3.4 Deploy a basic Alpine Linux pod 2018-07-09T11:34:37Z diff --git a/cmd/helm/testdata/output/search-output-yaml.txt b/cmd/helm/testdata/output/search-output-yaml.txt index 122b7f345..1f925a5b3 100644 --- a/cmd/helm/testdata/output/search-output-yaml.txt +++ b/cmd/helm/testdata/output/search-output-yaml.txt @@ -1,4 +1,5 @@ - app_version: 2.3.4 + created: "2018-07-09T11:34:37Z" description: Deploy a basic Alpine Linux pod name: testing/alpine version: 0.2.0