class Mysh::VarsCommand

The mysh internal variable commands.

Constants

VAR_EXP

The mysh variable parsing regex.

Public Class Methods

new(name, description) click to toggle source

Setup an internal action.

Calls superclass method Mysh::Action::new
# File lib/mysh/internal/vars.rb, line 16
def initialize(name, description)
  @var_name = @equals = @value = nil
  super(name, description)
end

Public Instance Methods

do_command() click to toggle source

Do the actual work here.

# File lib/mysh/internal/vars.rb, line 34
def do_command
  sym = @var_name.to_sym if @var_name

  if @value
    MNV[sym] = @value
  elsif @equals
    MNV[sym] = ""
  elsif @var_name
    puts "$#{@var_name} = #{MNV.get_source(sym)}"
  else
    show_all_values
  end
end
process_command(input) click to toggle source

Execute a command against the internal mysh variables.

# File lib/mysh/internal/vars.rb, line 22
def process_command(input)
  if (match = VAR_EXP.match(input.raw_body))
    @var_name, @equals, @value = match[:name], match[:equals], match[:value]
  else
    @var_name, @equals, @value = nil
  end

  do_command
  :internal
end
show_all_values() click to toggle source

Display all variables neatly.

# File lib/mysh/internal/vars.rb, line 49
def show_all_values
  puts (MNV.keys - ['$'.to_sym])
         .sort
         .map {|sym| ["$" + sym.to_s, MNV.get_source(sym)]}
         .format_output_bullets
end