Skip to content

Commit

Permalink
Add help example
Browse files Browse the repository at this point in the history
  • Loading branch information
cristaloleg committed Oct 28, 2021
1 parent 92936fb commit a7e5569
Showing 1 changed file with 49 additions and 0 deletions.
49 changes: 49 additions & 0 deletions example_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,14 @@ import (
"context"
"fmt"
"net/http"
"os"
"time"

"github.com/cristalhq/acmd"
)

var nopFunc = func(context.Context, []string) error { return nil }

func ExampleRunner() {
const format = "15:04:05"
now, _ := time.Parse("15:04:05", "10:20:30")
Expand Down Expand Up @@ -53,3 +56,49 @@ func ExampleRunner() {

// Output: now: 10:20:30
}

func ExampleHelp() {
cmds := []acmd.Command{
{
Name: "now",
Description: "prints current time",
Do: nopFunc,
},
{
Name: "status",
Description: "prints status of the system",
Do: nopFunc,
},
{
Name: "boom",
Description: "bombom",
Do: nopFunc,
},
}

r := acmd.RunnerOf(cmds, acmd.Config{
AppName: "acmd-example",
AppDescription: "Example of acmd package",
Version: "the best v0.x.y",
Output: os.Stdout,
Args: []string{"help"},
})

if err := r.Run(); err != nil {
panic(err)
}

// Output: Example of acmd package
//
// Usage:
//
// acmd-example <command> [arguments]
//
// The commands are:
//
// boom bombom
// now prints current time
// status prints status of the system
//
// Version: the best v0.x.y
}

0 comments on commit a7e5569

Please sign in to comment.