Skip to content
Merged
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
9 changes: 9 additions & 0 deletions internal/cmd/issue/list/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,9 @@
# List issues in a plain table view and show all fields
$ jira issue list --plain --no-truncate

# List issues in a plain table view using custom delimiter (default is "\t")
$ jira issue list --plain --delimeter "|"

# List issues as raw JSON data
$ jira issue list --raw

Expand Down Expand Up @@ -141,6 +144,10 @@
plain, err := cmd.Flags().GetBool("plain")
cmdutil.ExitIfError(err)


Check failure on line 147 in internal/cmd/issue/list/list.go

View workflow job for this annotation

GitHub Actions / tests

File is not properly formatted (gofmt)
delimiter, err := cmd.Flags().GetString("delimiter")
cmdutil.ExitIfError(err)

csv, err := cmd.Flags().GetBool("csv")
cmdutil.ExitIfError(err)

Expand Down Expand Up @@ -174,6 +181,7 @@
},
Display: view.DisplayFormat{
Plain: plain,
Delimiter: delimiter,
CSV: csv,
NoHeaders: noHeaders,
NoTruncate: noTruncate,
Expand Down Expand Up @@ -236,6 +244,7 @@
cmd.Flags().Bool("plain", false, "Display output in plain mode")
cmd.Flags().Bool("no-headers", false, "Don't display table headers in plain mode. Works only with --plain")
cmd.Flags().Bool("no-truncate", false, "Show all available columns in plain mode. Works only with --plain")
cmd.Flags().String("delimiter", "\t", "Custom delimeter for columns in plain mode. Works only with --plain")
cmd.Flags().Uint("comments", 1, "Show N comments when viewing the issue")
cmd.Flags().Bool("raw", false, "Print raw JSON output")
cmd.Flags().Bool("csv", false, "Print output in CSV format")
Expand Down
4 changes: 2 additions & 2 deletions internal/view/helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -152,13 +152,13 @@
}
}

func renderPlain(w io.Writer, data tui.TableData) error {
func renderPlain(w io.Writer, data tui.TableData, delimiter string) error {
for _, items := range data {
n := len(items)
for j, v := range items {
_, _ = fmt.Fprintf(w, "%s", unescape(v))
if j != n-1 {
_, _ = fmt.Fprintf(w, "\t")
fmt.Fprintf(w, "%s", delimiter)

Check failure on line 161 in internal/view/helper.go

View workflow job for this annotation

GitHub Actions / tests

Error return value of `fmt.Fprintf` is not checked (errcheck)
}
}
_, _ = fmt.Fprintln(w)
Expand Down
14 changes: 10 additions & 4 deletions internal/view/issues.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import (
// DisplayFormat is a issue display type.
type DisplayFormat struct {
Plain bool
Delimiter string
CSV bool
NoHeaders bool
NoTruncate bool
Expand All @@ -40,8 +41,13 @@ type IssueList struct {
// Render renders the view.
func (l *IssueList) Render() error {
if l.Display.Plain || tui.IsDumbTerminal() || tui.IsNotTTY() {
// custom delimiter is used only in plain mode, otherwise \t is used
delimeter := "\t"
if l.Display.Plain {
delimeter = l.Display.Delimiter
}
w := tabwriter.NewWriter(os.Stdout, 0, tabWidth, 1, '\t', 0)
return l.renderPlain(w)
return l.renderPlain(w, delimeter)
}

if l.Display.CSV {
Expand Down Expand Up @@ -129,9 +135,9 @@ func (l *IssueList) Render() error {
return view.Paint(data)
}

// renderPlain renders issues in plain formatted view.
func (l *IssueList) renderPlain(w io.Writer) error {
return renderPlain(w, l.data())
// renderPlain renders the issue in plain view.
func (l *IssueList) renderPlain(w io.Writer, delimeter string) error {
return renderPlain(w, l.data(), delimeter)
}

// renderCSV renders issues in csv format.
Expand Down
31 changes: 27 additions & 4 deletions internal/view/issues_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ func TestIssueRenderInPlainView(t *testing.T) {
NoTruncate: false,
},
}
assert.NoError(t, issue.renderPlain(&b))
assert.NoError(t, issue.renderPlain(&b, "\t"))

expected := `TYPE KEY SUMMARY STATUS
Bug TEST-1 This is a test Done
Expand All @@ -61,6 +61,29 @@ Story TEST-2 This is another test Open
assert.Equal(t, expected, b.String())
}

func TestIssueRenderInPlainViewWithCustomDelimiter(t *testing.T) {
var b bytes.Buffer

issue := IssueList{
Total: 2,
Project: "TEST",
Server: "https://test.local",
Data: getIssues(),
Display: DisplayFormat{
Plain: true,
NoHeaders: false,
NoTruncate: false,
},
}
assert.NoError(t, issue.renderPlain(&b, "|"))

expected := `TYPE|KEY|SUMMARY|STATUS
Bug|TEST-1|This is a test|Done
Story|TEST-2|This is another test|Open
`
assert.Equal(t, expected, b.String())
}

func TestIssueRenderInPlainViewAndNoTruncate(t *testing.T) {
var b bytes.Buffer

Expand All @@ -75,7 +98,7 @@ func TestIssueRenderInPlainViewAndNoTruncate(t *testing.T) {
NoTruncate: true,
},
}
assert.NoError(t, issue.renderPlain(&b))
assert.NoError(t, issue.renderPlain(&b, "\t"))

expected := `TYPE KEY SUMMARY STATUS ASSIGNEE REPORTER PRIORITY RESOLUTION CREATED UPDATED LABELS
Bug TEST-1 This is a test Done Person A Person Z High Fixed 2020-12-13 14:05:20 2020-12-13 14:07:20 krakatit
Expand All @@ -98,7 +121,7 @@ func TestIssueRenderInPlainViewWithoutHeaders(t *testing.T) {
NoTruncate: true,
},
}
assert.NoError(t, issue.renderPlain(&b))
assert.NoError(t, issue.renderPlain(&b, "\t"))

expected := `Bug TEST-1 This is a test Done Person A Person Z High Fixed 2020-12-13 14:05:20 2020-12-13 14:07:20 krakatit
Story TEST-2 This is another test Open Person A Normal 2020-12-13 14:05:20 2020-12-13 14:07:20 pat,mat
Expand All @@ -122,7 +145,7 @@ func TestIssueRenderInPlainViewWithFewColumns(t *testing.T) {
Columns: []string{"key", "type", "status", "created"},
},
}
assert.NoError(t, issue.renderPlain(&b))
assert.NoError(t, issue.renderPlain(&b, "\t"))

expected := `KEY TYPE STATUS CREATED
TEST-1 Bug Done 2020-12-13 14:05:20
Expand Down
3 changes: 2 additions & 1 deletion internal/view/sprint.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,8 @@ func (sl *SprintList) RenderInTable() error {

// renderPlain renders the issue in plain view.
func (sl *SprintList) renderPlain(w io.Writer) error {
return renderPlain(w, sl.tableData())
// sprint view supports only \t as delimiter, not custom.
return renderPlain(w, sl.tableData(), "\t")
}

func (sl *SprintList) data() []tui.PreviewData {
Expand Down
Loading