Documentation
¶
Overview ¶
Package payeecmd is the payee verbs of an application's command line, the same in every application: payee key, which hands a host its payee key, and payee settle, which takes the payments a host recorded into the payee's pool. Package payee does the work; this package is the verbs, their flags, their help and their words.
An application gives a Command its name, the directory that holds the payee's identity file, its output streams, the errors that carry its exit codes, and a way to open its home for settle. It keeps its own flag set and parsing, which this package binds to through FlagSet:
c := &payeecmd.Command{App: "app", KeyDir: home, Stdout: stdout, Stderr: stderr,
Usage: usage, Refused: refused, Open: openForSettle}
fs := flag.NewFlagSet("payee", flag.ContinueOnError)
fs.Usage = func() { fmt.Fprintln(stderr, c.Help()) }
f := c.Bind(fs)
if err := fs.Parse(args); err != nil {
return err
}
return c.Run(ctx, f, fs.Args())
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Command ¶
type Command struct {
// App is the command's name, as a user types it: it names the host's
// key variable (payee.KeyEnv), the command that creates a missing home
// (`<App> init`), the help, and the labels a settled payment carries.
App string
// KeyDir is the directory that holds the home's identity file
// (payee.IdentityFile), whose key is the payee key.
KeyDir string
// Stdout takes the verbs' output. Stderr takes notes and the lines of
// payments not settled; nil discards them.
Stdout, Stderr io.Writer
// Note, when set, writes a note in the application's way (a quiet flag,
// a prefix); nil writes the note and a newline to Stderr.
Note func(format string, args ...any)
// Usage and Refused make the application's errors for a misuse and for
// a refusal, which carry its exit codes; nil is a plain error.
Usage, Refused func(format string, args ...any) error
// Words, when set, puts a refusal of the purse in the application's
// words (payee.Settler.Words).
Words func(error) error
// Open opens the home for settle.
Open func(ctx context.Context) (*Session, error)
}
Command is one application's payee verbs.
Example ¶
An application binds the verbs to its own flag set and runs the one the arguments name. Here a misuse is refused before any home is opened.
package main
import (
"context"
"flag"
"fmt"
"os"
"strings"
"github.com/lightwebinc/bcommon/payeecmd"
)
func main() {
c := &payeecmd.Command{App: "sample", KeyDir: os.TempDir(), Stdout: os.Stdout}
fs := flag.NewFlagSet("payee", flag.ContinueOnError)
f := c.Bind(fs)
_ = fs.Parse([]string{"-in-flight", "0", "settle", "payments.jsonl"})
fmt.Println(c.Run(context.Background(), f, fs.Args()))
fmt.Println(strings.SplitN(c.Help(), "\n", 2)[0])
}
Output: -in-flight 0 is outside 1 to 64: payments broadcast and not yet mined at once usage: sample payee key -out FILE
type FlagSet ¶
type FlagSet interface {
StringVar(p *string, name, value, usage string)
IntVar(p *int, name string, value int, usage string)
}
FlagSet is the part of a flag set Bind uses; *flag.FlagSet is one.