go get github.com/lazarcloud/cli-utils
Built with by Lazar Dragos George. The content may not be distributed without my permission.
13 February 2025
cli-utils is a minimalistic and efficient Go package for building command-line interfaces.
Creating CLI applications in Go often requires boilerplate code for handling commands, arguments, and execution logic. cli-utils simplifies this process by providing a structured way to define and execute commands while ensuring smooth argument validation and error handling.
Install the package using:
go get github.com/lazarcloud/cli-utils
Here’s an example of how to use cli-utils in a real project:
An example backup CLI tool.
package main
import (
"cli_backup/cli"
"cli_backup/commands"
)
var COMMANDS = cli.Commands{
commands.HelloCommand,
commands.CheckCommand,
commands.BackupCommand,
commands.DeleteCommand,
commands.DownloadCommand,
}
func main() {
err := cli.NewCLI("cli_backup", COMMANDS, nil).Run()
if err != nil {
panic(err)
}
}
A basic hello commands that says hello to any name.
package commands
import (
"cli_backup/cli"
"fmt"
)
var HelloCommand = cli.Command{
Name: "hello",
Description: "Prints hello message",
Args: cli.Args{
cli.Arg{
Name: "name",
Description: "Name to say hello to",
Required: false,
Default: "lazar",
},
},
Run: func(args cli.RuntimeArgs, c *cli.CLI) error {
name := args.Get("name")
fmt.Printf("Hello, %s!\n", name)
return nil
},
}
With cli-utils, you can create structured and maintainable CLI applications with minimal effort. Whether you're building a simple utility or a complex CLI tool, cli-utils provides the foundation you need to streamline development.
Built with by Lazar Dragos George. The content may not be distributed without my permission.