Goコマンドの種類(と概要)を知る
「知る」と大きくでましたが、言い直すとgo --help
or go help
の結果を訳しただけ・・・です。
> go version go version go1.19.3 windows/amd64
> go help Go is a tool for managing Go source code. Usage: go <command> [arguments] The commands are: bug start a bug report build compile packages and dependencies clean remove object files and cached files doc show documentation for package or symbol env print Go environment information fix update packages to use new APIs fmt gofmt (reformat) package sources generate generate Go files by processing source get add dependencies to current module and install them install compile and install packages and dependencies list list packages or modules mod module maintenance work workspace maintenance run compile and run Go program test test packages tool run specified go tool version print Go version vet report likely mistakes in packages Use "go help <command>" for more information about a command. Additional help topics: buildconstraint build constraints buildmode build modes c calling between Go and C cache build and test caching environment environment variables filetype file types go.mod the go.mod file gopath GOPATH environment variable gopath-get legacy GOPATH go get goproxy module proxy protocol importpath import path syntax modules modules, module versions, and more module-get module-aware go get module-auth module authentication using go.sum packages package lists and patterns private configuration for downloading non-public code testflag testing flags testfunc testing functions vcs controlling version control with GOVCS Use "go help <topic>" for more information about that topic.
使い方
go <command> [arguments]
goと書いたあとにコマンドを指定し、さらに必要な引数がある場合は追加する、といった感じのようですね。
Commands
コマンド名 | 概要 |
---|---|
bug | バグ報告を開始する |
build | パッケージや依存関係にあるソースコードをコンパイルする(実行ファイルを作成する) |
clean | オブジェクトやキャッシュのファイルを削除する |
doc | パッケージやシンボルのドキュメントを表示する |
env | Goの環境情報を出力する |
fix | 新しいAPIを使うようにパッケージを更新する |
fmt | ソースコードをフォーマットする(gofmt) |
generate | ソースを生成する |
get | go.modに依存関係を追記し、インストールする |
install | パッケージと依存関係にあるソースコードをコンパイルし、インストールする |
list | パッケージやモジュールをリスト出力する |
mod | go.modファイルのメンテナンス |
work | go.workファイルのメンテナンス |
run | ビルドし、Goプログラムを実行する |
test | パッケージのテストコードを実行する |
tool | 設定されたGoツールの実行 |
version | Goのバージョン表示 |
vet | ソースコード内で間違えてそうなところを検出する |
中でも特にgenerate
、mod
、work
、tool
、vet
あたりは、訳したところでよくわかりませんでした。
しかしコマンドの種類を把握し、それぞれざっくり検索結果を読みながら仕入れられました。
topicsは、コマンドそのものとは違うもののヘルプとして提供されている情報郡といったところでしょうか。
> go help go.mod A module version is defined by a tree of source files, with a go.mod file in its root. When the go command is run, it looks in the current directory and then successive parent directories to find the go.mod marking the root of the main (current) module. The go.mod file format is described in detail at https://golang.org/ref/mod#go-mod-file. To create a new go.mod file, use 'go mod init'. For details see 'go help mod init' or https://golang.org/ref/mod#go-mod-init. To add missing module requirements or remove unneeded requirements, use 'go mod tidy'. For details, see 'go help mod tidy' or https://golang.org/ref/mod#go-mod-tidy. To add, upgrade, downgrade, or remove a specific module requirement, use 'go get'. For details, see 'go help module-get' or https://golang.org/ref/mod#go-get. To make other changes or to parse go.mod as JSON for use by other tools, use 'go mod edit'. See 'go help mod edit' or https://golang.org/ref/mod#go-mod-edit.
なるほど、go.modとはそのプログラムで使われているモジュールの設定ファイルらしいです。
このような感じで、それぞれ書いてありますが
go help <command>
go help <topic>
とすることで詳細情報を手に入れられるようです。