Skip to content

Commit 8b93beb

Browse files
authored
Expose branch-name flag (#105)
* Expose branch-name flag Also re-orders the flags so that they more closely match the help output, but required flags are still at the top. For #103 * Add line which was mistakenly removed
1 parent a7912cd commit 8b93beb

File tree

2 files changed

+29
-14
lines changed

2 files changed

+29
-14
lines changed

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ Usage:
7070
services promote [flags]
7171

7272
Flags:
73+
--branch-name string the name of the branch on the destination repository for the pull request
7374
--cache-dir string where to cache Git checkouts (default "~/.promotion/cache")
7475
--commit-email string the email to use for commits when creating branches
7576
--commit-message string the msg to use on the resultant commit and pull request
@@ -89,6 +90,7 @@ Global Flags:
8990

9091
This will _copy_ all files under `/services/service-a/base/config/*` in `first-environment` to `second-environment`, commit and push, and open a PR for the change. Any of these arguments may be provided as environment variables, using all upper case and replacing `-` with `_`. Hence you can set CACHE_DIR, COMMIT_EMAIL, etc.
9192

93+
- `--branch-name` : use this to override the branch name on the destination Git repository, which will otherwise be generated automatically.
9294
- `--cache-dir` : path on the local filesystem in which Git checkouts will be cached.
9395
- `--commit-email` : Git commits require an associated email address and username. This is the email address. May be set via ~/.gitconfig.
9496
- `--commit-message` : use this to override the commit message which will otherwise be generated automatically.
@@ -117,3 +119,4 @@ Inside of the `plugin` folder you'll see documentation and other files related t
117119
Client Version: openshift-clients-4.3.13-202004121622
118120
Server Version: 4.3.13
119121
Kubernetes Version: v1.16.2
122+
```

pkg/cmd/promote.go

Lines changed: 26 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ func makePromoteCmd() *cobra.Command {
2020
RunE: promoteAction,
2121
}
2222

23+
// Required flags
2324
cmd.Flags().String(
2425
fromFlag,
2526
"",
@@ -44,20 +45,21 @@ func makePromoteCmd() *cobra.Command {
4445
logIfError(cmd.MarkFlagRequired(serviceFlag))
4546
logIfError(viper.BindPFlag(serviceFlag, cmd.Flags().Lookup(serviceFlag)))
4647

48+
// Optional flags
49+
cmd.Flags().String(
50+
branchNameFlag,
51+
"",
52+
"the name of the branch on the destination repository for the pull request (auto-generated if empty)",
53+
)
54+
logIfError(viper.BindPFlag(branchNameFlag, cmd.Flags().Lookup(branchNameFlag)))
55+
4756
cmd.Flags().String(
4857
cacheDirFlag,
4958
"~/.promotion/cache",
5059
"where to cache Git checkouts",
5160
)
5261
logIfError(viper.BindPFlag(cacheDirFlag, cmd.Flags().Lookup(cacheDirFlag)))
5362

54-
cmd.Flags().String(
55-
nameFlag,
56-
"",
57-
"the name to use for commits when creating branches",
58-
)
59-
logIfError(viper.BindPFlag(nameFlag, cmd.Flags().Lookup(nameFlag)))
60-
6163
cmd.Flags().String(
6264
emailFlag,
6365
"",
@@ -73,11 +75,11 @@ func makePromoteCmd() *cobra.Command {
7375
logIfError(viper.BindPFlag(msgFlag, cmd.Flags().Lookup(msgFlag)))
7476

7577
cmd.Flags().String(
76-
repoTypeFlag,
77-
"github",
78-
"the type of repository: github, gitlab or ghe",
78+
nameFlag,
79+
"",
80+
"the name to use for commits when creating branches",
7981
)
80-
logIfError(viper.BindPFlag(repoTypeFlag, cmd.Flags().Lookup(repoTypeFlag)))
82+
logIfError(viper.BindPFlag(nameFlag, cmd.Flags().Lookup(nameFlag)))
8183

8284
cmd.Flags().Bool(
8385
debugFlag,
@@ -99,6 +101,13 @@ func makePromoteCmd() *cobra.Command {
99101
"whether to retain the locally cloned repositories in the cache directory",
100102
)
101103
logIfError(viper.BindPFlag(keepCacheFlag, cmd.Flags().Lookup(keepCacheFlag)))
104+
105+
cmd.Flags().String(
106+
repoTypeFlag,
107+
"github",
108+
"the type of repository: github, gitlab or ghe",
109+
)
110+
logIfError(viper.BindPFlag(repoTypeFlag, cmd.Flags().Lookup(repoTypeFlag)))
102111
return cmd
103112
}
104113

@@ -109,15 +118,18 @@ func logIfError(e error) {
109118
}
110119

111120
func promoteAction(c *cobra.Command, args []string) error {
121+
// Required flags
112122
fromRepo := viper.GetString(fromFlag)
113123
toRepo := viper.GetString(toFlag)
114124
service := viper.GetString(serviceFlag)
115-
repoType := viper.GetString(repoTypeFlag)
125+
126+
// Optional flags
116127
newBranchName := viper.GetString(branchNameFlag)
117-
insecureSkipVerify := viper.GetBool(insecureSkipVerifyFlag)
128+
msg := viper.GetString(msgFlag)
118129
debug := viper.GetBool(debugFlag)
130+
insecureSkipVerify := viper.GetBool(insecureSkipVerifyFlag)
119131
keepCache := viper.GetBool(keepCacheFlag)
120-
msg := viper.GetString(msgFlag)
132+
repoType := viper.GetString(repoTypeFlag)
121133

122134
cacheDir, err := homedir.Expand(viper.GetString(cacheDirFlag))
123135
if err != nil {

0 commit comments

Comments
 (0)