-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
68 lines (55 loc) · 1.04 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
package main
import (
"errors"
"flag"
"fmt"
"log"
"os"
"go_async_shops_products/app"
cliMigration "go_async_shops_products/cli/migration"
cliSeeder "go_async_shops_products/cli/seeder"
"go_async_shops_products/helper"
_ "github.com/go-sql-driver/mysql"
)
func init() {
helper.LoadEnv()
}
func initFlagUsage() {
flag.Usage = func() {
fmt.Fprintf(
os.Stderr,
`Usage: OPTIONS COMMAND [arg...]
Options:
-help Print usage
Commands:
%s
%s
%s
`, cliSeeder.Usage, cliMigration.Usage, app.Usage)
}
}
func runCommand(args []string) error {
switch args[0] {
case "seeder":
return cliSeeder.Main(args[1:])
case "migration":
return cliMigration.Main(args[1:])
case "start":
return app.Main(args[1:])
default:
return errors.New(fmt.Sprintf("error runCommand: command %s does`t exists", args[0]))
}
}
func main() {
initFlagUsage()
flag.Parse()
if len(flag.Args()) < 1 {
flag.Usage()
flag.PrintDefaults()
os.Exit(2)
}
args := flag.Args()
if err := runCommand(args); err != nil {
log.Fatal(err)
}
}