Open3
go-to-k/delstack のソースコード見て実践的な Go の書き方を勉強する
help
$ ./delstack -h
NAME:
delstack - A CLI tool to force delete the entire CloudFormation stack.
USAGE:
delstack [global options] [arguments...]
GLOBAL OPTIONS:
--stackName value, -s value CloudFormation stack name
--profile value, -p value AWS profile name
--region value, -r value AWS region
--interactive, -i Interactive Mode (default: false)
--help, -h show help
tree
$ tree -d
.
├── cmd
│ └── delstack
├── internal
│ ├── app
│ ├── io
│ ├── operation
│ ├── resourcetype
│ └── version
├── pkg
│ └── client
└── testdata
└── yamldir
12 directories
CLI コマンド作れる urfave/cliv2 を見てみると cli.App
の Action が諸々パースされてから実際に動作するロジックらしい
CLI のロジック部分である func (a *App) getAction() func(c *cli.Context) error
を GitHub Copilot Labs に説明させてみた(それほど量多くないけど)
Here is the explanation for the code above:
- First, we check if the interactive mode is enabled or not.
- If the interactive mode is enabled, we call the doInteractiveMode() method to get the target resource types and the keyword to filter the stack names.
- If the interactive mode is disabled, we get all the resource types without filtering.
- If the interactive mode is enabled and the stack name is not specified, we call the ListStacksFilteredByKeyword() method to get the stack names. Then, we call the selectStackName() method to select one of the stack names.
- If the interactive mode is enabled and the stack name is specified, we use the stack name specified by the command option.
- We create the CloudFormationStackOperator instance with the target resource types.
- If the interactive mode is enabled and the stack name is not specified, we create the OperatorCollection instance with the target resource types. Otherwise, we create the OperatorCollection instance with all the resource types.
- We create the OperatorManager instance with the OperatorCollection instance.
- We create the CloudFormationStackOperator instance with the OperatorFactory instance.
- We call the DeleteCloudFormationStack() method to delete the stack.