Skip to content
/ mamba Public

Simple, intuitive Golang package for building CLIs

License

Notifications You must be signed in to change notification settings

pranavnt/mamba

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

42 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Mamba

Godoc Reference push workflow result go version

Build command line apps in Go with ease

Installation 💻

To install mamba, run the following command in terminal:

go get github.com/pranavnt/mamba

To use it, include it in your imports:

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:

app := mamba.New()

Next, we will want to add commands to our app, which you do through AddCommand:

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).

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:

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:

package main

import (
	"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
}

About

Simple, intuitive Golang package for building CLIs

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages