-
Notifications
You must be signed in to change notification settings - Fork 2
/
main.go
88 lines (79 loc) · 1.83 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
package main
import (
"log"
"os"
"github.com/axetroy/s4/core/command"
"github.com/urfave/cli/v2"
)
func main() {
app := cli.NewApp()
app.Name = "s4"
app.Usage = "Integrate local and remote workflow"
app.Version = "0.12.0"
app.Authors = []*cli.Author{
{
Name: "Axetroy",
Email: "axetroy.dev@gmail.com",
},
}
cli.AppHelpTemplate = `NAME:
{{.Name}} - {{.Usage}}
USAGE:
{{.HelpName}} {{if .VisibleFlags}}[global options]{{end}}{{if .Commands}} command [command options]{{end}} {{if .ArgsUsage}}{{.ArgsUsage}}{{else}}[arguments...]{{end}}
{{if len .Authors}}
AUTHOR:
{{range .Authors}}{{ . }}{{end}}
{{end}}{{if .Commands}}
COMMANDS:
{{range .Commands}}{{if not .HideHelp}} {{join .Names ", "}}{{ "\t"}}{{.Usage}}{{ "\n" }}{{end}}{{end}}{{end}}{{if .VisibleFlags}}
GLOBAL OPTIONS:
{{range .VisibleFlags}}{{.}}
{{end}}{{end}}{{if .Copyright }}
COPYRIGHT:
{{.Copyright}}
{{end}}{{if .Version}}
VERSION:
{{.Version}}
{{end}}
SOURCE CODE:
https://github.com/axetroy/s4
`
app.Flags = []cli.Flag{
&cli.StringFlag{
Name: "config",
Aliases: []string{"c"},
Usage: "specify the s4 configuration file.",
Value: ".s4", // default value
},
}
app.Commands = []*cli.Command{
{
Name: "version",
Usage: "Print current s4 version to stdout",
Action: func(c *cli.Context) error {
return command.Version(app.Version)
},
},
{
Name: "upgrade",
Usage: "Upgrade s4 version to latest",
Action: func(c *cli.Context) error {
return command.Upgrade()
},
},
{
Name: "init",
Usage: "Initialize an s4 file",
Action: func(c *cli.Context) error {
return command.Init()
},
},
}
app.Action = func(c *cli.Context) error {
configFile := c.String("config")
return command.Default(configFile)
}
if err := app.Run(os.Args); err != nil {
log.Fatal(err)
}
}