Skip to content

Commit

Permalink
Merge pull request #36 from platogo/feature/add-label-lists
Browse files Browse the repository at this point in the history
Add label list command
  • Loading branch information
Daniils Petrovs authored Dec 1, 2023
2 parents 8bb4a91 + 29840a1 commit c4247ac
Show file tree
Hide file tree
Showing 12 changed files with 146 additions and 15 deletions.
2 changes: 1 addition & 1 deletion cmd/card_ls.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ var cardLsCmd = &cobra.Command{
cards = client.FetchCards(&query)
}

utils.PrintCards(&cards)
utils.PrintItems(&cards)
},
}

Expand Down
2 changes: 1 addition & 1 deletion cmd/epic_ls.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ var epicLsCmd = &cobra.Command{
if client, err := zube.NewClient(); err == nil {
projectId, _ := cmd.Flags().GetInt("project-id")
epics := client.FetchEpics(projectId)
utils.PrintEpics(&epics)
utils.PrintItems(&epics)
}
},
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import (
"fmt"
"os"

"github.com/logrusorgru/aurora"
"github.com/logrusorgru/aurora/v4"
"github.com/platogo/zube-cli/internal/utils"
"github.com/spf13/cobra"
"github.com/spf13/viper"
Expand Down
36 changes: 36 additions & 0 deletions cmd/label.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/*
Copyright © 2023 Daniils Petrovs <[email protected]>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package cmd

import (
"fmt"

"github.com/spf13/cobra"
)

// labelCmd represents the label command
var labelCmd = &cobra.Command{
Use: "label",
Short: "Manage Zube labels",
Run: func(cmd *cobra.Command, args []string) {
fmt.Println("use 'zube label ls' to list all labels")
},
}

func init() {
rootCmd.AddCommand(labelCmd)
}
52 changes: 52 additions & 0 deletions cmd/label_ls.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
/*
Copyright © 2023 Daniils Petrovs <[email protected]>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package cmd

import (
"log"

"github.com/platogo/zube"
"github.com/platogo/zube-cli/internal/utils"
"github.com/platogo/zube/models"
"github.com/spf13/cobra"
)

// lsCmd represents the ls command
var labelLsCmd = &cobra.Command{
Use: "ls",
Short: "List all Zube labels",
Long: `List all registered labels in a project. Will print the color of the label in supported terminals.`,
Run: func(cmd *cobra.Command, args []string) {
client, _ := zube.NewClient()

var labels []models.Label

if projectId, err := cmd.Flags().GetInt("project-id"); err == nil && projectId != 0 {
labels = client.FetchLabels(projectId)
} else {
log.Fatal("Project ID is required")
}

utils.PrintItems(&labels)
},
}

func init() {
labelCmd.AddCommand(labelLsCmd)

labelLsCmd.Flags().Int("project-id", 0, "Filter by project ID")
}
2 changes: 1 addition & 1 deletion cmd/project_ls.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ var projectLsCmd = &cobra.Command{
client, _ := zube.NewClient()

projects := client.FetchProjects(&zube.Query{})
utils.PrintProjects(&projects)
utils.PrintItems(&projects)
},
}

Expand Down
2 changes: 1 addition & 1 deletion cmd/source_ls.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ var sourceLsCmd = &cobra.Command{
Run: func(cmd *cobra.Command, args []string) {
if client, err := zube.NewClient(); err == nil {
sources := client.FetchSources()
utils.PrintSources(&sources)
utils.PrintItems(&sources)
}
},
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/sprint_ls.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ to quickly create a Cobra application.`,

if workspaceId, err := cmd.Flags().GetInt("workspace-id"); err == nil && workspaceId != 0 {
sprints := client.FetchSprints(workspaceId)
utils.PrintSprints(&sprints)
utils.PrintItems(&sprints)
}
},
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/workspace_ls.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ var workspaceLsCmd = &cobra.Command{
Run: func(cmd *cobra.Command, args []string) {
client, _ := zube.NewClient()
workspaces := client.FetchWorkspaces(&zube.Query{})
utils.PrintWorkspaces(&workspaces)
utils.PrintItems(&workspaces)
},
}

Expand Down
6 changes: 4 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ go 1.20
require (
github.com/AlecAivazis/survey/v2 v2.3.6
github.com/InVisionApp/tabular v0.3.0
github.com/logrusorgru/aurora v2.0.3+incompatible
github.com/gookit/color v1.5.4
github.com/logrusorgru/aurora/v4 v4.0.0
github.com/platogo/cache v1.0.0
github.com/platogo/zube v1.0.0
github.com/samber/lo v1.38.1
Expand All @@ -31,8 +32,9 @@ require (
github.com/spf13/cast v1.5.0 // indirect
github.com/spf13/jwalterweatherman v1.1.0 // indirect
github.com/subosito/gotenv v1.4.2 // indirect
github.com/xo/terminfo v0.0.0-20210125001918-ca9a967f8778 // indirect
golang.org/x/exp v0.0.0-20230321023759-10a507213a29 // indirect
golang.org/x/sys v0.7.0 // indirect
golang.org/x/sys v0.10.0 // indirect
golang.org/x/term v0.7.0 // indirect
golang.org/x/text v0.9.0 // indirect
gopkg.in/ini.v1 v1.67.0 // indirect
Expand Down
14 changes: 9 additions & 5 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,8 @@ github.com/google/uuid v1.1.2/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+
github.com/googleapis/gax-go/v2 v2.0.4/go.mod h1:0Wqv26UfaUD9n4G6kQubkQ+KchISgw+vpHVxEJEs9eg=
github.com/googleapis/gax-go/v2 v2.0.5/go.mod h1:DWXyrwAJ9X0FpwwEdw+IPEYBICEFu5mhpdKc/us6bOk=
github.com/googleapis/google-cloud-go-testing v0.0.0-20200911160855-bcd43fbb19e8/go.mod h1:dvDLG8qkwmyD9a/MJJN3XJcT3xFxOKAvTZGvuZmac9g=
github.com/gookit/color v1.5.4 h1:FZmqs7XOyGgCAxmWyPslpiok1k05wmY3SJTytgvYFs0=
github.com/gookit/color v1.5.4/go.mod h1:pZJOeOS8DM43rXbp4AZo1n9zCU2qjpcRko0b6/QJi9w=
github.com/hashicorp/golang-lru v0.5.0/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ4Ao+sR/qLZy8=
github.com/hashicorp/golang-lru v0.5.1/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ4Ao+sR/qLZy8=
github.com/hashicorp/hcl v1.0.0 h1:0Anlzjpi4vEasTeNFn2mLJgTSwt0+6sfsiTG8qcWGx4=
Expand All @@ -148,8 +150,8 @@ github.com/kr/pretty v0.3.0 h1:WgNl7dwNpEZ6jJ9k1snq4pZsg7DOEN8hP9Xw0Tsjwk0=
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
github.com/logrusorgru/aurora v2.0.3+incompatible h1:tOpm7WcpBTn4fjmVfgpQq0EfczGlG91VSDkswnjF5A8=
github.com/logrusorgru/aurora v2.0.3+incompatible/go.mod h1:7rIyQOR62GCctdiQpZ/zOJlFyk6y+94wXzv6RNZgaR4=
github.com/logrusorgru/aurora/v4 v4.0.0 h1:sRjfPpun/63iADiSvGGjgA1cAYegEWMPCJdUpJYn9JA=
github.com/logrusorgru/aurora/v4 v4.0.0/go.mod h1:lP0iIa2nrnT/qoFXcOZSrZQpJ1o6n2CUf/hyHi2Q4ZQ=
github.com/magiconair/properties v1.8.7 h1:IeQXZAiQcpL9mgcAe1Nu6cX9LLw6ExEHKjN0VQdvPDY=
github.com/magiconair/properties v1.8.7/go.mod h1:Dhd985XPs7jluiymwWYZ0G4Z61jb3vdS329zhj2hYo0=
github.com/markphelps/optional v0.10.0 h1:vTaMRRTuN7aPY5X8g6K82W23qR4VMqBNyniC5BIJlqo=
Expand Down Expand Up @@ -204,10 +206,12 @@ github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU=
github.com/stretchr/testify v1.8.1 h1:w7B6lhMri9wdJUVmEZPGGhZzrYTPvgJArz7wNPgYKsk=
github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4=
github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk=
github.com/subosito/gotenv v1.4.2 h1:X1TuBLAMDFbaTAChgCBLu3DU3UPyELpnF2jjJ2cz/S8=
github.com/subosito/gotenv v1.4.2/go.mod h1:ayKnFf/c6rvx/2iiLrJUk1e6plDbT3edrFNGqEflhK0=
github.com/xo/terminfo v0.0.0-20210125001918-ca9a967f8778 h1:QldyIu/L63oPpyvQmHgvgickp1Yw510KJOqX7H24mg8=
github.com/xo/terminfo v0.0.0-20210125001918-ca9a967f8778/go.mod h1:2MuV+tbUrU1zIOPMxZ5EncGwgmMJsa+9ucAQZXxsObs=
github.com/yuin/goldmark v1.1.25/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
github.com/yuin/goldmark v1.1.27/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
github.com/yuin/goldmark v1.1.32/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
Expand Down Expand Up @@ -351,8 +355,8 @@ golang.org/x/sys v0.0.0-20220422013727-9388b58f7150/go.mod h1:oPkhp1MJrh7nUepCBc
golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220908164124-27713097b956/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.7.0 h1:3jlCCIQZPdOYu1h8BkNvLz8Kgwtae2cagcG/VamtZRU=
golang.org/x/sys v0.7.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.10.0 h1:SqMFp9UcQJZa+pmYuAKjd9xq1f0j5rLcDIk0mj4qAsA=
golang.org/x/sys v0.10.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
golang.org/x/term v0.0.0-20210503060354-a79de5458b56/go.mod h1:tfny5GFUkzUvx4ps4ajbZsCe5lw1metzhBm9T3x7oIY=
golang.org/x/term v0.7.0 h1:BEvjmm5fURWqcfbSKTdpkDXYBrUS1c0m8agp14W48vQ=
Expand Down
39 changes: 38 additions & 1 deletion internal/utils/print.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,36 @@ import (
"unicode/utf8"

"github.com/InVisionApp/tabular"
. "github.com/logrusorgru/aurora"
"github.com/gookit/color"
. "github.com/logrusorgru/aurora/v4"
"github.com/platogo/zube"
"github.com/platogo/zube/models"
"github.com/samber/lo"
)

func PrintItems(items interface{}) {
switch items := items.(type) {
case *[]models.Card:
PrintCards(items)
case *[]models.Comment:
PrintComments(items)
case *[]models.Epic:
PrintEpics(items)
case *[]models.Project:
PrintProjects(items)
case *[]models.Sprint:
PrintSprints(items)
case *[]models.Source:
PrintSources(items)
case *[]models.Label:
PrintLabels(items)
case *[]models.Workspace:
PrintWorkspaces(items)
default:
fmt.Println("Unsupported type")
}
}

func PrintCards(cards *[]models.Card) {
const maxTitleLen = 60

Expand Down Expand Up @@ -155,3 +179,16 @@ func PrintSources(sources *[]models.Source) {
fmt.Printf(format, BrightYellow(source.Id), source.Name)
})
}

func PrintLabels(labels *[]models.Label) {
tab := tabular.New()

tab.Col("id", "ID", 10)
tab.Col("name", "Name", 30)

format := tab.Print("id", "name")
lo.ForEach(*labels, func(label models.Label, _ int) {
hexColor := color.HEX(label.Color, false)
fmt.Printf(format, BrightYellow(label.Id), hexColor.Sprintf("%s", label.Name))
})
}

0 comments on commit c4247ac

Please sign in to comment.