2017-05-06 14:06:49 -05:00
|
|
|
// Package main is complete tool for the go command line
|
2017-05-05 10:01:27 -05:00
|
|
|
package main
|
|
|
|
|
2017-05-07 11:53:55 -05:00
|
|
|
import "github.com/posener/complete"
|
2017-05-05 10:01:27 -05:00
|
|
|
|
2017-05-06 11:08:47 -05:00
|
|
|
var (
|
|
|
|
predictEllipsis = complete.PredictSet("./...")
|
2017-05-05 16:25:27 -05:00
|
|
|
|
2017-05-06 14:06:49 -05:00
|
|
|
goFilesOrPackages = complete.PredictFiles("*.go").
|
2017-05-06 11:47:27 -05:00
|
|
|
Or(complete.PredictDirs).
|
2017-05-06 11:11:16 -05:00
|
|
|
Or(predictEllipsis)
|
2017-05-06 11:08:47 -05:00
|
|
|
)
|
2017-05-05 16:25:27 -05:00
|
|
|
|
|
|
|
func main() {
|
|
|
|
build := complete.Command{
|
2017-05-05 10:06:31 -05:00
|
|
|
Flags: complete.Flags{
|
2017-05-06 14:06:49 -05:00
|
|
|
"-o": complete.PredictFiles("*"),
|
2017-05-05 13:59:10 -05:00
|
|
|
"-i": complete.PredictNothing,
|
2017-05-05 16:25:27 -05:00
|
|
|
|
|
|
|
"-a": complete.PredictNothing,
|
|
|
|
"-n": complete.PredictNothing,
|
|
|
|
"-p": complete.PredictAnything,
|
|
|
|
"-race": complete.PredictNothing,
|
|
|
|
"-msan": complete.PredictNothing,
|
|
|
|
"-v": complete.PredictNothing,
|
|
|
|
"-work": complete.PredictNothing,
|
|
|
|
"-x": complete.PredictNothing,
|
|
|
|
"-asmflags": complete.PredictAnything,
|
|
|
|
"-buildmode": complete.PredictAnything,
|
|
|
|
"-compiler": complete.PredictAnything,
|
|
|
|
"-gccgoflags": complete.PredictAnything,
|
|
|
|
"-gcflags": complete.PredictAnything,
|
|
|
|
"-installsuffix": complete.PredictAnything,
|
|
|
|
"-ldflags": complete.PredictAnything,
|
|
|
|
"-linkshared": complete.PredictNothing,
|
2017-05-06 11:47:27 -05:00
|
|
|
"-pkgdir": complete.PredictDirs,
|
2017-05-05 16:25:27 -05:00
|
|
|
"-tags": complete.PredictAnything,
|
|
|
|
"-toolexec": complete.PredictAnything,
|
2017-05-05 10:01:27 -05:00
|
|
|
},
|
2017-05-05 16:25:27 -05:00
|
|
|
Args: goFilesOrPackages,
|
2017-05-05 10:06:31 -05:00
|
|
|
}
|
|
|
|
|
2017-05-05 16:25:27 -05:00
|
|
|
run := complete.Command{
|
2017-05-05 10:06:31 -05:00
|
|
|
Flags: complete.Flags{
|
2017-05-05 16:25:27 -05:00
|
|
|
"-exec": complete.PredictAnything,
|
2017-05-05 10:06:31 -05:00
|
|
|
},
|
2017-05-06 11:47:27 -05:00
|
|
|
Args: complete.PredictFiles("*.go"),
|
2017-05-05 10:06:31 -05:00
|
|
|
}
|
|
|
|
|
2017-05-05 16:25:27 -05:00
|
|
|
test := complete.Command{
|
|
|
|
Flags: complete.Flags{
|
|
|
|
"-args": complete.PredictAnything,
|
|
|
|
"-c": complete.PredictNothing,
|
|
|
|
"-exec": complete.PredictAnything,
|
|
|
|
|
|
|
|
"-bench": predictTest("Benchmark"),
|
|
|
|
"-benchtime": complete.PredictAnything,
|
|
|
|
"-count": complete.PredictAnything,
|
|
|
|
"-cover": complete.PredictNothing,
|
2017-05-05 16:53:03 -05:00
|
|
|
"-covermode": complete.PredictSet("set", "count", "atomic"),
|
2017-05-06 11:47:27 -05:00
|
|
|
"-coverpkg": complete.PredictDirs,
|
2017-05-05 16:25:27 -05:00
|
|
|
"-cpu": complete.PredictAnything,
|
|
|
|
"-run": predictTest("test"),
|
|
|
|
"-short": complete.PredictNothing,
|
|
|
|
"-timeout": complete.PredictAnything,
|
|
|
|
|
|
|
|
"-benchmem": complete.PredictNothing,
|
2017-05-06 11:47:27 -05:00
|
|
|
"-blockprofile": complete.PredictFiles("*.out"),
|
2017-05-05 16:25:27 -05:00
|
|
|
"-blockprofilerate": complete.PredictAnything,
|
2017-05-06 11:47:27 -05:00
|
|
|
"-coverprofile": complete.PredictFiles("*.out"),
|
|
|
|
"-cpuprofile": complete.PredictFiles("*.out"),
|
|
|
|
"-memprofile": complete.PredictFiles("*.out"),
|
2017-05-05 16:25:27 -05:00
|
|
|
"-memprofilerate": complete.PredictAnything,
|
2017-05-06 11:47:27 -05:00
|
|
|
"-mutexprofile": complete.PredictFiles("*.out"),
|
2017-05-05 16:25:27 -05:00
|
|
|
"-mutexprofilefraction": complete.PredictAnything,
|
2017-05-06 11:47:27 -05:00
|
|
|
"-outputdir": complete.PredictDirs,
|
|
|
|
"-trace": complete.PredictFiles("*.out"),
|
2017-05-05 16:25:27 -05:00
|
|
|
},
|
|
|
|
Args: goFilesOrPackages,
|
|
|
|
}
|
|
|
|
|
|
|
|
fmt := complete.Command{
|
|
|
|
Flags: complete.Flags{
|
|
|
|
"-n": complete.PredictNothing,
|
|
|
|
"-x": complete.PredictNothing,
|
|
|
|
},
|
|
|
|
Args: goFilesOrPackages,
|
|
|
|
}
|
|
|
|
|
|
|
|
get := complete.Command{
|
|
|
|
Flags: complete.Flags{
|
|
|
|
"-d": complete.PredictNothing,
|
|
|
|
"-f": complete.PredictNothing,
|
|
|
|
"-fix": complete.PredictNothing,
|
|
|
|
"-insecure": complete.PredictNothing,
|
|
|
|
"-t": complete.PredictNothing,
|
|
|
|
"-u": complete.PredictNothing,
|
|
|
|
},
|
|
|
|
Args: goFilesOrPackages,
|
|
|
|
}
|
|
|
|
|
|
|
|
generate := complete.Command{
|
|
|
|
Flags: complete.Flags{
|
|
|
|
"-n": complete.PredictNothing,
|
|
|
|
"-x": complete.PredictNothing,
|
|
|
|
"-v": complete.PredictNothing,
|
|
|
|
"-run": complete.PredictAnything,
|
|
|
|
},
|
|
|
|
Args: goFilesOrPackages,
|
|
|
|
}
|
|
|
|
|
|
|
|
vet := complete.Command{
|
|
|
|
Flags: complete.Flags{
|
|
|
|
"-n": complete.PredictNothing,
|
|
|
|
"-x": complete.PredictNothing,
|
|
|
|
},
|
2017-05-06 11:47:27 -05:00
|
|
|
Args: complete.PredictDirs,
|
2017-05-05 16:25:27 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
list := complete.Command{
|
|
|
|
Flags: complete.Flags{
|
|
|
|
"-e": complete.PredictNothing,
|
|
|
|
"-f": complete.PredictAnything,
|
|
|
|
"-json": complete.PredictNothing,
|
|
|
|
},
|
2017-05-06 11:47:27 -05:00
|
|
|
Args: complete.PredictDirs,
|
2017-05-05 16:25:27 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
tool := complete.Command{
|
|
|
|
Flags: complete.Flags{
|
|
|
|
"-n": complete.PredictNothing,
|
|
|
|
},
|
|
|
|
Args: complete.PredictAnything,
|
|
|
|
}
|
|
|
|
|
|
|
|
clean := complete.Command{
|
|
|
|
Flags: complete.Flags{
|
|
|
|
"-i": complete.PredictNothing,
|
|
|
|
"-r": complete.PredictNothing,
|
|
|
|
"-n": complete.PredictNothing,
|
|
|
|
"-x": complete.PredictNothing,
|
|
|
|
},
|
2017-05-06 11:47:27 -05:00
|
|
|
Args: complete.PredictDirs,
|
2017-05-05 16:25:27 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
env := complete.Command{
|
|
|
|
Args: complete.PredictAnything,
|
|
|
|
}
|
|
|
|
|
|
|
|
bug := complete.Command{}
|
|
|
|
version := complete.Command{}
|
|
|
|
|
|
|
|
fix := complete.Command{
|
2017-05-06 11:47:27 -05:00
|
|
|
Args: complete.PredictDirs,
|
2017-05-05 16:25:27 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
// commands that also accepts the build flags
|
|
|
|
for name, options := range build.Flags {
|
|
|
|
test.Flags[name] = options
|
|
|
|
run.Flags[name] = options
|
|
|
|
list.Flags[name] = options
|
|
|
|
vet.Flags[name] = options
|
|
|
|
}
|
|
|
|
|
|
|
|
gogo := complete.Command{
|
2017-05-05 10:06:31 -05:00
|
|
|
Sub: complete.Commands{
|
2017-05-05 16:25:27 -05:00
|
|
|
"build": build,
|
|
|
|
"install": build, // install and build have the same flags
|
|
|
|
"run": run,
|
|
|
|
"test": test,
|
|
|
|
"fmt": fmt,
|
|
|
|
"get": get,
|
|
|
|
"generate": generate,
|
|
|
|
"vet": vet,
|
|
|
|
"list": list,
|
|
|
|
"tool": tool,
|
|
|
|
"clean": clean,
|
|
|
|
"env": env,
|
|
|
|
"bug": bug,
|
|
|
|
"fix": fix,
|
|
|
|
"version": version,
|
2017-05-05 10:01:27 -05:00
|
|
|
},
|
2017-05-05 10:06:31 -05:00
|
|
|
Flags: complete.Flags{
|
2017-05-05 13:59:10 -05:00
|
|
|
"-h": complete.PredictNothing,
|
2017-05-05 10:06:31 -05:00
|
|
|
},
|
|
|
|
}
|
2017-05-05 10:01:27 -05:00
|
|
|
|
2017-05-06 23:59:42 -05:00
|
|
|
complete.Run("go", gogo)
|
2017-05-05 10:01:27 -05:00
|
|
|
}
|