Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/neonxp/app
Last synced: about 1 month ago
JSON representation
- Host: GitHub
- URL: https://github.com/neonxp/app
- Owner: neonxp
- License: gpl-3.0
- Created: 2021-04-05T20:03:05.000Z (almost 4 years ago)
- Default Branch: master
- Last Pushed: 2021-04-05T20:40:16.000Z (almost 4 years ago)
- Last Synced: 2024-06-20T12:00:06.535Z (7 months ago)
- Language: Go
- Size: 18.6 KB
- Stars: 0
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# app
[![Go Reference](https://pkg.go.dev/badge/github.com/neonxp/app.svg)](https://pkg.go.dev/github.com/neonxp/app)
Simple cli applications runner.
## Usage
Commands must implements `app.Command` interface:
```go
type exampleCommand struct {
test string
}func (c *exampleCommand) Name() string {
return "example"
}func (c *exampleCommand) Usage() string {
return "just example command"
}func (c *exampleCommand) Flags() *flag.FlagSet {
fs := flag.NewFlagSet(c.Name(), flag.ExitOnError)
fs.StringVar(&c.test, "test", "value", "test flag")
return fs
}func (c *exampleCommand) Run(args []string) error {
fmt.Printf("Runned %s command with flag -test=%s and args: %v", c.Name(), c.test, args)
return nil
}
```Main file example:
```go
package mainimport "github.com/neonxp/app"
func main() {
app := app.New([]app.Command{
exampleCommand{}, // <- Register command
})
if err := app.Start(os.Args); err != nil { // <- Run!
fmt.Println(err)
os.Exit(1)
}
}
```That's all!
[Full example](/example/example.go)