Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve responses and error handling of commands #37

Merged
merged 2 commits into from
Dec 1, 2023
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
3 changes: 1 addition & 2 deletions cmd/card.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
/*
Copyright © 2022 Daniils Petrovs <[email protected]>

*/
package cmd

Expand All @@ -15,7 +14,7 @@ var cardCmd = &cobra.Command{
Use: "card",
Short: "Manage cards",
Run: func(cmd *cobra.Command, args []string) {
fmt.Println("card called")
fmt.Println("try to use `card ls` to list cards")
},
}

Expand Down
2 changes: 1 addition & 1 deletion cmd/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ var configCmd = &cobra.Command{
Use: "config",
Short: "Zube CLI configuration commands",
Run: func(cmd *cobra.Command, args []string) {
fmt.Println("config called")
fmt.Println("try to use `config init` to initialize the config")
},
}

Expand Down
12 changes: 1 addition & 11 deletions cmd/epic.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,20 +33,10 @@ Cobra is a CLI library for Go that empowers applications.
This application is a tool to generate the needed files
to quickly create a Cobra application.`,
Run: func(cmd *cobra.Command, args []string) {
fmt.Println("epic called")
fmt.Println("Try to call `epic ls` to list all epics")
},
}

func init() {
rootCmd.AddCommand(epicCmd)

// Here you will define your flags and configuration settings.

// Cobra supports Persistent Flags which will work for this command
// and all subcommands, e.g.:
// epicCmd.PersistentFlags().String("foo", "", "A help for foo")

// Cobra supports local flags which will only run when this command
// is called directly, e.g.:
// epicCmd.Flags().BoolP("toggle", "t", false, "Help message for toggle")
}
5 changes: 2 additions & 3 deletions cmd/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ package cmd

import (
"fmt"
"os"
"log"

"github.com/logrusorgru/aurora/v4"
"github.com/platogo/zube-cli/internal/utils"
Expand All @@ -34,8 +34,7 @@ var initCmd = &cobra.Command{
clientId := utils.StringPrompt("Enter your Zube Client ID:")

if clientId == "" {
fmt.Println(aurora.Red("Client ID cannot be blank!"))
os.Exit(1)
log.Fatal(aurora.Red("Client ID cannot be blank!"))
}

viper.Set("client_id", clientId)
Expand Down
2 changes: 1 addition & 1 deletion cmd/project.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ var projectCmd = &cobra.Command{
Use: "project",
Short: "Manage projects",
Run: func(cmd *cobra.Command, args []string) {
fmt.Println("project called")
fmt.Println("try to use `project ls` to list all projects")
},
}

Expand Down
8 changes: 1 addition & 7 deletions cmd/source.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,8 @@ import (
var sourceCmd = &cobra.Command{
Use: "source",
Short: "Manage Zube Github sources",
Long: `A longer description that spans multiple lines and likely contains examples
and usage of using your command. For example:

Cobra is a CLI library for Go that empowers applications.
This application is a tool to generate the needed files
to quickly create a Cobra application.`,
Run: func(cmd *cobra.Command, args []string) {
fmt.Println("source called")
fmt.Println("try to use `source ls` to list all sources")
},
}

Expand Down
20 changes: 2 additions & 18 deletions cmd/sprint.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,28 +25,12 @@ import (
// sprintCmd represents the sprint command
var sprintCmd = &cobra.Command{
Use: "sprint",
Short: "A brief description of your command",
Long: `A longer description that spans multiple lines and likely contains examples
and usage of using your command. For example:

Cobra is a CLI library for Go that empowers applications.
This application is a tool to generate the needed files
to quickly create a Cobra application.`,
Short: "Manage Zube sprints",
Run: func(cmd *cobra.Command, args []string) {
fmt.Println("sprint called")
fmt.Println("try to call `sprint ls` to list all sprints")
},
}

func init() {
rootCmd.AddCommand(sprintCmd)

// Here you will define your flags and configuration settings.

// Cobra supports Persistent Flags which will work for this command
// and all subcommands, e.g.:
// sprintCmd.PersistentFlags().String("foo", "", "A help for foo")

// Cobra supports local flags which will only run when this command
// is called directly, e.g.:
// sprintCmd.Flags().BoolP("toggle", "t", false, "Help message for toggle")
}
12 changes: 5 additions & 7 deletions cmd/sprint_ls.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ 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/spf13/cobra"
Expand All @@ -25,19 +27,15 @@ import (
// sprintLsCmd represents the sprintLs command
var sprintLsCmd = &cobra.Command{
Use: "ls",
Short: "A brief description of your command",
Long: `A longer description that spans multiple lines and likely contains examples
and usage of using your command. For example:

Cobra is a CLI library for Go that empowers applications.
This application is a tool to generate the needed files
to quickly create a Cobra application.`,
Short: "List sprints in a workspace",
Run: func(cmd *cobra.Command, args []string) {
client, _ := zube.NewClient()

if workspaceId, err := cmd.Flags().GetInt("workspace-id"); err == nil && workspaceId != 0 {
sprints := client.FetchSprints(workspaceId)
utils.PrintItems(&sprints)
} else {
log.Fatal("workspace-id is required")
}
},
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/workspace.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ var workspaceCmd = &cobra.Command{
Use: "workspace",
Short: "Manage workspaces",
Run: func(cmd *cobra.Command, args []string) {
fmt.Println("workspace called")
fmt.Println("try to use `workspace ls` to list all workspaces")
},
}

Expand Down
11 changes: 8 additions & 3 deletions internal/utils/print.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
"github.com/samber/lo"
)

// PrintItems prints a slice of items in a formatted table
func PrintItems(items interface{}) {
switch items := items.(type) {
case *[]models.Card:
Expand Down Expand Up @@ -68,7 +69,7 @@ func PrintCard(account *models.Account, project *models.Project, card *models.Ca
var assigneeNames []string

for _, label := range card.Labels {
labels = append(labels, label.Name)
labels = append(labels, printfLabel(label))
}

for _, assignee := range card.Assignees {
Expand Down Expand Up @@ -188,7 +189,11 @@ func PrintLabels(labels *[]models.Label) {

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))
fmt.Printf(format, BrightYellow(label.Id), printfLabel(label))
})
}

func printfLabel(label models.Label) string {
hexColor := color.HEX(label.Color, false)
return hexColor.Sprint(label.Name)
}