class

Opal::CLI::Context

Inherits Reference < Object

Context passed into command run blocks containing resolved arguments and flags.

Constructors

new(flags : Hash(Symbol, Bool) = Hash(Symbol, Bool).new, options : Hash(Symbol, Array(String) | Bool | Float64 | Int32 | String | Nil) = Hash(Symbol, OptionValue).new, args : Array(String) = Array(String).new, named_args : Hash(Symbol, String) = Hash(Symbol, String).new, named_arg_lists : Hash(Symbol, Array(String)) = Hash(Symbol, Array(String)).new, raw_args : Array(String) = Array(String).new)
Source

Instance methods

[](name : Symbol) : OptionValue

Retrieves an option by name

Source
[]?(name : Symbol) : OptionValue
Source
arg(name : Symbol) : String | Nil

Retrieves a positional argument by name

Source
arg!(name : Symbol) : String
Source
arg_list(name : Symbol) : Array(String)

Retrieves an array of positional arguments for variadic definitions

Source
arg_list

Retrieves all variadic or positional arguments without specifying a name

Source
args
Source
array(name : Symbol) : Array(String)

Strongly-typed array getter

Source
flag?(name : Symbol) : Bool

Returns true if flag was specified

Source
flags
Source
float(name : Symbol) : Float64
Source
float?(name : Symbol) : Float64 | Nil

Strongly-typed float getter

Source
int(name : Symbol) : Int32
Source
int?(name : Symbol) : Int32 | Nil

Strongly-typed int getter

Source
named_arg_lists
Source
named_args
Source
options
Source
pipe?

Returns true if STDIN is piped or redirected

Source
raw_args
Source
read_input_or_arg(arg_name : Symbol | Nil = nil) : String | Nil

Unified input reader: checks explicit argument first (file, '-', or text), and falls back to STDIN pipe if no argument was passed.

Source
stdin_content

Reads content from STDIN lazily and caches the result

Source
string(name : Symbol) : String
Source
string?(name : Symbol) : String | Nil

Strongly-typed string getter

Source