-
Notifications
You must be signed in to change notification settings - Fork 3
/
main.go
113 lines (101 loc) · 2.16 KB
/
main.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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
package main
import (
"fmt"
"io"
"os"
"github.com/pkg/browser"
"github.com/sharpvik/sema/v3/agent"
"github.com/urfave/cli/v2"
)
const gitHubURL = "https://github.com/sharpvik/sema"
const (
add = "add"
push = "push"
force = "force"
long = "long"
breaking = "breaking"
tags = "tags"
)
var version = "unknown"
var app = &cli.App{
Name: "sema",
Usage: "Semantic commits made simple",
Description: gitHubURL,
Version: version,
Authors: []*cli.Author{{
Name: "Viktor A. Rozenko Voitenko",
Email: "sharp.vik@gmail.com",
}, {
Name: "Antoine Langlois",
Email: "antoine.l@antoine-langlois.net",
}},
Flags: []cli.Flag{
&cli.BoolFlag{
Name: add,
Aliases: []string{"a"},
Usage: "begin by running 'git add'",
},
&cli.BoolFlag{
Name: push,
Aliases: []string{"p"},
Usage: "run 'git push' on successful commit",
},
&cli.BoolFlag{
Name: force,
Aliases: []string{"f"},
Usage: "force push changes with 'git push -f'",
},
&cli.BoolFlag{
Name: long,
Aliases: []string{"l"},
Usage: "open editor to elaborate commit message",
},
&cli.BoolFlag{
Name: breaking,
Aliases: []string{"b"},
Usage: "mark commit as introducing breaking changes",
},
&cli.BoolFlag{
Name: tags,
Aliases: []string{"t"},
Usage: "push tags along with commits",
},
},
UseShortOptionHandling: true,
Action: run,
Commands: []*cli.Command{{
Name: "github",
Usage: "Open sema GitHub repository in browser",
Action: github,
}},
}
func run(c *cli.Context) error {
do := agent.New(config(c))
return pipe(do.Init, do.Title).
thenIf(c.Bool(add), do.Add).
then(do.Commit).
thenIf(c.Bool(push), do.Push).
run()
}
func config(c *cli.Context) *agent.Config {
return &agent.Config{
Commit: agent.Commit{
Long: c.Bool(long),
Breaking: c.Bool(breaking),
},
Push: agent.Push{
Force: c.Bool(force),
Tags: c.Bool(tags),
},
}
}
func github(_ *cli.Context) error {
browser.Stdout = io.Discard
browser.Stderr = io.Discard
return browser.OpenURL(gitHubURL)
}
func main() {
if err := app.Run(os.Args); err != nil {
fmt.Fprintln(os.Stderr, err)
}
}