From 5f258547df86c04eb2b340fdb3825b387063f706 Mon Sep 17 00:00:00 2001 From: mms-gianni Date: Wed, 3 Mar 2021 17:59:19 +0100 Subject: [PATCH] fix some move shortcuts --- README.md | 11 ++++++++--- commands/move.go | 2 +- common/githubcommands.go | 26 +++++++++++++++++++------- 3 files changed, 28 insertions(+), 11 deletions(-) diff --git a/README.md b/README.md index 1ac07b3..4c83152 100644 --- a/README.md +++ b/README.md @@ -34,13 +34,13 @@ You find older releases here : https://github.com/mms-gianni/git-project/release ### Create your first personl project in your profile ``` -git project create -u +git project open -u ``` ### Create a repository related project ``` cd your-project -git project create +git project open ``` ### Add a new task to a project @@ -75,10 +75,15 @@ git project list ``` ``` -git project help create +git project help open ``` ### create a personal list with one shot ``` git project create shoppinglist -p -d "helps me to remember what to buy" ``` + +### move a card arround +``` +git project move shoppinglist -c milk -d done +``` \ No newline at end of file diff --git a/commands/move.go b/commands/move.go index f3a0b19..590a552 100644 --- a/commands/move.go +++ b/commands/move.go @@ -14,7 +14,7 @@ func cmdMove() *clif.Command { return clif.NewCommand("move", "Move a card to anoter column", cb). NewArgument("project", "Name of the project", "", false, false). NewOption("card", "c", "Selected cards", "", false, false). - NewOption("destinateion", "d", "destination column", "closed", false, false) + NewOption("destination", "d", "Destination column", "", false, false) } func init() { diff --git a/common/githubcommands.go b/common/githubcommands.go index 1de7324..51cc254 100644 --- a/common/githubcommands.go +++ b/common/githubcommands.go @@ -180,14 +180,15 @@ func MoveCard(c *clif.Command, out clif.Output, in clif.Input) { selectedProject := selectProject(client, in, c.Argument("project").String()) var selectedCard *github.ProjectCard + cards := getCards(client, selectedProject) if c.Option("card").String() == "" { - selectedCard = selectCard(client, in, selectedProject) + selectedCard = selectCard(cards, in) + } else { + selectedCard = selectCardByNote(cards, c.Option("card").String()) } var selectedColumn *github.ProjectColumn - if c.Option("card").String() == "" { - selectedColumn = selectColumn(client, in, selectedProject) - } + selectedColumn = selectColumn(client, in, selectedProject, c.Option("destination").String()) _, err := client.Projects.MoveProjectCard(ctx, selectedCard.GetID(), &github.ProjectCardMoveOptions{Position: "bottom", ColumnID: selectedColumn.GetID()}) @@ -213,22 +214,24 @@ func CreateCard(c *clif.Command, in clif.Input, out clif.Output) { } } -func selectColumn(client *github.Client, in clif.Input, project *github.Project) *github.ProjectColumn { +func selectColumn(client *github.Client, in clif.Input, project *github.Project, searchColumn string) *github.ProjectColumn { choices := make(map[string]string) columns, _, _ := client.Projects.ListProjectColumns(ctx, project.GetID(), nil) for key, column := range columns { choices[strconv.Itoa(key)] = "<" + column.GetName() + ">" + if column.GetName() == searchColumn { + return column + } } selectedNr, _ := strconv.Atoi(in.Choose("Select column to move the card", choices)) return columns[selectedNr] } -func selectCard(client *github.Client, in clif.Input, project *github.Project) *github.ProjectCard { +func selectCard(cards []*github.ProjectCard, in clif.Input) *github.ProjectCard { choices := make(map[string]string) - cards := getCards(client, project) for key, card := range cards { choices[strconv.Itoa(key)] = "<" + card.GetColumnName() + "> " + card.GetNote() } @@ -237,6 +240,15 @@ func selectCard(client *github.Client, in clif.Input, project *github.Project) * return cards[selectedNr] } +func selectCardByNote(cards []*github.ProjectCard, searchedCard string) *github.ProjectCard { + for _, card := range cards { + if card.GetNote() == searchedCard { + return card + } + } + return nil +} + func selectProject(client *github.Client, in clif.Input, preselectedProject string) *github.Project { choices := make(map[string]string)