-
Notifications
You must be signed in to change notification settings - Fork 0
/
cli.go
117 lines (109 loc) · 3.3 KB
/
cli.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
114
115
116
117
package bocian
import (
"fmt"
"github.com/urfave/cli/v2"
"log"
"os"
)
func (ba bocianapp) mergeexpcli() *cli.App {
commands := []*cli.Command{
{
Name: "build",
Usage: "only builds the experimental branch (and pushes it to BitBucket",
Action: func(c *cli.Context) error {
return ba.run(c, true, false)
},
},
{
Name: "deploy",
Usage: "only deploys the experimental brach from BitBucket to proper environment",
Action: func(c *cli.Context) error {
return ba.run(c, false, true)
},
},
}
flags := []cli.Flag{}
flags = append(flags,
&cli.StringFlag{
Name: "deployment_key",
Aliases: []string{"dk"},
Usage: fmt.Sprintf(`path to deployment key used to fetch the repos from BitBucket. If not supplied, file ~/.ssh/%s is used, if exists`,
ba.defaultDeploymentKey,
),
/*
Description:
fmt.Println(
"If not supplied, file ~/.ssh/%s is used if exists",
ba.defaultDeploymentKey(),
),
*/
},
)
flags = append(
flags,
&cli.StringFlag{
Name: "user",
Aliases: []string{"u"},
Usage: "BitBucket user name for access to REST",
EnvVars: []string{"BOCIAN_USER"},
},
&cli.StringFlag{
Name: "password",
Aliases: []string{"p"},
Usage: "BitBucket application password for access to REST",
EnvVars: []string{"BOCIAN_PASSWORD"},
},
)
/*
$cli->add_option( <<"END_USER");
user|u=s - Bitbucket username (likely email). If not supplied then environment variable BOCIAN_USER is used.
If the variable is not set, the username will be asked for.
END_USER
$cli->add_option( <<"END_PASSWORD");
password|p=s - Bitbucket user password, if not supplied then environment variable BOCIAN_PASSWORD is used.
If the variable is not set, the username will be asked for.
END_PASSWORD
*/
/*
$cli->add_option(<<"END_KEY");
deployment_key|dk=s - path to deployment key used to fetch the repos fro BitBucket.
If not supplied, uses ${\ default_deployment_key($target) }, if the file exists.
END_KEY
$cli->add_option( <<"END_USER");
user|u=s - Bitbucket username (likely email). If not supplied then environment variable BOCIAN_USER is used.
If the variable is not set, the username will be asked for.
END_USER
$cli->add_option( <<"END_PASSWORD");
password|p=s - Bitbucket user password, if not supplied then environment variable BOCIAN_PASSWORD is used.
If the variable is not set, the username will be asked for.
END_PASSWORD
*/
if ba.hasTest2 {
flags = append(flags,
&cli.BoolFlag{Name: "test2", Usage: "deploys to TEST2 environment (default is TEST1)"},
)
}
desc := fmt.Sprintf(
`Builds the experimental version of %s and deploys it to demo environment. The process:
* builds experimental branch and pushes it to BitBucket to %s/experimental branch
* deploys (push) the experimental branch to test environment
`, ba.target, ba.bitbucketrepo)
app := &cli.App{
Name: ba.target + "-MergeExperimental",
Usage: ` experimental merge and deploy!`,
Description: desc,
Flags: flags,
Action: func(c *cli.Context) error {
return ba.run(c, true, true)
},
Commands: commands,
}
return app
}
func (ba bocianapp) RunMergeExp() {
app := ba.mergeexpcli()
err := app.Run(os.Args)
if err != nil {
log.Fatal(err)
}
}