Skip to content

Commit d0e0e75

Browse files
authored
cmd/golicenser: fix flags missing (#4)
1 parent 3c6b5b0 commit d0e0e75

File tree

4 files changed

+22
-25
lines changed

4 files changed

+22
-25
lines changed

.github/release.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ changelog:
1212
- title: "🐛 Fixes"
1313
labels:
1414
- "type: bug"
15-
- "type: broken metric"
1615
- title: "🔧 Improvements"
1716
labels:
1817
- "type: enhancement"

.github/workflows/go.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,9 @@ jobs:
8484
- name: "Test"
8585
run: go test ./...
8686

87+
- name: "golicenser"
88+
run: make run
89+
8790
lint:
8891
name: "Lint"
8992
runs-on: "ubuntu-latest"

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
# SOFTWARE.
2020

2121
.PHONY: all
22-
all: lint build test
22+
all: lint build test run
2323

2424
.PHONY: deps
2525
deps:

cmd/golicenser/golicenser.go

Lines changed: 18 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ import (
2626
"log"
2727
"os"
2828
"strings"
29-
"sync"
3029

3130
"golang.org/x/tools/go/analysis"
3231
"golang.org/x/tools/go/analysis/singlechecker"
@@ -52,44 +51,39 @@ var (
5251
matchHeaderRegexp string
5352
)
5453

55-
var setupFlagsOnce = sync.OnceFunc(setupFlags)
56-
57-
func setupFlags() {
58-
flag.StringVar(&template, "tmpl", "", "License header template")
59-
flag.StringVar(&templateFile, "tmpl-file", "license_header.txt",
54+
func init() {
55+
flagSet.StringVar(&template, "tmpl", "", "License header template")
56+
flagSet.StringVar(&templateFile, "tmpl-file", "license_header.txt",
6057
"License header template file")
61-
flag.StringVar(&matchTemplate, "match-tmpl", "",
58+
flagSet.StringVar(&matchTemplate, "match-tmpl", "",
6259
"Match license header template")
63-
flag.StringVar(&matchTemplateFile, "match-tmpl-file", "",
60+
flagSet.StringVar(&matchTemplateFile, "match-tmpl-file", "",
6461
"Match license header template file (used to detect existing license headers which may be updated)")
65-
flag.BoolVar(&matchTemplateEscape, "match-tmpl-escape", false,
62+
flagSet.BoolVar(&matchTemplateEscape, "match-tmpl-escape", false,
6663
"Whether to regexp-escape the match-tmpl")
67-
flag.StringVar(&author, "author", "", "Copyright author")
68-
flag.StringVar(&authorRegexp, "author-regexp", "",
64+
flagSet.StringVar(&author, "author", "", "Copyright author")
65+
flagSet.StringVar(&authorRegexp, "author-regexp", "",
6966
"Regexp to match copyright author (default: match author)")
70-
flag.StringVar(&variables, "var", "", "Template variables (e.g. a=Hello,b=Test)")
71-
flag.StringVar(&yearModeStr, "year-mode", golicenser.YearMode(0).String(),
67+
flagSet.StringVar(&variables, "var", "", "Template variables (e.g. a=Hello,b=Test)")
68+
flagSet.StringVar(&yearModeStr, "year-mode", golicenser.YearMode(0).String(),
7269
"Year formatting mode (preserve, preserve-this-year-range, preserve-modified-range, this-year, last-modified, git-range, git-modified-years)")
73-
flag.StringVar(&commentStyleStr, "comment-style", golicenser.CommentStyle(0).String(),
70+
flagSet.StringVar(&commentStyleStr, "comment-style", golicenser.CommentStyle(0).String(),
7471
"Comment style (line, block)")
75-
flag.StringVar(&exclude, "exclude", strings.Join(golicenser.DefaultExcludes, ","),
72+
flagSet.StringVar(&exclude, "exclude", strings.Join(golicenser.DefaultExcludes, ","),
7673
"Paths to exclude (doublestar or r!-prefixed regexp, comma-separated)")
77-
flag.IntVar(&maxConcurrent, "max-concurrent", golicenser.DefaultMaxConcurrent,
74+
flagSet.IntVar(&maxConcurrent, "max-concurrent", golicenser.DefaultMaxConcurrent,
7875
"Maximum concurrent processes to use when processing files")
79-
flag.StringVar(&matchHeaderRegexp, "match-header-regexp", golicenser.DefaultMatchHeaderRegexp,
76+
flagSet.StringVar(&matchHeaderRegexp, "match-header-regexp", golicenser.DefaultMatchHeaderRegexp,
8077
"Match header regexp (used to detect any copyright headers)")
8178
}
8279

8380
// TODO(joshuasing): There has to be a better way of doing this...
8481

8582
var analyzer = &analysis.Analyzer{
86-
Name: "golicenser",
87-
Doc: "manages license headers",
88-
URL: "https://github.com/joshuasing/golicenser",
89-
Flags: flagSet,
83+
Name: "golicenser",
84+
Doc: "manages license headers",
85+
URL: "https://github.com/joshuasing/golicenser",
9086
Run: func(pass *analysis.Pass) (any, error) {
91-
setupFlagsOnce()
92-
9387
var err error
9488
if template == "" {
9589
//nolint:gosec // Reading user-defined file.
@@ -165,5 +159,6 @@ var analyzer = &analysis.Analyzer{
165159
}
166160

167161
func main() {
162+
analyzer.Flags = flagSet
168163
singlechecker.Main(analyzer)
169164
}

0 commit comments

Comments
 (0)