https://github.com/pranavnt/mamba
Simple, intuitive Golang package for building CLIs
https://github.com/pranavnt/mamba
cli command-line go golang mamba
Last synced: 3 months ago
JSON representation
Simple, intuitive Golang package for building CLIs
- Host: GitHub
- URL: https://github.com/pranavnt/mamba
- Owner: pranavnt
- License: mit
- Created: 2021-03-09T23:56:48.000Z (over 4 years ago)
- Default Branch: main
- Last Pushed: 2021-07-18T23:55:21.000Z (about 4 years ago)
- Last Synced: 2025-07-19T21:19:16.557Z (3 months ago)
- Topics: cli, command-line, go, golang, mamba
- Language: Go
- Homepage:
- Size: 45.9 KB
- Stars: 11
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
Mamba
![]()
Build command line apps in Go with ease
## Installation 💻
To install mamba, run the following command in terminal:
```bash
go get github.com/pranavnt/mamba
```To use it, include it in your imports:
```go
import (
"github.com/pranavnt/mamba"
)
```## Usage 📝
For the usage example, we'll create a command line app called `ace`, which is used for deploying apps.
First, we will want to initialize a CLI app, which is done through:
```go
app := mamba.New()
```Next, we will want to add commands to our app, which you do through `AddCommand`:
```go
app.AddCommand("deploy {fileName}", deploy)
```The command above creates the deploy command, which takes in a parameter for `fileName` (the user will enter this). For example, this would handle `ace run hello.py`.
Now, let's write code for the function that handles this command, called `deploy`. This function must accept one parameter (of type `mamba.Dict`).
```go
func deploy(params mamba.Dict) {
fmt.Println("About to deploy " + params["fileName"].(string))
// code for deployment
}
```Here is a sample function where you can read and print the fileName. You can later use this parameter to actually deploy the project in this app.
Finally, in order to run the code, you need to add:
```go
app.Run(os.Args)
```Here, you are actually running the app, and `os.Args` are the command line arguments that are parsed by mamba. You're done!
The full code:
```go
package mainimport (
"fmt"
"os"
"github.com/pranavnt/mamba"
)func main() {
app := mamba.New()
app.AddCommand("deploy {directory}", deploy)
app.Run(os.Args)
}func deploy(params mamba.Dict) {
fmt.Println("About to deploy " + params["directory"].(string))
// other code for deployment
}
```