class Exa::ShellCommand
Public Class Methods
extract(string)
click to toggle source
# File lib/exa/shell.rb, line 39 def self.extract(string) tokens = string.split(' ') # p [ :extract, tokens: tokens ] cmd,*args = *tokens # p [ :extract, cmd: cmd, args: args ] new(title: cmd, args: args) end
new(title:,args:)
click to toggle source
# File lib/exa/shell.rb, line 10 def initialize(title:,args:) @title = title @args = args end
Public Instance Methods
evaluate(shell)
click to toggle source
# File lib/exa/shell.rb, line 15 def evaluate(shell) case @title when "ls" then if shell.pwd.children.any? shell.print_collection shell.pwd.children.map(&:name) else shell.print_warning "(no children of #{shell.pwd.path})" end when "cd" then target = Exa.expand(@args.first) if target && !target.empty? shell.change_directory target.first else shell.print_warning "Invalid path for cd: #{@args.first}" end when "mkdir" then target = Exa.recall(@args.first) when "pwd" then shell.print_info shell.pwd.path else shell.print_warning "Unknown command: '#@title'" end end