class Jargon::Result

Overview

Outcome of parsing arguments. Carries the parsed #data, any validation #errors, and the resolved #subcommand, plus flags describing meta-requests (help, shell completion) that run acts on automatically. A pending help/completion request is not a validation outcome — check #help_requested?/#completion_requested? before treating #errors as final.

Defined in:

jargon/result.cr

Constructors

Instance Method Summary

Constructor Detail

def self.new(data : JSON::Any, errors : Array(String) = [] of String, subcommand : String | Nil = nil, help_requested : Bool = false, help_subcommand : String | Nil = nil, completion_shell : String | Nil = nil) #

[View source]
def self.new(data : Hash(String, JSON::Any), errors : Array(String) = [] of String, subcommand : String | Nil = nil, help_requested : Bool = false, help_subcommand : String | Nil = nil, completion_shell : String | Nil = nil) #

[View source]

Instance Method Detail

def [](key : String) : JSON::Any #

Fetch a top-level value, raising KeyError if absent.


[View source]
def []?(key : String) : JSON::Any | Nil #

Fetch a top-level value, or nil if absent.


[View source]
def completion_requested? : Bool #

True when --completions <shell> was requested.


[View source]
def completion_shell : String | Nil #

The shell passed to --completions (e.g. "bash"), or nil if not requested.


[View source]
def data : JSON::Any #

[View source]
def errors : Array(String) #

[View source]
def help? : Bool #

Alias for #help_requested?.


[View source]
def help_requested? : Bool #

[View source]
def help_subcommand : String | Nil #

Which subcommand's help was requested (nil = top-level help).


[View source]
def subcommand : String | Nil #

Resolved subcommand name, space-separated for nested commands; nil for a flat CLI or when no subcommand matched.


[View source]
def to_json : String #

The parsed data as a compact JSON string.


[View source]
def to_pretty_json : String #

The parsed data as an indented JSON string.


[View source]
def valid? : Bool #

True when parsing produced no validation errors. Note a help/completion request is also error-free, so guard those separately when it matters.


[View source]