forked from aperezg/goscaffold
-
Notifications
You must be signed in to change notification settings - Fork 0
/
client.go
59 lines (47 loc) · 1.33 KB
/
client.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
package goscaffold
import (
"flag"
"fmt"
"github.com/aperezg/goscaffold/data"
"os"
)
var Client consoleClient
type consoleClient struct{}
func (c *consoleClient) Stdin() (setting *Settings) {
c.configureHelp()
command := flag.NewFlagSet("create-project", flag.ExitOnError)
enableGitlabCI := command.Bool("gitlabci", false, "Create a .gitlab-ci with a valid pipeline")
workspace := command.String("workspace", "$GOPATH/src", "Your golang workspace")
flag.Parse()
if flag.NArg() < 3 {
flag.Usage()
os.Exit(1)
}
command.Parse(os.Args[4:])
if command.Parsed() {
namespace, applicationName, importPath := c.extractRepoPaths(workspace)
setting = NewSettings(
applicationName,
importPath,
namespace,
*enableGitlabCI,
)
}
return
}
func (c *consoleClient) extractRepoPaths(workspace *string) (namespace, applicationName, importPath string) {
args := os.Args[2:4]
namespace, applicationName = args[0], args[1]
importPath = os.ExpandEnv(*workspace) + string(os.PathSeparator) + namespace + string(os.PathSeparator) + applicationName
return
}
func (c *consoleClient) configureHelp() {
flag.Usage = func() {
d, err := data.Asset("doc/help")
if err != nil {
fmt.Println("Can't load the help, go to de 'https://github.com/aperezg/goscaffold' for more information")
os.Exit(1)
}
fmt.Println(string(d))
}
}