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:
Andrew Thornton 2022-09-16 17:31:37 +08:00 committed by Norwin
parent 37ed264d72
commit 3b83ddcefb
3 changed files with 41 additions and 8 deletions

5
.gitignore vendored
View File

@ -3,4 +3,7 @@
# Binaries
/changelog
/changelog.exe
/changelog.exe
# Go
/vendor/

View File

@ -1,4 +1,5 @@
# Changelog
A changelog generator for Gitea
[![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
#### Changelog Entries
```
changelog -m=1.11.0 -c=/path/to/my_config_file generate
### Changelog Entries
```sh
changelog generate -m=1.11.0 -c=/path/to/my_config_file
```
#### Contributors List
```
changelog -m=1.11.0 -c=/path/to/my_config_file contributors
### Contributors List
```sh
changelog contributors -m=1.11.0 -c=/path/to/my_config_file
```
## Building
```
```sh
go build
```

View File

@ -80,6 +80,7 @@ func New() *cli.App {
Init,
},
}
copyGlobalFlags(app)
return app
}
@ -95,3 +96,28 @@ func getDefaultConfigFile() string {
}
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)
}
}
}
}