Repositories

This change makes the CLI consistent for all of the review subcommands.

Specifically:

  1. The usage strings for every command follow a consistent format.
  2. The "comment" command now takes the file and line as flags, and allows the review hash to be provided as a positional argument.

The change to the "comment" command is backwards-incompatible. Scripts that relied on being able to pass the file and line number as positional arguments will no longer work with this new version.

To mitigate the issues with that; the previous commit has been tagged as version "v0.1", so that users who need the previous behavior can always install the older version of the tool.

Modified commands/accept.go

@@ -72,7 +72,7 @@ func acceptReview(repo repository.Repo, args []string) error {
// acceptCmd defines the "accept" subcommand.
var acceptCmd = &Command{
Usage: func(arg0 string) {
fmt.Printf("Usage: %s accept <option>... (<commit>)\n\nOptions:\n", arg0)
fmt.Printf("Usage: %s accept [<option>...] [<commit>]\n\nOptions:\n", arg0)
acceptFlagSet.PrintDefaults()
},
RunMethod: func(repo repository.Repo, args []string) error {

Modified commands/comment.go

@@ -23,56 +23,70 @@ import (
"github.com/google/git-appraise/repository"
"github.com/google/git-appraise/review"
"github.com/google/git-appraise/review/comment"
"strconv"
)
var commentFlagSet = flag.NewFlagSet("comment", flag.ExitOnError)
var (
commentMessage = commentFlagSet.String("m", "", "Message to attach to the review")
parent = commentFlagSet.String("p", "", "Parent comment")
lgtm = commentFlagSet.Bool("lgtm", false, "'Looks Good To Me'. Set this to express your approval. This cannot be combined with nmw")
nmw = commentFlagSet.Bool("nmw", false, "'Needs More Work'. Set this to express your disapproval. This cannot be combined with lgtm")
commentParent = commentFlagSet.String("p", "", "Parent comment")
commentFile = commentFlagSet.String("f", "", "File being commented upon")
commentLine = commentFlagSet.Uint("l", 0, "Line being commented upon; requires that the -f flag also be set")
commentLgtm = commentFlagSet.Bool("lgtm", false, "'Looks Good To Me'. Set this to express your approval. This cannot be combined with nmw")
commentNmw = commentFlagSet.Bool("nmw", false, "'Needs More Work'. Set this to express your disapproval. This cannot be combined with lgtm")
)
// commentOnReview adds a comment to the current code review.
func commentOnReview(repo repository.Repo, args []string) error {
commentFlagSet.Parse(args)
args = commentFlagSet.Args()
if *lgtm && *nmw {
if *commentLgtm && *commentNmw {
return errors.New("You cannot combine the flags -lgtm and -nmw.")
}
if *commentLine != 0 && *commentFile == "" {
return errors.New("Specifying a line number with the -l flag requires that you also specify a file name with the -f flag.")
}
var r *review.Review
var err error
if len(args) > 1 {
return errors.New("Only accepting a single review is supported.")
}
if len(args) == 1 {
r = review.Get(repo, args[0])
} else {
r, err = review.GetCurrent(repo)
}
r, err := review.GetCurrent(repo)
if err != nil {
return fmt.Errorf("Failed to load the current review: %v\n", err)
return fmt.Errorf("Failed to load the review: %v\n", err)
}
if r == nil {
return errors.New("There is no current review.")
return errors.New("There is no matching review.")
}
commentedUponCommit := repo.GetCommitHash(r.Request.ReviewRef)
commentedUponCommit, err := r.GetHeadCommit()
if err != nil {
return err
}
location := comment.Location{
Commit: commentedUponCommit,
}
if len(args) > 0 {
location.Path = args[0]
if len(args) > 1 {
startLine, err := strconv.ParseUint(args[1], 0, 32)
if err != nil {
return err
}
if *commentFile != "" {
location.Path = *commentFile
if *commentLine != 0 {
location.Range = &comment.Range{
StartLine: uint32(startLine),
StartLine: uint32(*commentLine),
}
}
}
c := comment.New(repo.GetUserEmail(), *commentMessage)
c.Location = &location
c.Parent = *parent
if *lgtm || *nmw {
resolved := *lgtm
c.Parent = *commentParent
if *commentLgtm || *commentNmw {
resolved := *commentLgtm
c.Resolved = &resolved
}
return r.AddComment(c)
@@ -81,7 +95,7 @@ func commentOnReview(repo repository.Repo, args []string) error {
// commentCmd defines the "comment" subcommand.
var commentCmd = &Command{
Usage: func(arg0 string) {
fmt.Printf("Usage: %s comment <option>... [<file> [<line>]]\n\nOptions:\n", arg0)
fmt.Printf("Usage: %s comment [<option>...] [<review-hash>]\n\nOptions:\n", arg0)
commentFlagSet.PrintDefaults()
},
RunMethod: func(repo repository.Repo, args []string) error {

Modified commands/list.go

@@ -49,7 +49,7 @@ func listReviews(repo repository.Repo, args []string) {
// listCmd defines the "list" subcommand.
var listCmd = &Command{
Usage: func(arg0 string) {
fmt.Printf("Usage: %s list <option>...\n\nOptions:\n", arg0)
fmt.Printf("Usage: %s list [<option>...]\n\nOptions:\n", arg0)
listFlagSet.PrintDefaults()
},
RunMethod: func(repo repository.Repo, args []string) error {

Modified commands/request.go

@@ -101,7 +101,7 @@ func requestReview(repo repository.Repo, args []string) error {
// requestCmd defines the "request" subcommand.
var requestCmd = &Command{
Usage: func(arg0 string) {
fmt.Printf("Usage: %s request <option>...\n\nOptions:\n", arg0)
fmt.Printf("Usage: %s request [<option>...]\n\nOptions:\n", arg0)
requestFlagSet.PrintDefaults()
},
RunMethod: func(repo repository.Repo, args []string) error {

Modified commands/show.go

@@ -72,7 +72,7 @@ func showReview(repo repository.Repo, args []string) error {
// showCmd defines the "show" subcommand.
var showCmd = &Command{
Usage: func(arg0 string) {
fmt.Printf("Usage: %s show <option>... (<commit>)\n\nOptions:\n", arg0)
fmt.Printf("Usage: %s show [<option>...] [<commit>]\n\nOptions:\n", arg0)
showFlagSet.PrintDefaults()
},
RunMethod: func(repo repository.Repo, args []string) error {

Modified commands/submit.go

@@ -77,7 +77,7 @@ func submitReview(repo repository.Repo, args []string) error {
// submitCmd defines the "submit" subcommand.
var submitCmd = &Command{
Usage: func(arg0 string) {
fmt.Printf("Usage: %s submit <option>...\n\nOptions:\n", arg0)
fmt.Printf("Usage: %s submit [<option>...]\n\nOptions:\n", arg0)
submitFlagSet.PrintDefaults()
},
RunMethod: func(repo repository.Repo, args []string) error {