Shortens the command documentation

This commit is contained in:
Miguel de la Cruz 2020-04-27 12:22:15 +02:00
parent 54a26c7297
commit 5dde18d3ae
9 changed files with 41 additions and 26 deletions

View file

@ -77,7 +77,8 @@ func CsvAddCmd() *cobra.Command {
func AddCmd() *cobra.Command { func AddCmd() *cobra.Command {
cmd := &cobra.Command{ cmd := &cobra.Command{
Use: "add", Use: "add",
Short: "Adds tickets to the campaign from the output of grep/ag/govet", Short: "Adds tickets to the campaign",
Long: "Adds tickets to the campaign from the output of grep/ag/govet",
} }
cmd.AddCommand( cmd.AddCommand(

View file

@ -15,7 +15,8 @@ import (
func InitCmd() *cobra.Command { func InitCmd() *cobra.Command {
cmd := &cobra.Command{ cmd := &cobra.Command{
Use: "init", Use: "init",
Short: "Creates a new campaign in the current directory", Short: "Creates a campaign",
Long: "Creates a new campaign in the current directory",
Example: ` campaigner init \ Example: ` campaigner init \
--jira-username johndoe \ --jira-username johndoe \
--jira-token secret \ --jira-token secret \

View file

@ -43,7 +43,8 @@ func GithubPublishCmd() *cobra.Command {
func PublishCmd() *cobra.Command { func PublishCmd() *cobra.Command {
cmd := &cobra.Command{ cmd := &cobra.Command{
Use: "publish", Use: "publish",
Short: "Publishes the campaign tickets in different providers", Short: "Publishes campaign tickets",
Long: "Publishes the campaign tickets in both Jira and Github",
} }
cmd.AddCommand( cmd.AddCommand(

View file

@ -15,7 +15,7 @@ func RootCmd() *cobra.Command {
cmd.AddCommand( cmd.AddCommand(
AddCmd(), AddCmd(),
FilterCmd(), // FilterCmd(),
InitCmd(), InitCmd(),
StatusCmd(), StatusCmd(),
PublishCmd(), PublishCmd(),

View file

@ -9,7 +9,8 @@ import (
func StatusCmd() *cobra.Command { func StatusCmd() *cobra.Command {
return &cobra.Command{ return &cobra.Command{
Use: "status", Use: "status",
Short: "Prints the current status of the campaign", Short: "Prints the campaign status",
Long: "Prints the current status of the campaign and its tickets",
Args: cobra.NoArgs, Args: cobra.NoArgs,
Run: statusCmdF, Run: statusCmdF,
} }
@ -21,5 +22,5 @@ func statusCmdF(cmd *cobra.Command, _ []string) {
ErrorAndExit(cmd, err) ErrorAndExit(cmd, err)
} }
cmp.PrintStatus(cmd.OutOrStdout()) cmp.PrintStatus()
} }

View file

@ -7,11 +7,16 @@ import (
func SyncCmd() *cobra.Command { func SyncCmd() *cobra.Command {
cmd := &cobra.Command{ cmd := &cobra.Command{
Use: "sync", Use: "sync",
Short: "Synchronizes the status of the tickets with remote providers", Short: "Syncs the tickets",
Long: "Synchronizes the status of the published tickets with remote providers",
Args: cobra.NoArgs, Args: cobra.NoArgs,
Run: syncCmdF, Run: syncCmdF,
} }
cmd.Flags().BoolP("all", "a", false, "syncs all the published tickets")
cmd.Flags().StringP("jira-issue", "j", "", "syncs a ticket by Jira issue number")
cmd.Flags().StringP("github-issue", "g", "", "syncs a ticket by GitHub issue number")
return cmd return cmd
} }

View file

@ -70,7 +70,7 @@ func (c *GithubClient) PublishNextTicket(cmp *model.Campaign, dryRun bool) (bool
return true, nil return true, nil
} }
ticket.GithubLink = *issue.ID ticket.GithubLink = issue.GetNumber()
if err := campaign.Save(cmp); err != nil { if err := campaign.Save(cmp); err != nil {
return false, err return false, err
} }

View file

@ -3,7 +3,6 @@ package model
import ( import (
"bytes" "bytes"
"fmt" "fmt"
"io"
"strings" "strings"
"text/template" "text/template"
) )
@ -34,7 +33,7 @@ type Campaign struct {
func (c *Campaign) NextJiraUnpublishedTicket() *Ticket { func (c *Campaign) NextJiraUnpublishedTicket() *Ticket {
for _, ticket := range c.Tickets { for _, ticket := range c.Tickets {
if ticket.JiraLink == "" { if !ticket.IsPublishedJira() {
return ticket return ticket
} }
} }
@ -43,26 +42,26 @@ func (c *Campaign) NextJiraUnpublishedTicket() *Ticket {
func (c *Campaign) NextGithubUnpublishedTicket() *Ticket { func (c *Campaign) NextGithubUnpublishedTicket() *Ticket {
for _, ticket := range c.Tickets { for _, ticket := range c.Tickets {
if ticket.JiraLink != "" && ticket.GithubLink == 0 { if ticket.IsPublishedJira() && !ticket.IsPublishedGithub() {
return ticket return ticket
} }
} }
return nil return nil
} }
func (c *Campaign) PrintStatus(w io.Writer) { func (c *Campaign) PrintStatus() {
fmt.Fprintf(w, "JIRA URL: %s\n", c.Jira.Url) fmt.Printf("JIRA URL: %s\n", c.Jira.Url)
fmt.Fprintf(w, "JIRA Project: %s\n", c.Jira.Project) fmt.Printf("JIRA Project: %s\n", c.Jira.Project)
fmt.Fprintf(w, "JIRA Epic: %s\n", c.Jira.Epic) fmt.Printf("JIRA Epic: %s\n", c.Jira.Epic)
fmt.Fprintf(w, "JIRA Issue Type: %s\n", c.Jira.IssueType) fmt.Printf("JIRA Issue Type: %s\n", c.Jira.IssueType)
fmt.Fprintf(w, "GitHub Repo: %s\n", c.Github.Repo) fmt.Printf("GitHub Repo: %s\n", c.Github.Repo)
fmt.Fprintf(w, "GitHub Labels: %s\n", c.Github.Labels) fmt.Printf("GitHub Labels: %s\n", c.Github.Labels)
fmt.Fprintf(w, "Summary: %s\n", c.Summary) fmt.Printf("Summary: %s\n", c.Summary)
fmt.Fprintf(w, "Template: %s\n", c.Template) fmt.Printf("Template: %s\n", c.Template)
fmt.Fprintln(w, "") fmt.Println("")
for _, ticket := range c.Tickets { for _, ticket := range c.Tickets {
ticket.PrintStatus(w) ticket.PrintStatus()
} }
} }

View file

@ -2,11 +2,10 @@ package model
import ( import (
"fmt" "fmt"
"io"
) )
type Ticket struct { type Ticket struct {
GithubLink int64 `json:"github_link,omitempty"` GithubLink int `json:"github_link,omitempty"`
GithubStatus string `json:"github_status,omitempty"` GithubStatus string `json:"github_status,omitempty"`
JiraLink string `json:"jira_link,omitempty"` JiraLink string `json:"jira_link,omitempty"`
JiraStatus string `json:"jira_status,omitempty"` JiraStatus string `json:"jira_status,omitempty"`
@ -35,8 +34,16 @@ func RemoveDuplicateTickets(tickets []*Ticket, fileOnly bool) []*Ticket {
return cleanTickets return cleanTickets
} }
func (t *Ticket) PrintStatus(w io.Writer) { func (t *Ticket) IsPublishedJira() bool {
return t.JiraLink != ""
}
func (t *Ticket) IsPublishedGithub() bool {
return t.JiraLink != "" && t.GithubLink != 0
}
func (t *Ticket) PrintStatus() {
if t.Summary != "" { if t.Summary != "" {
fmt.Fprintf(w, "[%s] %s\n", t.JiraLink, t.Summary) fmt.Printf("[%s] %s\n", t.JiraLink, t.Summary)
} }
} }