Skip to content

Commit

Permalink
code alignment
Browse files Browse the repository at this point in the history
  • Loading branch information
Songmu committed Aug 27, 2022
1 parent 4c25407 commit f8fbd7a
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 30 deletions.
38 changes: 38 additions & 0 deletions cli.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package rcpr

import (
"context"
"flag"
"fmt"
"io"
"log"
)

const cmdName = "rcpr"

func printVersion(out io.Writer) error {
_, err := fmt.Fprintf(out, "%s v%s (rev:%s)\n", cmdName, version, revision)
return err
}

// Run the rcpr
func Run(ctx context.Context, argv []string, outStream, errStream io.Writer) error {
log.SetOutput(errStream)
fs := flag.NewFlagSet(
fmt.Sprintf("%s (v%s rev:%s)", cmdName, version, revision), flag.ContinueOnError)
fs.SetOutput(errStream)
ver := fs.Bool("version", false, "display version")
if err := fs.Parse(argv); err != nil {
return err
}
if *ver {
return printVersion(outStream)
}

rp, err := newRcpr(ctx, &commander{
gitPath: "git", outStream: outStream, errStream: errStream, dir: "."})
if err != nil {
return err
}
return rp.Run(ctx)
}
31 changes: 1 addition & 30 deletions rcpr.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,7 @@ package rcpr
import (
"context"
"errors"
"flag"
"fmt"
"io"
"log"
"net/url"
"os"
Expand All @@ -20,7 +18,6 @@ import (
)

const (
cmdName = "rcpr"
gitUser = "github-actions[bot]"
gitEmail = "github-actions[bot]@users.noreply.github.com"
defaultReleaseBranch = "main"
Expand All @@ -29,11 +26,6 @@ const (
autoLableName = "rcpr"
)

func printVersion(out io.Writer) error {
_, err := fmt.Fprintf(out, "%s v%s (rev:%s)\n", cmdName, version, revision)
return err
}

type rcpr struct {
c *commander
gh *github.Client
Expand Down Expand Up @@ -111,28 +103,6 @@ func isRcpr(pr *github.PullRequest) bool {
return false
}

// Run the rcpr
func Run(ctx context.Context, argv []string, outStream, errStream io.Writer) error {
log.SetOutput(errStream)
fs := flag.NewFlagSet(
fmt.Sprintf("%s (v%s rev:%s)", cmdName, version, revision), flag.ContinueOnError)
fs.SetOutput(errStream)
ver := fs.Bool("version", false, "display version")
if err := fs.Parse(argv); err != nil {
return err
}
if *ver {
return printVersion(outStream)
}

rp, err := newRcpr(ctx, &commander{
gitPath: "git", outStream: outStream, errStream: errStream, dir: "."})
if err != nil {
return err
}
return rp.Run(ctx)
}

func (rp *rcpr) Run(ctx context.Context) error {
latestSemverTag := rp.latestSemverTag()
currVerStr := latestSemverTag
Expand Down Expand Up @@ -426,6 +396,7 @@ func parseGitURL(u string) (*url.URL, error) {
}

func mergeBody(now, update string) string {
// TODO: If there are check boxes, respect what is checked, etc.
return update
}

Expand Down

0 comments on commit f8fbd7a

Please sign in to comment.