class

Scroll::CLI

Inherits Shell::AutoComplete::Command < Reference < Object

Constants

DEFAULT_INTERVAL = 40
DEFAULT_LINES = 10
DEFAULT_POLL = 250
DEFAULT_WATCH_TIMEOUT = 10
FLAG_REGISTRY_NAMES = ["--lines", "-n", "--interval", "--force", "--no-force", "--sanitize", "--no-sanitize", "--final", "--no-final", "--null", "--no-null", "--file", "-f", "--from-start", "--poll", "--pid", "--watch-proc", "--watch-proc-timeout", "--sort", "-s", "--reverse", "-r", "--sort-by", "--human", "--progress", "--size", "--size-lines", "--file-size", "--name", "--terminal-progress", "--no-terminal-progress", "--color", "--progress-charset", "--fullscreen", "--no-fullscreen", "--leave"] of ::String

Compile-time flag-name registry (issue #10). The flag macro appends every spelling a declaration produces (canonical, aliases, short form, generated negations, enum shortcut switches) plus the owning property name, and raises on collision. override: true tombstones the prior owner's entries and records its property in OVERRIDDEN_FLAG_IVARS, which every generator consults to skip the replaced declaration. When the command inherits another command (parent: on the command macro), the registries seed from the parent's completed registries — interpolation re-parses the parent's array literal into fresh nodes, so later macro-time mutation of the child's copy never touches the parent. Inherited-vs-own collisions and override: true of an inherited flag then fall out of the issue #10 logic unchanged.

FLAG_REGISTRY_OWNERS = ["lines", "lines", "interval_ms", "force", "force", "sanitize", "sanitize", "final", "final", "null", "null", "file", "file", "from_start", "poll_ms", "pid", "watch_proc", "watch_proc_timeout_s", "sort", "sort", "reverse", "reverse", "sort_by", "human", "progress", "size", "size_lines", "size_file", "name", "terminal_progress", "terminal_progress", "color", "progress_charset", "fullscreen", "fullscreen", "leave"] of ::String
OVERRIDDEN_FLAG_IVARS = [] of ::String
SUBCOMMAND_CLASS_NODES = [] of ::Shell::AutoComplete::Command.class

Macro-time-readable list of this command's direct subcommand classes, parallel to SUBCOMMANDS (which is built at runtime and so can't be enumerated during macro expansion). The subcommand macro pushes each class node here; dispatch reads it to learn subcommand flag arities for routing past a subcommand-only flag (issue #22 follow-up).

SUBCOMMANDS = [] of ::Tuple(String, ::Shell::AutoComplete::Command.class)

Constructors

parse(argv : Array(String)) : self

Class methods

all_help(parent_prefix : String | Nil = nil) : String
color_enabled?(mode : ColorMode, stderr_tty : Bool, no_color : String | Nil, term : String | Nil) : Bool

Auto follows the display: color when STDERR is a terminal, unless NO_COLOR is set or $TERM says the terminal cannot show it.

Source
command_aliases

Alternate names this command answers to when routed as a subcommand, declared with aliases: on the command macro (e.g. aliases: ["mv", "rename"] on a move command). Each alias routes to this command exactly as its canonical name does, is offered in completion, and is listed beside the name in the parent's help. The canonical name is not repeated here.

command_description
command_name
completion_candidates(words : Array(String), cword : Int32, current : String, prev : String) : Array(String)
completion_script(shell : Symbol, executable : String | Nil = nil) : String

Generates the shell completion script. executable, when given, is the command the generated callback invokes for __complete — pass an absolute path so completion runs a specific binary regardless of PATH (useful for a dev build); the command name still registers the completion. Defaults to the command name.

dispatch(argv : Array(String), stdout : IO = STDOUT, stderr : IO = STDERR, rescue_errors : Bool = true, parent_prefix : String | Nil = nil) : Shell::AutoComplete::Command | Nil
expand_count_shorthand(opts : Array(String)) : Array(String)

Translate the shorthand tokens the parser has no notion of: a bare -N (e.g. -20) into --lines N, and -c/-C into --color on/--color off. Everything else is passed through untouched.

A completion callback (__complete <cword> <words...>, emitted by the generated bash/zsh/fish wrappers) is passed through untouched. Rewriting one token into two would shift every word after it without moving cword, so the shell would be offered candidates for the wrong word.

Source
external_subcommand_dirs

Directories searched for external subcommands (external_subcommands). With search_path: set, the configured entries are resolved once — relative ones against the running binary's directory — so the lookup is independent of PATH. Otherwise the PATH directories are used, git style. Returns an empty list when the feature is off.

external_subcommand_names(prefix : String) : Array(String)

External subcommand names (the <word> in <command_name>-<word>) discovered on the search path, prefix-filtered, deduplicated, in search-path order. Used to offer external subcommands in completion.

external_subcommand_path(word : String) : String | Nil

Resolves an external subcommand word to an executable path, or nil. A word with a path separator is never looked up. With search_path: the configured dirs are scanned in order; otherwise PATH is used.

help(parent_prefix : String | Nil = nil) : String
qualified_name(parent_prefix : String | Nil = nil) : String

Builds this command's fully qualified path. With no parent_prefix the command is the root, so its bare command_name is the whole path; otherwise the parent's path is prepended (e.g. "hf scrape").

shell_completion_flag_name
subcommand_named(name : String) : ::Shell::AutoComplete::Command.class | Nil

Resolves a token to a subcommand class by its canonical name or any of its declared aliases:. A canonical-name match on any subcommand wins over an alias match, so an alias can never shadow another command's real name.

transform_size(value : String) : Int64

Parse a --size value into a byte count: an integer, or a decimal with a 1024-based suffix (100b, 1.1k, 2.5GiB).

Source
transform_sort_key(value : String) : SortKey

Parse a --sort-by SPEC into a SortKey. A fully slash-delimited /.../ value is a PCRE2 regex; anything else must be a 1-based integer column.

Source
version_name

The program name shown by --version and the version subcommand; set with the tool_name macro (a TOOL_NAME constant, inherited through parent:), defaulting to the command's name — itself defaulting to the basename of PROGRAM_NAME.

version_string

The version string shown by --version and the version subcommand. Resolution order: the tool_version macro's TOOL_VERSION constant (inherited through parent:); then the nearest VERSION constant visible from this class (the class itself, each enclosing namespace, the top level, or an inherited command) — emitted as a plain constant reference so Crystal's own lexical lookup picks the nearest one; finally the project's shards version, captured at compile time.

Instance methods

__before_run_hook_0__

Run the cross-flag rules after parsing, before run. As a hook they cannot be forgotten by a future entry point the way an explicit call at the top of run can.

Source
color
color=(color : ColorMode)
color?

Whether the progress line is colorized, for the terminal this run has.

Source
file

Path-typed, so the generated completions delegate to the shell's own filesystem completion for this flag's value.

file=(file : Path | Nil)

Path-typed, so the generated completions delegate to the shell's own filesystem completion for this flag's value.

file?

True when following a file. Passed to Runner as the "mode implies null" input so file mode is silent on STDOUT unless --no-null re-enables teeing.

Source
final
final=(final : Bool)
final?
Source
flag_given?(name : Symbol | String) : Bool

Whether the named flag (by declaration name) was explicitly given on the command line, under any of its spellings: canonical, aliases, short form, generated --no- negations, and enum shortcut switches. Distinguishes an explicit value (even one equal to the default, or an explicit --no-x) from the flag being left untouched.

force
force=(force : Bool)
force?

Bool predicates, so the rest of the codebase reads config.force? rather than the plain property the macro generates.

Source
from_start
from_start=(from_start : Bool)
from_start?
Source
fullscreen
fullscreen=(fullscreen : Bool)
fullscreen?
Source
human
human=(human : Bool)
human?
Source
interval_ms
interval_ms=(interval_ms : Int32)
leave
leave=(leave : Bool)
leave?
Source
lines
lines=(lines : Int32)
name

A Path rather than a String so the shells complete it as a filename; any string is a valid Path, so an arbitrary label still parses.

name=(name : Path | Nil)

A Path rather than a String so the shells complete it as a filename; any string is a valid Path, so an arbitrary label still parses.

name_text

The --name label, sanitized of control bytes when the display draws it.

Source
null

Tri-state: unset (nil), --null (true), --no-null (false). Resolved in Runner against any mode that implies null, so --no-null can override --file.

null=(null : Bool | Nil)

Tri-state: unset (nil), --null (true), --no-null (false). Resolved in Runner against any mode that implies null, so --no-null can override --file.

pid
pid=(pid : Int32 | Nil)
poll_ms
poll_ms=(poll_ms : Int32)
progress
progress=(progress : Bool)
progress?

Naming any part of the input size, or a label, turns the progress line on.

Source
progress_charset
progress_charset=(progress_charset : Progress::Charset)
reverse
reverse=(reverse : Bool)
reverse?
Source
run_before_hooks

Invokes every before_run hook in the class hierarchy, parent-first, on this instance. Called by dispatch between parse and run.

sanitize
sanitize=(sanitize : Bool)
sanitize?
Source
size

The three size options all turn --progress on, the way --sort-by turns on --sort: naming a size is only useful to the progress line.

size=(size : Int64 | Nil)

The three size options all turn --progress on, the way --sort-by turns on --sort: naming a size is only useful to the progress line.

size_file
size_file=(size_file : Path | Nil)
size_lines
size_lines=(size_lines : Int64 | Nil)
sort
sort=(sort : Bool)
sort?

--sort-by and --human both imply --sort.

Source
sort_by
sort_by=(sort_by : SortKey | Nil)
terminal_progress

Tri-state, like --null: nil asks the terminal what it is, true and false settle it without asking. --no-terminal-progress therefore also means "do not query the terminal at all".

terminal_progress=(terminal_progress : Bool | Nil)

Tri-state, like --null: nil asks the terminal what it is, true and false settle it without asking. --no-terminal-progress therefore also means "do not query the terminal at all".

validate!

Cross-flag rules the per-flag types cannot express. Raises ParseError so dispatch reports it the same way it reports a bad flag value.

Source
watch_proc
watch_proc=(watch_proc : Bool)
watch_proc?
Source
watch_proc_timeout_s
watch_proc_timeout_s=(watch_proc_timeout_s : Int32)

Macros

subcommand(klass)

Nested types