cli

package
v0.0.8 Latest Latest
Warning

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

Go to latest
Published: Apr 17, 2026 License: GPL-2.0 Imports: 20 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrDone indicates that the program should end early with a 0 exit code.
	// This can happen if the help message, version message,
	// or a list operation was requested.
	ErrDone = errors.New("done")

	// ErrUnreachable means that there is a coding defect if returned.
	ErrUnreachable = errors.New("unreachable code")

	// ErrUsage means that CLI arguments were invalid,
	// and the usage message should be displayed.
	ErrUsage = errors.New("usage error")
)
View Source
var InfoKeys = []string{
	"cities",
	"default-city",
	"languages",
}

InfoKeys lists types of data which can be queried with the --info CLI option.

View Source
var InitLogging = func() {
	slogger := slog.New(slog.NewJSONHandler(
		os.Stderr,
		&slog.HandlerOptions{
			AddSource: true,
		},
	))
	slog.SetDefault(slogger)

	log.Default().SetFlags(0)
	log.Default().SetOutput(os.Stderr)
	log.Default().SetPrefix("")
}

InitLogging sets up log and slog for program-wide use. By default, we set log to simply output to stderr with no special formatting. slog is configured to for JSON output with source line numbers.

If you replace InitLogging, keep in mind that hebcalfmt uses log for ordinary errors, likely caused externally. slog is for internal errors, likely indicating a bug in hebcalfmt.

View Source
var ProgName = "hebcalfmt"

ProgName affects the messages we display and the default config file path.

View Source
var Version = "v0.0.8"

Functions

func DefaultConfigPath added in v0.0.3

func DefaultConfigPath() string

func NewFlags

func NewFlags() *pflag.FlagSet

NewFlags returns a pflag.FlagSet configured with the flags used by hebcalfmt.

func Run

func Run() int

Run is the entry point for the CLI program. It sets up the program inputs and returns an exit code.

Specifically, it configures logging settings, pulls CLI arguments to parse from os.Args, ensures that filesystem requests get forwarded to os.Open, sets the current time from time.Now, and sets the output writer to os.Stdout.

If you need to modify these, take a look at RunInEnvironment.

func RunInEnvironment added in v0.0.2

func RunInEnvironment(
	args []string,
	files fs.FS,
	now time.Time,
	buildData func(
		cfg *config.Config,
		files fs.FS,
		tmplPath string,
	) (*template.Template, map[string]any, error),
	w io.Writer,
) error

RunInEnvironment takes CLI-style args, a filesystem, and the current time, and prints the result of the requested operation.

`now` uses the computer's timezone for our idea of "now" and the current date, rather than the configured city's timezone. If a date/time in a different timezone is required, the template should set that specially, rather than rely on the timezone embedded in this variable.

NOTE: Even though this behavior is less consistent logically, and, e.g., a computer in Phoenix will use the date in Phoenix when calculating results for New York where it is already the next day, this program is written for humans. Humans would get confused if, e.g., results for Jan. 1 next year get generated when for them it is still Dec. 31, and they didn't specify the date:

hebcalfmt examples/hebcalClassic.tmpl

For those wanting full consistency, they should specify a timezone in the template or on the CLI. For example:

TZ=America/New_York hebcalfmt examples/hebcalClassic.tmpl

Types

This section is empty.

Jump to

Keyboard shortcuts

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