Skip to content

Commit c27dac3

Browse files
committed
Update command flags, add new --from flag for 'label copy'
Improve README. These changes make it easier to use the tool. Fixes #5 further more.
1 parent 4afe826 commit c27dac3

File tree

6 files changed

+47
-50
lines changed

6 files changed

+47
-50
lines changed

README.md

Lines changed: 13 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,14 @@
11
# gitlab-cli [![Build Status](https://travis-ci.org/clns/gitlab-cli.svg?branch=master)](https://travis-ci.org/clns/gitlab-cli)
22

3-
CLI commands for performing actions against GitLab repositories. The main reasons for building this tool is to be able to use it without any prerequisites and to deal with global labels, which GitLab API doesn't expose.
3+
CLI commands for performing actions against GitLab repositories.
44

55
- [Installation](#installation)
66
- [Usage](#usage)
77
- [Labels](#labels)
8+
- [Copy global labels](#copy-global-labels-into-a-repository)
9+
- [Copy labels from repoA to repoB](#copy-labels-from-repoa-to-repob)
10+
- [Update labels](#update-labels-that-match-a-regex)
11+
- [Delete labels](#delete-labels-that-match-a-regex)
812
- [Specifying a repository](#specifying-a-repository)
913
- [The config file](#the-config-file)
1014
- [Development](#development)
@@ -32,31 +36,23 @@ gitlab-cli label copy -U https://gitlab.com/<USER>/<REPO> -t <TOKEN>
3236
#### Copy labels from repoA to repoB
3337

3438
```sh
35-
gitlab-cli label copy -r <NAME> <GROUP>/<REPO>
39+
gitlab-cli label copy --from <repoA> -r <repoB>
3640
```
3741

38-
> Tip: The above command copies labels between repositories on the same GitLab instance. To copy from/to a different GitLab instance, use the config file as explained in [Specifying a repository](#specifying-a-repository).
39-
40-
##### Example
41-
42-
If both repositories are added to the [config file](#specifying-a-repository) as `repoA` and `repoB`, you can copy labels from repoA to repoB as follows:
43-
44-
```sh
45-
gitlab-cli label copy -r repoB repoA
46-
```
42+
> Tip: For repositories on the same installation, you can specify the `--from` repo as `group/repo`, as a convenience, in which case the repository is considered on the same GitLab instance as the target repo.
4743
4844
#### Update labels that match a regex
4945

5046
```sh
51-
gitlab-cli label update -r <NAME> --match <REGEX> --replace <REPLACE> --color <COLOR>
47+
gitlab-cli label update -r <NAME> --match <REGEX> --name <NAME> --color <COLOR> --description <DESC>
5248
```
5349

54-
> Note: `<REGEX>` is a Go regex string as in <https://golang.org/pkg/regexp/syntax> and `<REPLACE>` is a replacement string as in <https://golang.org/pkg/regexp/#Regexp.FindAllString>.
50+
> Note: `<REGEX>` is a Go regex string as in <https://golang.org/pkg/regexp/syntax> and `<NAME>` is a replacement string as in <https://golang.org/pkg/regexp/#Regexp.FindAllString>.
5551
5652
#### Delete labels that match a regex
5753

5854
```sh
59-
gitlab-cli label update -r <NAME> --regex <REGEX>
55+
gitlab-cli label delete -r <NAME> --match <REGEX>
6056
```
6157

6258
### TODO
@@ -72,19 +68,19 @@ There are 2 ways to specify a repository:
7268

7369
Example:
7470

71+
Instead of this:
72+
7573
```sh
7674
gitlab-cli label copy -U https://git.my-site.com/my_group/my_repo -t ghs93hska
7775
```
7876

79-
is the same as this, but the repo gets saved in the config file and we can refer to it later by its name:
77+
you can first save the repo in the config file and refer to it by name on all subsequent commands:
8078

8179
```sh
8280
gitlab-cli config repo save -r myrepo -U https://git.my-site.com/my_group/my_repo -t ghs93hska
8381
gitlab-cli label copy -r myrepo
8482
```
8583

86-
> Note: Some commands like [`label copy`](#copy-labels-from-one-repository-to-another) allow you to specify a repository by its path (e.g. `my_group/my_repo`), in which case the repository is considered on the same GitLab instance as the target repo.
87-
8884
#### Using user and password instead of token
8985

9086
You can specify your GitLab login (user or email) - `--user (-u)` - and password - `--password (-p)` - instead of the token in any command, if this is easier for you. Example:

cmd/label_copy.go

Lines changed: 19 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -7,42 +7,34 @@ import (
77
"github.com/spf13/cobra"
88
)
99

10+
var fromRepo string
11+
1012
var labelCopyCmd = &cobra.Command{
11-
Use: "copy [<from-repo>]",
13+
Use: "copy",
1214
Aliases: []string{"c"},
1315
Short: "Copy labels into a repository",
1416
Long: `Copy labels into a repository.
1517
16-
If given without an argument, it will copy global labels. If <from-repo>
17-
is specified, it will copy all labels from that repository. This argument
18-
can be a repo name as in the config file or a path (e.g. 'myuser/myrepo').
19-
In the later case it will use --url, without its path.`,
20-
Example: ` $ gitlab label copy -U https://gitlab.com/user/myrepo -t <TOKEN>
21-
# = copy global labels into 'user/myrepo'
18+
If --from is omitted, it will copy global labels. If --from is specified,
19+
it will copy all labels from that repository.
2220
23-
$ gitlab label copy -r myrepo myotherrepo
24-
# = copy labels from 'myotherrepo' into 'myrepo'`,
21+
The from repo can be a repo name as in the config file or a relative path
22+
as group/repo (e.g. 'myuser/myrepo'). In the later case it will use the url
23+
of the target repo, so the repositories need to be on the same GitLab instance.`,
24+
Example: ` $ gitlab label copy -U https://gitlab.com/user/myrepo -t <TOKEN>
25+
$ gitlab label copy --from sourceRepo -r targetRepo
26+
$ gitlab label copy --from group/repo -r targetRepo`,
2527
Run: func(cmd *cobra.Command, args []string) {
26-
if len(args) > 1 {
27-
fmt.Fprintln(os.Stderr, "error: invalid arguments")
28-
cmd.Usage()
29-
os.Exit(2)
30-
}
3128
var (
3229
from, to *Repo
3330
err error
3431
)
35-
if len(args) == 0 {
36-
if to, err = LoadFromConfig(repo); err != nil {
37-
fmt.Fprintf(os.Stderr, "error: invalid target repository: %v\n", err.Error())
38-
os.Exit(1)
39-
}
40-
} else if len(args) == 1 {
41-
if to, err = LoadFromConfig(repo); err != nil {
42-
fmt.Fprintf(os.Stderr, "error: invalid target repository: %v\n", err.Error())
43-
os.Exit(1)
44-
}
45-
if from, err = LoadFromConfig(args[0]); err != nil {
32+
if to, err = LoadFromConfig(repo); err != nil {
33+
fmt.Fprintf(os.Stderr, "error: invalid target repository: %v\n", err.Error())
34+
os.Exit(1)
35+
}
36+
if fromRepo != "" {
37+
if from, err = LoadFromConfig(fromRepo); err != nil {
4638
fmt.Fprintf(os.Stderr, "error: invalid source repository: %v\n", err.Error())
4739
os.Exit(1)
4840
}
@@ -68,4 +60,6 @@ In the later case it will use --url, without its path.`,
6860

6961
func init() {
7062
labelCmd.AddCommand(labelCopyCmd)
63+
64+
labelCopyCmd.Flags().StringVar(&fromRepo, "from", "", "Source repository (optional)")
7165
}

cmd/label_delete.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,10 @@ var labelDeleteCmd = &cobra.Command{
1515
Short: "Delete labels from a repository",
1616
Long: `Delete labels from a repository.
1717
18-
The --regex flag can be specified as a Go regexp pattern to delete only
18+
The --match flag can be specified as a Go regexp pattern to delete only
1919
labels that match. If ommitted, all repository labels will be deleted.`,
2020
Example: ` $ gitlab label delete -r myrepo
21-
$ gitlab label delete -r myrepo --regexp=".*:.*"`,
21+
$ gitlab label delete -r myrepo --match=".*:.*"`,
2222
Run: func(cmd *cobra.Command, args []string) {
2323
var (
2424
to *Repo
@@ -39,5 +39,5 @@ labels that match. If ommitted, all repository labels will be deleted.`,
3939
func init() {
4040
labelCmd.AddCommand(labelDeleteCmd)
4141

42-
labelDeleteCmd.Flags().StringVar(&regexpLabel, "regex", "", "Label name to match, as a Go regex (https://golang.org/pkg/regexp/syntax)")
42+
labelDeleteCmd.Flags().StringVar(&regexpLabel, "match", "", "Label name to match, as a Go regex (https://golang.org/pkg/regexp/syntax)")
4343
}

cmd/label_update.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@ var labelUpdateCmd = &cobra.Command{
2020
Long: `Update labels in a repository.
2121
2222
The --match flag is required and is a Go regex that will be used to match the label
23-
name. At least one of --replace or --color is required to update the label(s).`,
24-
Example: ` $ gitlab label update -r myrepo --match "(.*):(.*)" --replace "${1}/${2}"`,
23+
name. At least one of --name, --color or --description is required to update the label(s).`,
24+
Example: ` $ gitlab label update -r myrepo --match "(.*):(.*)" --name "${1}/${2}"`,
2525
Run: func(cmd *cobra.Command, args []string) {
2626
var (
2727
to *Repo
@@ -48,7 +48,7 @@ func init() {
4848
labelCmd.AddCommand(labelUpdateCmd)
4949

5050
labelUpdateCmd.Flags().StringVar(&matchLabel, "match", "", "Label name to match, as a Go regex (https://golang.org/pkg/regexp/syntax)")
51-
labelUpdateCmd.Flags().StringVar(&replaceLabel, "replace", "", "Label name replacement (https://golang.org/pkg/regexp/#Regexp.FindAllString)")
51+
labelUpdateCmd.Flags().StringVar(&replaceLabel, "name", "", "Label name (https://golang.org/pkg/regexp/#Regexp.FindAllString)")
5252
labelUpdateCmd.Flags().StringVar(&colorLabel, "color", "", "Label color (e.g. '#000000')")
5353
labelUpdateCmd.Flags().StringVar(&descriptionLabel, "description", "", "Label description")
5454
}

cmd/root.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ var (
2222
// RootCmd represents the base command when called without any subcommands
2323
var RootCmd = &cobra.Command{
2424
Use: "gitlab-cli",
25-
Short: "GitLab CLI tool",
25+
Short: "Cli tool for performing actions against GitLab repositories",
2626
// Uncomment the following line if your bare application
2727
// has an action associated with it:
2828
// Run: func(cmd *cobra.Command, args []string) { },

cmd/update.go

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@ var updateCmd = &cobra.Command{
1919
Use: "update",
2020
Aliases: []string{"u"},
2121
Short: "Update this tool to the latest version",
22+
Long: `Update this tool to the latest version.
23+
24+
You might need to run this command with sudo.`,
2225
Run: func(cmd *cobra.Command, args []string) {
2326
rel, err := getLatestRelease()
2427
if err != nil {
@@ -137,7 +140,11 @@ func CheckUpdate() {
137140

138141
func printUpdateAvl(latest string) {
139142
if latest != Version {
140-
fmt.Printf("New update available: %s. Run 'gitlab-cli update' to update.\n", latest)
143+
if runtime.GOOS == "linux" {
144+
fmt.Printf("New update available: %s. Run 'sudo gitlab-cli update' to update.\n", latest)
145+
} else {
146+
fmt.Printf("New update available: %s. Run 'gitlab-cli update' to update.\n", latest)
147+
}
141148
}
142149
}
143150

0 commit comments

Comments
 (0)