cli

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Sep 16, 2026 License: MIT Imports: 31 Imported by: 0

Documentation

Overview

Package cli is the `zn` command surface: the same commands, flags, output and JSON shapes as the CLI the desktop app bundles, plus `zn tui`.

Index

Constants

This section is empty.

Variables

View Source
var Version = defaultVersion

Version is what `zn --version` and the help banner print.

Functions

func DeriveTitle

func DeriveTitle(body string) string

DeriveTitle is the first non-empty line, stripped of its leading marker and capped at 60 characters, so a captured `- [ ] buy milk` titles the note "buy milk" while the marker stays in the body.

func FindDesktopApp

func FindDesktopApp() (string, error)

FindDesktopApp locates the ZenNotes desktop executable. ZENNOTES_APP_PATH wins; then the usual install locations per platform; then PATH.

func Main

func Main(argv []string) int

Main runs the CLI and returns the exit code.

func OpenBackend

func OpenBackend(target backend.Target) (backend.Backend, error)

OpenBackend binds a target with the user's portable preferences applied.

func ReadStdin

func ReadStdin() string

ReadStdin drains stdin; empty when it is a terminal.

func RenderHelp

func RenderHelp(argv []string) string

RenderHelp is the pretty `zn --help`, colors gated on TTY detection and the NO_COLOR / FORCE_COLOR conventions.

func RenderVersion

func RenderVersion(argv []string) string

RenderVersion is `zn --version`.

func ResolveTargetFromArgs

func ResolveTargetFromArgs(args Args) (backend.Target, error)

ResolveTargetFromArgs picks the vault for an invocation from the global flags.

func TagCounts

func TagCounts(notes []vault.NoteMeta) []tagCount

TagCounts tallies every tag across live notes, most used first.

Types

type Args

type Args struct {
	Positionals []string
	Flags       map[string][]string
}

Args is a parsed command line: positionals plus repeated flags.

zn <command> [<subcommand>] [positional...] [--flag value | --flag=value | -x value]

Repeated flags collect in order. Boolean flags are inferred when no value follows or when the next token starts with `--`.

func Parse

func Parse(argv []string) Args

Parse mirrors the desktop CLI's parser, including its one subtlety: only a dash followed by a letter is a short flag, so `zn capture "- [ ] task"` keeps its task line positional.

func (Args) Bool

func (a Args) Bool(name string) bool

Bool reads a boolean flag.

func (Args) Int

func (a Args) Int(name string) (int, bool)

Int reads a numeric flag; ok is false when absent or not a number.

func (Args) IntOr

func (a Args) IntOr(name string, fallback int) int

IntOr reads a numeric flag with a default.

func (Args) Many

func (a Args) Many(name string) []string

Many lists every value given for a flag.

func (Args) Positional

func (a Args) Positional(n int) string

Positional is the nth positional or "".

func (Args) ResolveBody

func (a Args) ResolveBody(fallbackPositional string) *string

ResolveBody applies the body conventions: `--body "literal"`, `--body -` (stdin), a positional fallback, then piped stdin; nil when nothing.

func (Args) Str

func (a Args) Str(name string) string

Str is the last value or "".

func (Args) String

func (a Args) String(name string) (string, bool)

String is the last value given for a flag, and whether it was given.

type Handler

type Handler func(ctx context.Context, b backend.Backend, args Args) error

Handler runs one command against a resolved backend.

Jump to

Keyboard shortcuts

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