Skip to content

Commit 578d063

Browse files
committed
Use RFC3339 for all printed times.
Short help for release inspect and channel inspect should show required paramters. Use errors.New instead of fmt.Errorf unless formatting.
1 parent 82a6b26 commit 578d063

File tree

10 files changed

+35
-19
lines changed

10 files changed

+35
-19
lines changed

cli/cmd/channel_inspect.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package cmd
22

33
import (
4+
"errors"
45
"fmt"
56

67
"github.com/spf13/cobra"
@@ -10,7 +11,7 @@ import (
1011

1112
// channelInspectCmd represents the channelInspect command
1213
var channelInspectCmd = &cobra.Command{
13-
Use: "inspect",
14+
Use: "inspect CHANNEL_ID",
1415
Short: "Show full details for a channel",
1516
Long: "Show full details for a channel",
1617
}
@@ -21,7 +22,7 @@ func init() {
2122

2223
func (r *runners) channelInspect(cmd *cobra.Command, args []string) error {
2324
if len(args) != 1 {
24-
return fmt.Errorf(cmd.UsageString())
25+
return errors.New("channel ID is required")
2526
}
2627
chanID := args[0]
2728

cli/cmd/channel_rm.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package cmd
22

33
import (
4+
"errors"
45
"fmt"
56

67
"github.com/spf13/cobra"
@@ -19,7 +20,7 @@ func init() {
1920

2021
func (r *runners) channelRemove(cmd *cobra.Command, args []string) error {
2122
if len(args) != 1 {
22-
return fmt.Errorf("channel ID is required")
23+
return errors.New("channel ID is required")
2324
}
2425
chanID := args[0]
2526

cli/cmd/release_inspect.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import (
1212

1313
// releaseInspectCmd represents the inspect command
1414
var releaseInspectCmd = &cobra.Command{
15-
Use: "inspect",
15+
Use: "inspect SEQUENCE",
1616
Short: "Print the YAML config for a release",
1717
Long: "Print the YAML config for a release",
1818
}

cli/cmd/release_promote.go

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
package cmd
22

33
import (
4+
"errors"
45
"fmt"
5-
"os"
66
"strconv"
77

88
"github.com/spf13/cobra"
@@ -14,7 +14,7 @@ var releaseVersion string
1414

1515
// releasePromoteCmd represents the releasePromote command
1616
var releasePromoteCmd = &cobra.Command{
17-
Use: "promote SEQUENCE CHANNEL",
17+
Use: "promote SEQUENCE CHANNEL_ID",
1818
Short: "Set the release for a channel",
1919
Long: `Set the release for a channel
2020
@@ -32,8 +32,7 @@ func init() {
3232
func (r *runners) releasePromote(cmd *cobra.Command, args []string) error {
3333
// parse sequence and channel ID positional arguments
3434
if len(args) != 2 {
35-
cmd.Usage()
36-
os.Exit(1)
35+
return errors.New("releasese sequence and channel ID are required")
3736
}
3837
seq, err := strconv.ParseInt(args[0], 10, 64)
3938
if err != nil {

cli/cmd/release_update.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package cmd
22

33
import (
4+
"errors"
45
"fmt"
56
"strconv"
67

@@ -26,7 +27,7 @@ func (r *runners) releaseUpdate(cmd *cobra.Command, args []string) error {
2627
return fmt.Errorf("yaml is required")
2728
}
2829
if len(args) < 1 {
29-
return fmt.Errorf("release sequence is required")
30+
return errors.New("release sequence is required")
3031
}
3132
seq, err := strconv.ParseInt(args[0], 10, 64)
3233
if err != nil {

cli/print/channel_releases.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,18 @@ package print
22

33
import (
44
"fmt"
5-
"html/template"
65
"text/tabwriter"
6+
"text/template"
77

88
channels "github.com/replicatedhq/replicated/gen/go/channels"
99
)
1010

1111
var channelReleasesTmplSrc = `CHANNEL_SEQUENCE RELEASE_SEQUENCE RELEASED VERSION REQUIRED AIRGAP_STATUS RELEASE_NOTES
1212
{{ range . -}}
13-
{{ .ChannelSequence }} {{ .ReleaseSequence }} {{ .Created }} {{ .Version }} {{ .Required }} {{ .AirgapBuildStatus}} {{ .ReleaseNotes }}
13+
{{ .ChannelSequence }} {{ .ReleaseSequence }} {{ time .Created }} {{ .Version }} {{ .Required }} {{ .AirgapBuildStatus}} {{ .ReleaseNotes }}
1414
{{ end }}`
1515

16-
var channelReleasesTmpl = template.Must(template.New("ChannelReleases").Parse(channelReleasesTmplSrc))
16+
var channelReleasesTmpl = template.Must(template.New("ChannelReleases").Funcs(funcs).Parse(channelReleasesTmplSrc))
1717

1818
func ChannelReleases(w *tabwriter.Writer, releases []channels.ChannelRelease) error {
1919
if len(releases) == 0 {

cli/print/channels.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
package print
22

33
import (
4-
"html/template"
54
"text/tabwriter"
5+
"text/template"
66

77
channels "github.com/replicatedhq/replicated/gen/go/channels"
88
)

cli/print/release.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,13 @@ import (
88
)
99

1010
var releaseTmplSrc = `SEQUENCE: {{ .Sequence }}
11-
CREATED: {{ .CreatedAt }}
12-
EDITED: {{ .EditedAt }}
11+
CREATED: {{ time .CreatedAt }}
12+
EDITED: {{ time .EditedAt }}
1313
CONFIG:
1414
{{ .Config }}
1515
`
1616

17-
var releaseTmpl = template.Must(template.New("Release").Parse(releaseTmplSrc))
17+
var releaseTmpl = template.Must(template.New("Release").Funcs(funcs).Parse(releaseTmplSrc))
1818

1919
func Release(w *tabwriter.Writer, release *releases.AppRelease) error {
2020
if err := releaseTmpl.Execute(w, release); err != nil {

cli/print/releases.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,17 @@ import (
44
"strings"
55
"text/tabwriter"
66
"text/template"
7+
"time"
78

89
releases "github.com/replicatedhq/replicated/gen/go/releases"
910
)
1011

1112
var releasesTmplSrc = `SEQUENCE VERSION CREATED EDITED ACTIVE_CHANNELS
1213
{{ range . -}}
13-
{{ .Sequence }} {{ .Version }} {{ .CreatedAt }} {{ .EditedAt }} {{ .ActiveChannels }}
14+
{{ .Sequence }} {{ .Version }} {{ time .CreatedAt }} {{ .EditedAt }} {{ .ActiveChannels }}
1415
{{ end }}`
1516

16-
var releasesTmpl = template.Must(template.New("Releases").Parse(releasesTmplSrc))
17+
var releasesTmpl = template.Must(template.New("Releases").Funcs(funcs).Parse(releasesTmplSrc))
1718

1819
func Releases(w *tabwriter.Writer, appReleases []releases.AppReleaseInfo) error {
1920
rs := make([]map[string]interface{}, len(appReleases))
@@ -27,7 +28,7 @@ func Releases(w *tabwriter.Writer, appReleases []releases.AppReleaseInfo) error
2728
activeChansField := strings.Join(activeChans, ",")
2829

2930
// don't print edited if it's the same as created
30-
edited := r.EditedAt.String()
31+
edited := r.EditedAt.Format(time.RFC3339)
3132
if r.CreatedAt.Equal(r.EditedAt) {
3233
edited = ""
3334
}

cli/print/util.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package print
2+
3+
import (
4+
"text/template"
5+
"time"
6+
)
7+
8+
var funcs = template.FuncMap{
9+
// Use RFC 3339 for standard time printing in all output
10+
"time": func(t time.Time) string {
11+
return t.Format(time.RFC3339)
12+
},
13+
}

0 commit comments

Comments
 (0)