aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMichael Muré <batolettre@gmail.com>2023-01-18 17:08:02 +0100
committerMichael Muré <batolettre@gmail.com>2023-01-18 19:09:32 +0100
commit3e41812ddb0c1879f9c37a7f952db073b115c85b (patch)
tree9c4bbe3fc62b0fa429a3e0392329d06d0ff47f45
parent248486708911105e7067cb1061607b712c39a60e (diff)
downloadgit-bug-3e41812ddb0c1879f9c37a7f952db073b115c85b.tar.gz
commands: different pattern to detect changed flags
-rw-r--r--commands/bug/bug.go33
-rw-r--r--commands/bug/bug_test.go7
-rw-r--r--doc/man/git-bug-bug.12
-rw-r--r--doc/md/git-bug_bug.md2
4 files changed, 24 insertions, 20 deletions
diff --git a/commands/bug/bug.go b/commands/bug/bug.go
index 4c83ffa5..55a1fa59 100644
--- a/commands/bug/bug.go
+++ b/commands/bug/bug.go
@@ -21,17 +21,18 @@ import (
)
type bugOptions struct {
- statusQuery []string
- authorQuery []string
- metadataQuery []string
- participantQuery []string
- actorQuery []string
- labelQuery []string
- titleQuery []string
- noQuery []string
- sortBy string
- sortDirection string
- outputFormat string
+ statusQuery []string
+ authorQuery []string
+ metadataQuery []string
+ participantQuery []string
+ actorQuery []string
+ labelQuery []string
+ titleQuery []string
+ noQuery []string
+ sortBy string
+ sortDirection string
+ outputFormat string
+ outputFormatChanged bool
}
func NewBugCommand(env *execenv.Env) *cobra.Command {
@@ -57,6 +58,7 @@ git bug status:open --by creation "foo bar" baz
`,
PreRunE: execenv.LoadBackend(env),
RunE: execenv.CloseBackend(env, func(cmd *cobra.Command, args []string) error {
+ options.outputFormatChanged = cmd.Flags().Changed("format")
return runBug(env, options, args)
}),
ValidArgsFunction: completion.Ls(env),
@@ -93,7 +95,7 @@ git bug status:open --by creation "foo bar" baz
flags.StringVarP(&options.sortDirection, "direction", "d", "asc",
"Select the sorting direction. Valid values are [asc,desc]")
cmd.RegisterFlagCompletionFunc("direction", completion.From([]string{"asc", "desc"}))
- flags.StringVarP(&options.outputFormat, "format", "f", "",
+ flags.StringVarP(&options.outputFormat, "format", "f", "default",
"Select the output formatting style. Valid values are [default,plain,id,json,org-mode]")
cmd.RegisterFlagCompletionFunc("format",
completion.From([]string{"default", "plain", "id", "json", "org-mode"}))
@@ -156,14 +158,15 @@ func runBug(env *execenv.Env, opts bugOptions, args []string) error {
}
switch opts.outputFormat {
- case "":
+ case "default":
+ if opts.outputFormatChanged {
+ return bugsDefaultFormatter(env, excerpts)
+ }
if env.Out.IsTerminal() {
return bugsDefaultFormatter(env, excerpts)
} else {
return bugsPlainFormatter(env, excerpts)
}
- case "default":
- return bugsDefaultFormatter(env, excerpts)
case "id":
return bugsIDFormatter(env, excerpts)
case "plain":
diff --git a/commands/bug/bug_test.go b/commands/bug/bug_test.go
index e6fadd6f..6b0aa4e0 100644
--- a/commands/bug/bug_test.go
+++ b/commands/bug/bug_test.go
@@ -72,9 +72,10 @@ $`
env, _ := testenv.NewTestEnvAndBug(t)
opts := bugOptions{
- sortDirection: "asc",
- sortBy: "creation",
- outputFormat: testcase.format,
+ sortDirection: "asc",
+ sortBy: "creation",
+ outputFormat: testcase.format,
+ outputFormatChanged: true, // disable auto-detect
}
require.NoError(t, runBug(env, opts, []string{}))
diff --git a/doc/man/git-bug-bug.1 b/doc/man/git-bug-bug.1
index c9d2bd65..db26518e 100644
--- a/doc/man/git-bug-bug.1
+++ b/doc/man/git-bug-bug.1
@@ -61,7 +61,7 @@ You can pass an additional query to filter and order the list. This query can be
Select the sorting direction. Valid values are [asc,desc]
.PP
-\fB-f\fP, \fB--format\fP=""
+\fB-f\fP, \fB--format\fP="default"
Select the output formatting style. Valid values are [default,plain,id,json,org-mode]
.PP
diff --git a/doc/md/git-bug_bug.md b/doc/md/git-bug_bug.md
index 5b79bb97..0917f654 100644
--- a/doc/md/git-bug_bug.md
+++ b/doc/md/git-bug_bug.md
@@ -42,7 +42,7 @@ git bug status:open --by creation "foo bar" baz
-n, --no strings Filter by absence of something. Valid values are [label]
-b, --by string Sort the results by a characteristic. Valid values are [id,creation,edit] (default "creation")
-d, --direction string Select the sorting direction. Valid values are [asc,desc] (default "asc")
- -f, --format string Select the output formatting style. Valid values are [default,plain,id,json,org-mode]
+ -f, --format string Select the output formatting style. Valid values are [default,plain,id,json,org-mode] (default "default")
-h, --help help for bug
```