aboutsummaryrefslogtreecommitdiffstats
path: root/commands
diff options
context:
space:
mode:
Diffstat (limited to 'commands')
-rw-r--r--commands/commands.go2
-rw-r--r--commands/comment.go2
-rw-r--r--commands/label.go2
-rw-r--r--commands/ls.go98
-rw-r--r--commands/new.go2
-rw-r--r--commands/webui.go3
6 files changed, 106 insertions, 3 deletions
diff --git a/commands/commands.go b/commands/commands.go
index 51aa4e9a..44a08da0 100644
--- a/commands/commands.go
+++ b/commands/commands.go
@@ -50,6 +50,8 @@ var commandsCmd = &cobra.Command{
func init() {
RootCmd.AddCommand(commandsCmd)
+ commandsCmd.Flags().SortFlags = false
+
commandsCmd.Flags().BoolVarP(&commandsDesc, "pretty", "p", false,
"Output the command description as well as Markdown compatible comment",
)
diff --git a/commands/comment.go b/commands/comment.go
index 35937e2b..4c516358 100644
--- a/commands/comment.go
+++ b/commands/comment.go
@@ -73,6 +73,8 @@ var commentCmd = &cobra.Command{
func init() {
RootCmd.AddCommand(commentCmd)
+ commentCmd.Flags().SortFlags = false
+
commentCmd.Flags().StringVarP(&commentMessageFile, "file", "F", "",
"Take the message from the given file. Use - to read the message from the standard input",
)
diff --git a/commands/label.go b/commands/label.go
index 713d9b35..f5e3a6fc 100644
--- a/commands/label.go
+++ b/commands/label.go
@@ -57,6 +57,8 @@ var labelCmd = &cobra.Command{
func init() {
RootCmd.AddCommand(labelCmd)
+ labelCmd.Flags().SortFlags = false
+
labelCmd.Flags().BoolVarP(&labelRemove, "remove", "r", false,
"Remove a label",
)
diff --git a/commands/ls.go b/commands/ls.go
index 79124f7f..4ff4b315 100644
--- a/commands/ls.go
+++ b/commands/ls.go
@@ -9,6 +9,15 @@ import (
"github.com/spf13/cobra"
)
+var (
+ lsStatusQuery []string
+ lsAuthorQuery []string
+ lsLabelQuery []string
+ lsNoQuery []string
+ lsSortBy string
+ lsSortDirection string
+)
+
func runLsBug(cmd *cobra.Command, args []string) error {
backend, err := cache.NewRepoCache(repo)
if err != nil {
@@ -23,6 +32,11 @@ func runLsBug(cmd *cobra.Command, args []string) error {
if err != nil {
return err
}
+ } else {
+ query, err = lsQueryFromFlags()
+ if err != nil {
+ return err
+ }
}
allIds := backend.QueryBugs(query)
@@ -58,12 +72,90 @@ func runLsBug(cmd *cobra.Command, args []string) error {
return nil
}
+// Transform the command flags into a query
+func lsQueryFromFlags() (*cache.Query, error) {
+ query := cache.NewQuery()
+
+ for _, status := range lsStatusQuery {
+ f, err := cache.StatusFilter(status)
+ if err != nil {
+ return nil, err
+ }
+ query.Status = append(query.Status, f)
+ }
+
+ for _, author := range lsAuthorQuery {
+ f := cache.AuthorFilter(author)
+ query.Author = append(query.Author, f)
+ }
+
+ for _, label := range lsLabelQuery {
+ f := cache.LabelFilter(label)
+ query.Label = append(query.Label, f)
+ }
+
+ for _, no := range lsNoQuery {
+ switch no {
+ case "label":
+ query.NoFilters = append(query.NoFilters, cache.NoLabelFilter())
+ default:
+ return nil, fmt.Errorf("unknown \"no\" filter %s", no)
+ }
+ }
+
+ switch lsSortBy {
+ case "id":
+ query.OrderBy = cache.OrderById
+ case "creation":
+ query.OrderBy = cache.OrderByCreation
+ case "edit":
+ query.OrderBy = cache.OrderByEdit
+ default:
+ return nil, fmt.Errorf("unknown sort flag %s", lsSortBy)
+ }
+
+ switch lsSortDirection {
+ case "asc":
+ query.OrderDirection = cache.OrderAscending
+ case "desc":
+ query.OrderDirection = cache.OrderDescending
+ default:
+ return nil, fmt.Errorf("unknown sort direction %s", lsSortDirection)
+ }
+
+ return query, nil
+}
+
var lsCmd = &cobra.Command{
- Use: "ls <query>",
- Short: "Display a summary of all bugs",
- RunE: runLsBug,
+ Use: "ls [<query>]",
+ Short: "List bugs",
+ Long: `Display a summary of each bugs.
+
+You can pass an additional query to filter and order the list. This query can be expressed either with a simple query language or with flags.`,
+ Example: `List open bugs sorted by last edition with a query:
+git bug ls "status:open sort:edit-desc"
+
+List closed bugs sorted by creation with flags:
+git bug ls --status closed --by creation
+`,
+ RunE: runLsBug,
}
func init() {
RootCmd.AddCommand(lsCmd)
+
+ lsCmd.Flags().SortFlags = false
+
+ lsCmd.Flags().StringSliceVarP(&lsStatusQuery, "status", "s", nil,
+ "Filter by status. Valid values are [open,closed]")
+ lsCmd.Flags().StringSliceVarP(&lsAuthorQuery, "author", "a", nil,
+ "Filter by author")
+ lsCmd.Flags().StringSliceVarP(&lsLabelQuery, "label", "l", nil,
+ "Filter by label")
+ lsCmd.Flags().StringSliceVarP(&lsNoQuery, "no", "n", nil,
+ "Filter by absence of something. Valid values are [label]")
+ lsCmd.Flags().StringVarP(&lsSortBy, "by", "b", "creation",
+ "Sort the results by a characteristic. Valid values are [id,creation,edit]")
+ lsCmd.Flags().StringVarP(&lsSortDirection, "direction", "d", "asc",
+ "Select the sorting direction. Valid values are [asc,desc]")
}
diff --git a/commands/new.go b/commands/new.go
index c7846aea..0d68ffd8 100644
--- a/commands/new.go
+++ b/commands/new.go
@@ -61,6 +61,8 @@ var newCmd = &cobra.Command{
func init() {
RootCmd.AddCommand(newCmd)
+ newCmd.Flags().SortFlags = false
+
newCmd.Flags().StringVarP(&newTitle, "title", "t", "",
"Provide a title to describe the issue",
)
diff --git a/commands/webui.go b/commands/webui.go
index f3f9c184..a2da8be7 100644
--- a/commands/webui.go
+++ b/commands/webui.go
@@ -199,5 +199,8 @@ var webUICmd = &cobra.Command{
func init() {
RootCmd.AddCommand(webUICmd)
+
+ webUICmd.Flags().SortFlags = false
+
webUICmd.Flags().IntVarP(&port, "port", "p", 0, "Port to listen to")
}