-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
71 lines (64 loc) · 1.38 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
package main
import (
"log"
"os"
"time"
"github.com/kaatinga/commit/internal/commit"
"github.com/kaatinga/commit/internal/gitlet"
"github.com/kaatinga/commit/internal/settings"
"github.com/urfave/cli/v2"
)
func main() {
settings.Init()
gitlet.Init()
app := &cli.App{
Name: "A git commit CLI tool",
Description: "Commit helps to generate commit messages.",
DefaultCommand: "commit",
Compiled: time.Now(),
Authors: []*cli.Author{
{
Name: "Michael Gunkoff",
},
},
HelpName: "commit",
Usage: "automatic commit message generator",
Commands: []*cli.Command{
{
Name: "commit",
Action: commit.Generate,
Hidden: true,
},
{
Name: "push",
Action: actionChain(commit.Generate, gitlet.Push),
},
},
Flags: []cli.Flag{
&cli.StringFlag{
Name: "key",
Usage: "provide a valid key to work with openAI API",
Action: func(context *cli.Context, s string) error {
if len(s) != 51 {
return cli.Exit("invalid key ", 1)
}
settings.APIKey = s
return nil
},
},
&cli.StringFlag{
Name: "path",
Usage: "provide a valid path to work with git repository",
Action: func(context *cli.Context, s string) error {
if s != "" {
settings.Path = s
}
return settings.DefinePaths()
},
},
},
}
if err := app.Run(os.Args); err != nil {
log.Fatal(err)
}
}