cli

package
v1.3.8 Latest Latest
Warning

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

Go to latest
Published: Aug 7, 2026 License: AGPL-3.0 Imports: 6 Imported by: 0

Documentation

Overview

Package cli holds common-flag glue: the Options struct cobra binds the truly provider-agnostic flags onto, and provider-agnostic validation. Provider-specific flags (model, size, aspect ratio, quality, …) live inside each provider's BindFlags/ReadFlags.

Index

Constants

View Source
const SeparatorFlagDefault = `\n\n`

SeparatorFlagDefault is a blank line in escaped form, so --help prints (default "\n\n") on one line.

Variables

View Source
var CommonFlagNames = map[string]bool{
	"prompt":         true,
	"separator":      true,
	"output":         true,
	"filename":       true,
	"count":          true,
	"input":          true,
	"replace":        true,
	"provider":       true,
	"max-parallel":   true,
	"embed-metadata": true,
	"help":           true,
	"version":        true,
}

CommonFlagNames lists the truly provider-agnostic flag names — the long forms of the flags bound on the root command in commands/root.go. Single source of truth: both the single-shot validation gate and the batch path read from this map. Any flag not listed here must be claimed by at least one provider's Bundle.SupportedFlags.

Functions

func IsBatchPath added in v1.2.1

func IsBatchPath(path string) bool

IsBatchPath returns true if path's extension marks it as a batch file. Delegates to paths.IsBatchFile so cli and batch always agree.

func IsCommonFlag added in v1.2.1

func IsCommonFlag(name string) bool

IsCommonFlag reports whether name is a common (provider-agnostic) flag.

func NormalizeSeparator added in v1.3.7

func NormalizeSeparator(raw string) (string, error)

NormalizeSeparator rejects an empty separator, expands escapes, and puts an unpadded newline-free token on its own line ("---" → "\n---\n").

func ResolvePromptParts added in v1.3.7

func ResolvePromptParts(parts []string, separator, baseDir string) (string, error)

ResolvePromptParts resolves each part through ResolvePromptText and joins them, dropping empty values.

func ResolvePromptText added in v1.2.4

func ResolvePromptText(value, baseDir string) (string, error)

ResolvePromptText resolves a prompt value to literal text: a file path (relative to baseDir, "" = CWD) becomes its trimmed contents, else verbatim.

Types

type Options

type Options struct {
	// Prompts holds the raw -p values in order: text, file paths, or (alone) a batch file.
	Prompts []string
	// Separator is the raw --separator value, normalised by NormalizeSeparator.
	Separator string
	// Prompt is what Validate resolves Prompts to: parts read and joined, or the batch path.
	Prompt           string
	Output           string
	OutputFilename   string
	NumImages        int
	RefInputs        []string
	PreserveFilename bool

	// MaxParallel caps concurrent provider HTTP requests — covers both
	// single-shot per-count fan-out and batch per-entry fan-out via a
	// shared semaphore threaded into api.Params. 0 (default) means
	// unlimited, the pre-existing behaviour.
	MaxParallel int

	// EmbedMetadata embeds prompt/model/provider into PNG output (--embed-metadata).
	EmbedMetadata bool

	// IsBatch is set by Validate when the single -p resolves to a batch file
	// (.yaml/.yml/.json). Callers branch on this to call internal/batch
	// instead of building a single-shot Request.
	IsBatch bool
}

Options holds the truly common CLI flags — same meaning for every provider. Everything provider-specific lives inside each provider's bundle and ends up in Request.Options.

func (*Options) Validate

func (opts *Options) Validate() error

Validate runs provider-agnostic checks:

  • at least one non-empty -p (reading from a file if the value points at a path)
  • tilde expansion in -o, -i
  • -n is in range
  • -i paths exist and contain supported images
  • -f and -r are mutually exclusive (cobra also enforces)
  • -r requires exactly one -i pointing at a single file.

Jump to

Keyboard shortcuts

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