-
Notifications
You must be signed in to change notification settings - Fork 3
/
pro.go
79 lines (68 loc) · 1.62 KB
/
pro.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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
package main
import (
"fmt"
"os"
"github.com/wowu/pro/command"
"github.com/urfave/cli/v2"
)
var openCommandFlags = []cli.Flag{
&cli.BoolFlag{
Name: "print",
Aliases: []string{"p"},
Usage: "print URL instead of opening in browser",
},
&cli.BoolFlag{
Name: "copy",
Aliases: []string{"c"},
Usage: "copy URL to clipboard instead of opening in browser",
},
}
func main() {
// cli library API example:
// https://github.com/urfave/cli/blob/main/docs/v2/manual.md#full-api-example
app := &cli.App{
Name: "pro",
Usage: "Pull Request Opener",
Version: "v0.3.2",
Flags: openCommandFlags,
Commands: []*cli.Command{
{
Name: "auth",
ArgsUsage: "[gitlab|github]",
Usage: "Authorize GitLab or GitHub",
UsageText: "pro auth gitlab\npro login github",
Action: func(c *cli.Context) error {
if c.NArg() != 1 {
fmt.Println("Please specify provider (github or gitlab)")
os.Exit(1)
}
provider := c.Args().Get(0)
if provider != "gitlab" && provider != "github" {
fmt.Println("Please specify provider (github or gitlab)")
os.Exit(1)
}
command.Auth(provider)
return nil
},
},
{
Name: "open",
Usage: "Open PR page in browser (default action)",
Flags: openCommandFlags,
Action: func(c *cli.Context) error {
command.Open(".", c.Bool("print"), c.Bool("copy"))
return nil
},
},
},
Action: func(c *cli.Context) error {
command.Open(".", c.Bool("print"), c.Bool("copy"))
return nil
},
}
err := app.Run(os.Args)
if err != nil {
fmt.Fprintln(os.Stderr, err)
os.Exit(1)
}
}