サブコマンド - コマンドグループ - イントロ
前にコマンドを使用してプログラムを作成する方法を読んだことがあります。
ここでは、独自のサブコマンドを持つコマンドを使用してCLIプログラムを作成する方法について説明します。コマンドグループとも呼ばれます。
たとえば、CLIプログラムgit
にはremote
コマンドがあります。
しかし、git remote
には、add
などの独自のサブコマンドがあります。
// git remote alone shows the current remote repositories
$ git remote
origin
// Use -v to make it verbose and show more info
$ git remote -v
origin git@github.com:yourusername/typer.git (fetch)
origin git@github.com:yourusername/typer.git (push)
// git remote add takes 2 CLI arguments, a name and URL
$ git remote add upstream https://github.com/tiangolo/typer.git
// Doesn't output anything, but now you have another remote repository called upstream
// Now check again
$ git remote -v
origin git@github.com:yourusername/typer.git (fetch)
origin git@github.com:yourusername/typer.git (push)
upstream https://github.com/tiangolo/typer.git (fetch)
upstream https://github.com/tiangolo/typer.git (push)
次のセクションでは、このようなサブコマンドを作成する方法について説明します。