application

package
v0.1.0-dev.20260824001806 Latest Latest
Warning

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

Go to latest
Published: Aug 24, 2026 License: Apache-2.0 Imports: 4 Imported by: 0

Documentation

Overview

Package application defines the per-tool Application handle the workflow framework carries on its runtime environment.

Each tool (lore, star, writ, devlore-test) constructs an Application from its own CLI / config plumbing and hands it to the framework's runtime-environment spec at construction. The Application carries the variable resolver's input sources (flag / config / override maps) plus the tool's program name; the framework reads them uniformly without knowing tool specifics.

Flag projection uses cobra's pflag merged view: a single call to cobra.Command.Flags surfaces both the command's local flags and every persistent flag inherited from its ancestors. NewApplication walks that merged view via pflag.FlagSet.Visit, which yields only flags the user explicitly supplied on the command line — defaults are not stamped into Application.Flags.

Index

Constants

This section is empty.

Variables

View Source
var (
	// Version is the semantic version, e.g. "v0.4.0"; "dev" in an unstamped build.
	Version = "dev"

	// Commit is the short git commit hash; "none" in an unstamped build or outside a repository.
	Commit = "none"

	// BuildDate is the RFC 3339 UTC build timestamp; "unknown" in an unstamped build.
	BuildDate = "unknown"
)

Build-time identity, stamped by the linker and shared by every command.

These are the `-X` targets, and they live here — beside the program name and the tool's other identity — because a build stamps the product once, not once per binary. The build stanzas name exactly these three symbols:

-X github.com/NobleFactor/devlore-cli/pkg/application.Version=$(VERSION)
-X github.com/NobleFactor/devlore-cli/pkg/application.Commit=$(COMMIT)
-X github.com/NobleFactor/devlore-cli/pkg/application.BuildDate=$(BUILD_DATE)

**The path is load-bearing and silently so.** `-X` against a symbol that does not exist is not an error — the linker ignores it and the binary reports its compiled-in default. Every release built before 2026-08-16 shipped that way, because the stanzas named `internal/cli.Version`, where `Version` was only ever a struct field. A package move that leaves these paths behind produces working, testable, correct-looking binaries that report `dev`; only a build-time check comparing what was stamped against what the binary prints can catch it (docs/plans/version-stamping.md).

The defaults are what an unstamped build honestly reports — `go run`, an IDE build, `go build` without the Makefile — and they are deliberately not empty strings.

Functions

This section is empty.

Types

type Application

type Application struct {

	// Name is the tool's program name (e.g., "lore", "star", "writ", "devlore-test").
	//
	// The framework's variable resolver derives its env-var prefix from this value as `strings.ToUpper(Name) + "_"`.
	Name string

	// Flags carries values parsed from command-line arguments.
	//
	// Consumed by the variable resolver as its flag source. Keys are snake-case (normalized from
	// cobra/pflag's kebab-case at [NewApplication] time so `--dry-run` lands under `Flags["dry_run"]`); values are the
	// typed Go value pflag parsed.
	//
	// Populated by [NewApplication] via [pflag.FlagSet.Visit] — only flags the user explicitly supplied are present. A
	// lookup for a flag the user did not pass returns the zero value via map-zero semantics.
	Flags map[string]any

	// Config carries values loaded from configuration files.
	//
	// Consumed by the variable resolver as its config source.
	Config map[string]any

	// Overrides carries programmatic-force values applied at highest precedence.
	//
	// Consumed by the variable resolver as its override source.
	Overrides map[string]any
}

Application is the tool-side handle the workflow framework reads through its runtime environment.

It carries the variable-resolver source maps and the tool's program name. Each tool owns its own instance and projects its native CLI / config plumbing into the three maps.

Flags, Config, and Overrides are passed verbatim to the framework's variable resolver when the runtime environment is constructed. Framework code that needs a specific flag (e.g., "dry-run") reads from Application.Flags directly without invoking the resolver.

func NewApplication

func NewApplication(name string, cmd *cobra.Command) *Application

NewApplication constructs an Application from a cobra command's parsed flag state.

Walks the command's merged pflag set (cobra merges persistent + local automatically when cobra.Command.Flags is called on the leaf) and stamps each user-supplied flag into Application.Flags under its snake-case form (cobra's kebab-case flag name with hyphens replaced by underscores). Defaults are not stamped.

The kebab→snake normalization makes Application.Flags uniform with the variable resolver's parameter-name conventions (snake_case throughout); the resolver's flag-source step matches the parameter name verbatim against the snake-case keys.

Config and Overrides are left nil. Tools that source either layer populate them via direct field assignment after construction.

Parameters:

  • `name`: the tool's program name (e.g., "lore", "writ").
  • `cmd`: the cobra command whose merged flag set drives Flags. Must be non-nil.

Returns:

  • *Application: the constructed Application with Name and Flags set.

func (*Application) DryRun

func (a *Application) DryRun() bool

DryRun reports whether the user supplied `--dry-run` on the active command.

Reads Application.Flags under the canonical snake-case key "dry_run" (normalized from cobra's "dry-run" at NewApplication time). Returns false when the flag was not supplied, when its value is not a bool, or when Application.Flags is nil.

Returns:

  • `bool`: true when `--dry-run` was supplied; false otherwise.

Jump to

Keyboard shortcuts

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