ComponeGo Framework + Urfave CLI

This package provides easy integration of the Componego Framework with Urfave CLI V2.
All Urfave CLI features are supported.
You can use a convenient solution for processing command line arguments with the Componego Framework together.
Documentation
The application must be launched in a special way for this to work.
main.go
package main
import (
"github.com/componego/componego"
"github.com/componego/urfave-cli-integration"
"github.com/YOUR-USER-OR-ORG-NAME/YOUR-REPO-NAME/internal/application"
)
func main() {
urfave_cli_integration.RunAndExit(application.New(), componego.ProductionMode)
}
This is necessary because the current integration may launch different componego applications depending on the command line arguments.
Inside the application, you can access the Urfave CLI context.
You can also modify any command options. For example, add a couple of required flags for the command line.
application.go
package application
import (
"github.com/componego/componego"
"github.com/componego/urfave-cli-integration"
"github.com/urfave/cli/v2"
)
type Application struct {
}
func New() *Application {
return &Application{}
}
// ApplicationName belongs to interface componego.Application.
func (a *Application) ApplicationName() string {
return "Application Name v0.0.1"
}
// ApplicationCLI belongs to interface urfave_cli_integration.ApplicationCLI.
func (a *Application) ApplicationCLI(cmd *cli.Command) {
cmd.Flags = []cli.Flag{
&cli.StringFlag{
Name: "config",
Usage: "config filename",
Required: true,
},
}
// ...
}
// ApplicationConfigInit belongs to interface componego.ApplicationConfigInit.
func (a *Application) ApplicationConfigInit(_ componego.ApplicationMode, options any) (map[string]any, error) {
cliCtx := options.(*cli.Context) // <----
// ...
}
// ApplicationAction belongs to interface componego.Application.
func (a *Application) ApplicationAction(env componego.Environment, options any) (int, error) {
cliCtx := options.(*cli.Context) // <----
// ...
}
var (
_ componego.Application = (*Application)(nil)
_ componego.ApplicationConfigInit = (*Application)(nil)
_ urfave_cli_integration.ApplicationCLI = (*Application)(nil)
)
Subcommands can be added like this:
// ApplicationCLI belongs to interface urfave_cli_integration.ApplicationCLI.
func (a *Application) ApplicationCLI(cmd *cli.Command) {
cmd.Subcommands = []*cli.Command{
urfave_cli_integration.ToCommand("subcommand", application.New()),
}
// ....
}
Examples available here.
Contributing
We are open to improvements and suggestions. Pull requests are welcome.
License
The source code of the repository is licensed under the MIT license.