@@ -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
8582var 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
167161func main () {
162+ analyzer .Flags = flagSet
168163 singlechecker .Main (analyzer )
169164}
0 commit comments