Pass global flags down to subcommands (#54)
Fix #51 Signed-off-by: Andrew Thornton <art27@cantab.net> Co-authored-by: 6543 <6543@obermui.de> Reviewed-on: https://gitea.com/gitea/changelog/pulls/54 Reviewed-by: 6543 <6543@obermui.de> Reviewed-by: Norwin <noerw@noreply.gitea.io> Co-authored-by: Andrew Thornton <art27@cantab.net> Co-committed-by: Andrew Thornton <art27@cantab.net>
This commit is contained in:
parent
37ed264d72
commit
3b83ddcefb
|
@ -3,4 +3,7 @@
|
||||||
|
|
||||||
# Binaries
|
# Binaries
|
||||||
/changelog
|
/changelog
|
||||||
/changelog.exe
|
/changelog.exe
|
||||||
|
|
||||||
|
# Go
|
||||||
|
/vendor/
|
||||||
|
|
18
README.md
18
README.md
|
@ -1,4 +1,5 @@
|
||||||
# Changelog
|
# Changelog
|
||||||
|
|
||||||
A changelog generator for Gitea
|
A changelog generator for Gitea
|
||||||
|
|
||||||
[![Build Status](https://drone.gitea.com/api/badges/gitea/changelog/status.svg)](https://drone.gitea.com/gitea/changelog)
|
[![Build Status](https://drone.gitea.com/api/badges/gitea/changelog/status.svg)](https://drone.gitea.com/gitea/changelog)
|
||||||
|
@ -19,18 +20,21 @@ See the [changelog.example.yml](config/changelog.example.yml) example file.
|
||||||
|
|
||||||
## Usage
|
## Usage
|
||||||
|
|
||||||
#### Changelog Entries
|
### Changelog Entries
|
||||||
```
|
|
||||||
changelog -m=1.11.0 -c=/path/to/my_config_file generate
|
```sh
|
||||||
|
changelog generate -m=1.11.0 -c=/path/to/my_config_file
|
||||||
```
|
```
|
||||||
|
|
||||||
#### Contributors List
|
### Contributors List
|
||||||
```
|
|
||||||
changelog -m=1.11.0 -c=/path/to/my_config_file contributors
|
```sh
|
||||||
|
changelog contributors -m=1.11.0 -c=/path/to/my_config_file
|
||||||
```
|
```
|
||||||
|
|
||||||
## Building
|
## Building
|
||||||
```
|
|
||||||
|
```sh
|
||||||
go build
|
go build
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
26
cmd/cmd.go
26
cmd/cmd.go
|
@ -80,6 +80,7 @@ func New() *cli.App {
|
||||||
Init,
|
Init,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
copyGlobalFlags(app)
|
||||||
return app
|
return app
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -95,3 +96,28 @@ func getDefaultConfigFile() string {
|
||||||
}
|
}
|
||||||
return ""
|
return ""
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func copyGlobalFlags(app *cli.App) {
|
||||||
|
for _, command := range app.Commands {
|
||||||
|
originalFlagNames := make([]string, 0, len(command.Flags))
|
||||||
|
for _, flag := range command.Flags {
|
||||||
|
originalFlagNames = append(originalFlagNames, flag.Names()...)
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, flag := range app.Flags {
|
||||||
|
found := false
|
||||||
|
flagNameLoop:
|
||||||
|
for _, name := range flag.Names() {
|
||||||
|
for _, originalName := range originalFlagNames {
|
||||||
|
if name == originalName {
|
||||||
|
found = true
|
||||||
|
break flagNameLoop
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if !found {
|
||||||
|
command.Flags = append(command.Flags, flag)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue