Skip to content

Commit

Permalink
Added "bug status" and "bug priority" commands
Browse files Browse the repository at this point in the history
  • Loading branch information
driusan committed Dec 30, 2015
1 parent 5f55d0c commit c5f4f0d
Show file tree
Hide file tree
Showing 16 changed files with 236 additions and 26 deletions.
65 changes: 65 additions & 0 deletions BugApplication.go
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,71 @@ func (a BugApplication) Create(Args []string) {
}
}

func (a BugApplication) Priority(args []string) {
if len(args) < 1 {
fmt.Printf("Usage: %s priority issuenum [set priority]\n", os.Args[0])
return
}

idx, err := strconv.Atoi(args[0])
if err != nil {
fmt.Printf("Invalid issue number. \"%s\" is not a number.\n\n", args[0])
fmt.Printf("Usage: %s priority issuenum [set priority]\n", os.Args[0])
return
}
b, err := bugs.LoadBugByIndex(idx)
if err != nil {
fmt.Printf("Invalid issue number %s\n", args[0])
return
}
if len(args) > 1 {
newPriority := strings.Join(args[1:], " ")
err := b.SetPriority(newPriority)
if err != nil {
fmt.Printf("Error setting priority: %s", err.Error())
}
} else {
priority := b.Priority()
if priority == "" {
fmt.Printf("Priority not defined\n")
} else {
fmt.Printf("%s\n", priority)
}
}
}
func (a BugApplication) Status(args []string) {
if len(args) < 1 {
fmt.Printf("Usage: %s status issuenum [set status]\n", os.Args[0])
return
}

idx, err := strconv.Atoi(args[0])
if err != nil {
fmt.Printf("Invalid bug number. \"%s\" is not a number.\n\n", args[0])
fmt.Printf("Usage: %s status issuenum [set status]\n", os.Args[0])
return
}
b, err := bugs.LoadBugByIndex(idx)
if err != nil {
fmt.Printf("Invalid bug number %s\n", args[0])
return
}
if len(args) > 1 {
newStatus := strings.Join(args[1:], " ")
fmt.Printf("Setting status to %s\n", newStatus)
err := b.SetStatus(newStatus)
if err != nil {
fmt.Printf("Error setting status: %s", err.Error())
}
} else {
status := b.Status()
if status == "" {
fmt.Printf("Status not defined\n")
} else {
fmt.Printf("%s\n", status)
}
}
}
func (a BugApplication) Dir() {
fmt.Printf("%s", bugs.GetRootDir()+"/issues")
}
Expand Down
60 changes: 48 additions & 12 deletions BugHelp.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,35 @@ print any issues which have that tag (in short form)
`This will launch your standard editor to edit the description of the bug numbered
IssueNumber, where IssueNumber is a reference to same index provided with a
"bug list" command.
`)
case "status":
fmt.Printf("Usage: " + os.Args[0] + " status IssueNumber [NewStatus]\n\n")
fmt.Printf(
`This will edit or display the status of the bug numbered IssueNumber.
If NewStatus is provided, it will update the first line of the Status file
for the issue (creating the file as necessary). If not provided, it will
display the first line of the Status file to STDOUT.
Note that you can manually edit the Status file in the issues/ directory
to provide further explanation (for instance, why that status is set.)
This command will preserve the explanation when updating a status.
`)
case "priority":
fmt.Printf("Usage: " + os.Args[0] + " priority IssueNumber [NewPriority]\n\n")
fmt.Printf(
`This will edit or display the priority of the bug numbered IssueNumber.
By convention, priorities should be an integer number (higher is more
urgent), but that is not enforced by this command and NewPriority can
be any free-form text if you prefer.
If NewPriority is provided, it will update the first line of the Priority
file for the issue (creating the file as necessary). If not provided, it
will display the first line of the Priority file to STDOUT.
Note that you can manually edit the Priority file in the issues/ directory
to provide further explanation (for instance, why that priority is set.)
This command will preserve the explanation when updating a priority.
`)
case "rm":
fallthrough
Expand Down Expand Up @@ -107,17 +136,24 @@ Tags can be any string which would make a valid file name.
fmt.Printf("Usage: " + os.Args[0] + " command [options]\n\n")
fmt.Printf("Use \"bug help [command]\" for more information about any command below\n\n")
fmt.Printf("Valid commands\n")
fmt.Printf("\tcreate\tFile a new bug\n")
fmt.Printf("\tlist\tList existing bugs\n")
fmt.Printf("\tedit\tEdit an existing bug\n")
fmt.Printf("\ttag\tTag a bug with a category\n")
fmt.Printf("\tclose\tDelete an existing bug\n")
fmt.Printf("\tcommit\tCommit any new, changed or deleted bug to git\n")
fmt.Printf("\tpurge\tRemove all issues not tracked by git\n")
fmt.Printf("\trm\tAlias of close\n")
fmt.Printf("\tenv\tShow settings that bug will use if invoked from this directory\n")
fmt.Printf("\tdir\tPrints the issues directory to stdout (useful subcommand in the shell)\n")
fmt.Printf("\tpwd\tAlias of dir\n")
fmt.Printf("\thelp\tShow this screen\n")
fmt.Printf("\nIssue editing commands:\n")
fmt.Printf("\tcreate\t File a new bug\n")
fmt.Printf("\tlist\t List existing bugs\n")
fmt.Printf("\tedit\t Edit an existing bug\n")
fmt.Printf("\ttag\t Tag a bug with a category\n")
fmt.Printf("\tclose\t Delete an existing bug\n")
fmt.Printf("\trm\t Alias of close\n")
fmt.Printf("\tstatus\t View or edit a bug's status\n")
fmt.Printf("\tpriority View or edit a bug's priority\n")

