payeecmd

package
v0.40.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 24, 2026 License: Apache-2.0 Imports: 5 Imported by: 1 module, 1 package

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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

func (*Command) Bind

func (c *Command) Bind(fs FlagSet) *Flags

Bind adds the verbs' flags to fs: -out (key) and -in-flight (settle).

func (*Command) Help

func (c *Command) Help() string

Help is the verbs' help, in the application's name.

func (*Command) Run

func (c *Command) Run(ctx context.Context, f *Flags, pos []string) error

Run runs the verb pos names (pos is what is left after the flags): key, or settle with the ledgers' paths.

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.

type Flags

type Flags struct {
	Out      string
	InFlight int
}

Flags are the verbs' flags, bound to an application's flag set.

type Session

type Session struct {
	Payer  payee.Payer
	Record payee.Record
	Pool   payee.Pool
	Close  func()
}

Session is what settle needs of an opened home: the payee's purse, its record of what is settled, its pool (reported when set), and Close, which settle calls when it is done (nil is nothing to close).

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL