Features
- Standard flags -
--github-issue,--verbose,--versionout of the box - Output formatting - Tables, lists, headers, code blocks
- Markdown mode - GitHub issue-friendly output with
--github-issue - Cross-platform - Browser opening for macOS, Linux, Windows
- Context handling - Timeouts and cancellation
Usage
package main
import (
"fmt"
"os"
"www.ubuntusoftware.net/pkg/cli"
)
func main() {
app := cli.New("myapp", "v1.0.0")
err := app.Run(os.Args[1:], func(c *cli.Context) error {
if len(c.Args) == 0 {
return fmt.Errorf("command required")
}
switch c.Args[0] {
case "list":
c.Header("Items")
table := c.NewTable("NAME", "VALUE")
table.Row("foo", "bar")
table.Row("baz", "qux")
table.Flush()
case "open":
return c.Open("https://example.com")
}
return nil
})
if err != nil {
fmt.Fprintf(os.Stderr, "ERROR: %v\n", err)
os.Exit(1)
}
}
Output Modes
Normal output:
Items
=====
NAME VALUE
foo bar
baz qux
With --github-issue flag:
## Items
| NAME | VALUE |
|--------|--------|
| foo | bar |
| baz | qux |
Context Methods
| Method | Description |
|---|---|
c.Header(title) | Print section header |
c.KeyValue(key, val) | Print key-value pair |
c.NewTable(headers...) | Create table |
c.List(items...) | Print bulleted list |
c.Code(code) | Print code block |
c.Success(msg) | Print success message |
c.Warning(msg) | Print warning |
c.Open(url) | Open URL in browser |