Пример #1
0
// showReview prints the current code review.
func showReview(args []string) error {
	showFlagSet.Parse(args)
	args = showFlagSet.Args()

	var r *review.Review
	var err error
	if len(args) > 1 {
		return errors.New("Only showing a single review is supported.")
	}

	if len(args) == 1 {
		r = review.Get(args[0])
	} else {
		r, err = review.GetCurrent()
	}

	if err != nil {
		return fmt.Errorf("Failed to load the review: %v\n", err)
	}
	if r == nil {
		return errors.New("There is no matching review.")
	}
	if *showJsonOutput {
		return r.PrintJson()
	}
	return r.PrintDetails()
}
Пример #2
0
// showReview prints the current code review.
func showReview(repo repository.Repo, args []string) error {
	showFlagSet.Parse(args)
	args = showFlagSet.Args()
	if *showDiffOptions != "" && !*showDiffOutput {
		return errors.New("The --diff-opts flag can only be used if the --diff flag is set.")
	}

	var r *review.Review
	var err error
	if len(args) > 1 {
		return errors.New("Only showing a single review is supported.")
	}

	if len(args) == 1 {
		r = review.Get(repo, args[0])
	} else {
		r, err = review.GetCurrent(repo)
	}

	if err != nil {
		return fmt.Errorf("Failed to load the review: %v\n", err)
	}
	if r == nil {
		return errors.New("There is no matching review.")
	}
	if *showJsonOutput {
		return r.PrintJson()
	}
	if *showDiffOutput {
		var diffArgs []string
		if *showDiffOptions != "" {
			diffArgs = strings.Split(*showDiffOptions, ",")
		}
		return r.PrintDiff(diffArgs...)
	}
	return r.PrintDetails()
}