@@ -29,22 +29,29 @@ var (
29
29
sortOutput bool
30
30
silent bool
31
31
relative bool
32
+ listLangs bool
33
+ fields string
32
34
)
33
35
36
+ // ignore unknown flags
37
+ var flags = flag .NewFlagSet (os .Args [0 ], flag .ContinueOnError )
38
+
34
39
// Initialize flags.
35
40
func init () {
36
- flag .BoolVar (& printVersion , "v" , false , "print version." )
37
- flag .StringVar (& inputFile , "L" , "" , `source file names are read from the specified file. If file is "-", input is read from standard in.` )
38
- flag .StringVar (& outputFile , "f" , "" , `write output to specified file. If file is "-", output is written to standard out.` )
39
- flag .BoolVar (& recurse , "R" , false , "recurse into directories in the file list." )
40
- flag .BoolVar (& sortOutput , "sort" , true , "sort tags." )
41
- flag .BoolVar (& silent , "silent" , false , "do not produce any output on error." )
42
- flag .BoolVar (& relative , "tag-relative" , false , "file paths should be relative to the directory containing the tag file." )
43
-
44
- flag .Usage = func () {
41
+ flags .BoolVar (& printVersion , "v" , false , "print version." )
42
+ flags .StringVar (& inputFile , "L" , "" , `source file names are read from the specified file. If file is "-", input is read from standard in.` )
43
+ flags .StringVar (& outputFile , "f" , "" , `write output to specified file. If file is "-", output is written to standard out.` )
44
+ flags .BoolVar (& recurse , "R" , false , "recurse into directories in the file list." )
45
+ flags .BoolVar (& sortOutput , "sort" , true , "sort tags." )
46
+ flags .BoolVar (& silent , "silent" , false , "do not produce any output on error." )
47
+ flags .BoolVar (& relative , "tag-relative" , false , "file paths should be relative to the directory containing the tag file." )
48
+ flags .BoolVar (& listLangs , "list-languages" , false , "list supported languages." )
49
+ flags .StringVar (& fields , "fields" , "" , "include selected extension fields (only +l)." )
50
+
51
+ flags .Usage = func () {
45
52
fmt .Fprintf (os .Stderr , "gotags version %s\n \n " , Version )
46
53
fmt .Fprintf (os .Stderr , "Usage: %s [options] file(s)\n \n " , os .Args [0 ])
47
- flag .PrintDefaults ()
54
+ flags .PrintDefaults ()
48
55
}
49
56
}
50
57
@@ -109,7 +116,7 @@ func readNames(names []string) ([]string, error) {
109
116
func getFileNames () ([]string , error ) {
110
117
var names []string
111
118
112
- names = append (names , flag .Args ()... )
119
+ names = append (names , flags .Args ()... )
113
120
names , err := readNames (names )
114
121
if err != nil {
115
122
return nil , err
@@ -126,23 +133,28 @@ func getFileNames() ([]string, error) {
126
133
}
127
134
128
135
func main () {
129
- flag .Parse ()
136
+ flags .Parse (os . Args [ 1 :] )
130
137
131
138
if printVersion {
132
139
fmt .Printf ("gotags version %s\n " , Version )
133
140
return
134
141
}
135
142
143
+ if listLangs {
144
+ fmt .Println ("Go" )
145
+ return
146
+ }
147
+
136
148
files , err := getFileNames ()
137
149
if err != nil {
138
150
fmt .Fprintf (os .Stderr , "cannot get specified files\n \n " )
139
- flag .Usage ()
151
+ flags .Usage ()
140
152
os .Exit (1 )
141
153
}
142
154
143
155
if len (files ) == 0 && len (inputFile ) == 0 {
144
156
fmt .Fprintf (os .Stderr , "no file specified\n \n " )
145
- flag .Usage ()
157
+ flags .Usage ()
146
158
os .Exit (1 )
147
159
}
148
160
@@ -157,6 +169,13 @@ func main() {
157
169
}
158
170
}
159
171
172
+ fieldSet , err := parseFields (fields )
173
+ if err != nil {
174
+ fmt .Fprintf (os .Stderr , "%s\n \n " , err )
175
+ flags .Usage ()
176
+ os .Exit (1 )
177
+ }
178
+
160
179
tags := []Tag {}
161
180
for _ , file := range files {
162
181
ts , err := Parse (file , relative , basedir )
@@ -171,6 +190,9 @@ func main() {
171
190
172
191
output := createMetaTags ()
173
192
for _ , tag := range tags {
193
+ if fieldSet .Includes (Language ) {
194
+ tag .Fields [Language ] = "Go"
195
+ }
174
196
output = append (output , tag .String ())
175
197
}
176
198
0 commit comments