-
-
Notifications
You must be signed in to change notification settings - Fork 20
/
cli.go
38 lines (33 loc) · 808 Bytes
/
cli.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
package tagpr
import (
"context"
"flag"
"fmt"
"io"
"log"
)
const cmdName = "tagpr"
func printVersion(out io.Writer) error {
_, err := fmt.Fprintf(out, "%s v%s (rev:%s)\n", cmdName, version, revision)
return err
}
// Run the tagpr
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)
}
tp, err := newTagPR(ctx, &commander{
gitPath: "git", outStream: outStream, errStream: errStream, dir: "."})
if err != nil {
return err
}
return tp.Run(ctx)
}