fmt.Printf("\nSource control commands:\n")
fmt.Printf("\tcommit\t Commit any new, changed or deleted bug to git\n")
fmt.Printf("\tpurge\t Remove all issues not tracked by git\n")

fmt.Printf("\nOther commands:\n")
fmt.Printf("\tenv\t Show settings that bug will use if invoked from this directory\n")
fmt.Printf("\tdir\t Prints the issues directory to stdout (useful subcommand in the shell)\n")
fmt.Printf("\tpwd\t Alias of dir\n")
fmt.Printf("\thelp\t Show this screen\n")
}
}
31 changes: 20 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,17 +21,26 @@ Usage: bug command [options]
Use "bug help [command]" for more information about any command below
Valid commands
create File a new bug
list List existing bugs
edit Edit an existing bug
close Delete an existing bug
commit Commit any new, changed or deleted bug to git
purge Remove all issues not tracked by git
rm Alias of close
env Show settings that bug will use if invoked from this directory
dir Prints the issues directory to stdout (useful subcommand in the shell)
pwd Alias of dir
help Show this screen
Issue editing commands:
create File a new bug
list List existing bugs
edit Edit an existing bug
tag Tag a bug with a category
close Delete an existing bug
rm Alias of close
status View or edit a bug's status
priority View or edit a bug's priority
Source control commands:
commit Commit any new, changed or deleted bug to git
purge Remove all issues not tracked by git
Other commands:
env Show settings that bug will use if invoked from this directory
dir Prints the issues directory to stdout (useful subcommand in the shell)
pwd Alias of dir
help Show this screen
$ bug create I don't know what I'm doing
# (Your standard editor will open here for you to enter a description, save it when you're done)
Expand Down
60 changes: 60 additions & 0 deletions bugs/Bug.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,19 @@ func (b Bug) ViewBug() {
fmt.Printf("Title: %s\n\n", b.Title)
fmt.Printf("Description:\n%s", b.Description)

status := b.Status()
if status != "" {
fmt.Printf("\nStatus: %s", status)
}
priority := b.Priority()
if priority != "" {
fmt.Printf("\nPriority: %s", priority)
}
tags := b.Tags()
if tags != nil {
fmt.Printf("\nTags: %s", strings.Join(tags, ", "))
}

}

func (b Bug) Tags() []string {
Expand All @@ -68,3 +77,54 @@ func (b Bug) Tags() []string {
return tags

}

func (b Bug) getField(fieldName string) string {
dir, _ := b.GetDirectory()
field, err := ioutil.ReadFile(string(dir) + "/" + fieldName)
if err != nil {
return ""
}
lines := strings.Split(string(field), "\n")
if len(lines) > 0 {
return strings.TrimSpace(lines[0])
}
return ""
}

func (b Bug) setField(fieldName, value string) error {
dir, _ := b.GetDirectory()
oldValue, err := ioutil.ReadFile(string(dir) + "/" + fieldName)
var oldLines []string
if err == nil {
oldLines = strings.Split(string(oldValue), "\n")
}

newValue := ""
if len(oldLines) >= 1 {
// If there were 0 or 1 old lines, overwrite them
oldLines[0] = value
newValue = strings.Join(oldLines, "\n")
} else {
newValue = value
}

err = ioutil.WriteFile(string(dir)+"/"+fieldName, []byte(newValue), 0644)
if err != nil {
return err
}
return nil
}
func (b Bug) Status() string {
return b.getField("Status")
}

func (b Bug) SetStatus(newStatus string) error {
return b.setField("Status", newStatus)
}
func (b Bug) Priority() string {
return b.getField("Priority")
}

func (b Bug) SetPriority(newValue string) error {
return b.setField("Priority", newValue)
}
22 changes: 22 additions & 0 deletions bugs/Find.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,27 @@
package bugs

import (
"fmt"
"io/ioutil"
)

type BugNotFoundError string

func (b BugNotFoundError) Error() string {
return "Bug not found"
}
func FindBugsByTag(tags []string) []Bug {
return []Bug{}
}

func LoadBugByIndex(idx int) (*Bug, error) {
issues, _ := ioutil.ReadDir(string(GetRootDir()) + "/issues")
if idx < 1 || idx > len(issues) {
return nil, BugNotFoundError("Invalid Index")
}

b := Bug{}
directoryString := fmt.Sprintf("%s%s%s", GetRootDir(), "/issues/", issues[idx-1].Name())
b.LoadBug(Directory(directoryString))
return &b, nil
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
It would be nice to support things other than
git as a storage engine. In particular, a
BugsEverywhere user requested hg support.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
open

This file was deleted.

4 changes: 4 additions & 0 deletions issues/Should-have-bug-relabel-command/Description
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
There is currently no way to update a bug's title. There
should be a relabel command to make it easier to change
the title of a bug without manually doing a mv and commiting
to source control
7 changes: 7 additions & 0 deletions issues/Should-have-milestone-and-roadmap-command/Description
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
There should be a command to add a milestone to issues, and
another command to display all issues sorted by milestone
(and subsorted by priority?) in markdown (or other easy, human
readable) format.

Then there can be a git hook to generate a roadmap automatically
on commit.
2 changes: 2 additions & 0 deletions issues/bug-tag-with-no-arguments/Description
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
"bug tag" with no arguments should print a show usage
line. It should also display all currently in use tags.
Empty file.
Empty file.
4 changes: 4 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@ func main() {
fallthrough
case "list":
app.List(os.Args[2:])
case "priority":
app.Priority(os.Args[2:])
case "status":
app.Status(os.Args[2:])
case "tag":
app.Tag(os.Args[2:])
case "purge":
Expand Down

0 comments on commit c5f4f0d

Please sign in to comment.