Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/umutbasal/cobra-gen
cobra-gen is a boilerplate code generator for the Cobra CLI framework in Go.
https://github.com/umutbasal/cobra-gen
cli cobra cobra-cli code-generation codegen go golang
Last synced: about 1 month ago
JSON representation
cobra-gen is a boilerplate code generator for the Cobra CLI framework in Go.
- Host: GitHub
- URL: https://github.com/umutbasal/cobra-gen
- Owner: umutbasal
- License: mit
- Created: 2024-07-15T02:58:16.000Z (4 months ago)
- Default Branch: main
- Last Pushed: 2024-07-21T15:11:51.000Z (4 months ago)
- Last Synced: 2024-07-21T17:48:58.236Z (4 months ago)
- Topics: cli, cobra, cobra-cli, code-generation, codegen, go, golang
- Language: Go
- Homepage: https://github.com/umutbasal/cobra-gen
- Size: 55.7 KB
- Stars: 0
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# cobra-gen
`cobra-gen` is a boilerplate code generator for the [Cobra](https://github.com/spf13/cobra) CLI framework in Go.
## Dependencies
- Go
- gofmt
- goimports: Install with `go install golang.org/x/tools/cmd/goimports@latest`## Installation
To install `cobra-gen`, run:
```sh
go install github.com/umutbasal/cobra-gen@latest
```## Usage
### Example: Designing a Simple AWS CLI
Let's create a basic AWS CLI with `cobra-gen` that handles `s3` and `ec2` commands:
- `aws --profile`
- `aws s3 ls mybucket --page-size 10`
- `aws ec2 create-instance`1. **Generate Config**
Convert your commands to the following format and run them in your Go project:
```sh
cobra-gen --profile
cobra-gen s3 ls +mybucket --page-size
cobra-gen ec2 create-instance
```This will generate a YAML configuration file named `.cobra-gen.yaml`. You can modify this file as needed:
```yaml
cmd:
- --profile
- s3:
- ls:
- +mybucket # `+` denotes arguments
- --page-size # `--` denotes flags; do not add values for flags
- ec2:
- create-instance
```2. **Generate Code**
Run `cobra-gen` without any arguments to generate the boilerplate code:
```sh
cobra-gen
```This will create the following files:
- `./cmd/cmd.go`
- `./cmd/s3/ls.go`
- `./cmd/s3/s3.go`
- `./cmd/ec2/create-instance.go`
- `./cmd/ec2/ec2.go`See the [examples/aws](examples/aws) directory for the generated code.
## License
This project is licensed under the MIT License. See the [LICENSE](LICENSE) file for details.