class Opal::CLI::Context

Overview

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

Defined in:

opal/cli/context.cr

Constructors

Instance Method Summary

Constructor Detail

def self.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) #

[View source]

Instance Method Detail

def [](name : Symbol) : OptionValue #

Retrieves an option by name


[View source]
def []?(name : Symbol) : OptionValue #

[View source]
def arg(name : Symbol) : String | Nil #

Retrieves a positional argument by name


[View source]
def arg!(name : Symbol) : String #

[View source]
def arg_list(name : Symbol) : Array(String) #

Retrieves an array of positional arguments for variadic definitions


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

Retrieves all variadic or positional arguments without specifying a name


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

[View source]
def array(name : Symbol) : Array(String) #

Strongly-typed array getter


[View source]
def flag?(name : Symbol) : Bool #

Returns true if flag was specified


[View source]
def flags : Hash(Symbol, Bool) #

[View source]
def float(name : Symbol) : Float64 #

[View source]
def float?(name : Symbol) : Float64 | Nil #

Strongly-typed float getter


[View source]
def int(name : Symbol) : Int32 #

[View source]
def int?(name : Symbol) : Int32 | Nil #

Strongly-typed int getter


[View source]
def named_arg_lists : Hash(Symbol, Array(String)) #

[View source]
def named_args : Hash(Symbol, String) #

[View source]
def options : Hash(Symbol, OptionValue) #

[View source]
def pipe? : Bool #

Returns true if STDIN is piped or redirected


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

[View source]
def 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.


[View source]
def stdin_content : String | Nil #

Reads content from STDIN lazily and caches the result


[View source]
def string(name : Symbol) : String #

[View source]
def string?(name : Symbol) : String | Nil #

Strongly-typed string getter


[View source]