Created
February 5, 2015 02:22
show goimports
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"fmt" | |
"go/ast" | |
"go/parser" | |
"go/token" | |
"os" | |
) | |
func main() { | |
for i, arg := range os.Args { | |
if i == 0 { | |
continue | |
} | |
fmt.Println(arg) | |
fset := token.NewFileSet() | |
f, err := parser.ParseFile(fset, arg, nil, 0) | |
if err != nil { | |
panic(err) | |
} | |
for _, decl := range f.Decls { | |
switch td := decl.(type) { | |
case *ast.GenDecl: | |
switch td.Tok { | |
case token.IMPORT: | |
for _, sp := range td.Specs { | |
s := sp.(*ast.ImportSpec) | |
fmt.Println(s.Path.Value) | |
} | |
default: | |
} | |
} | |
} | |
fmt.Println() | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment