Class: Exa::ShellCommand
- Inherits:
-
Object
- Object
- Exa::ShellCommand
- Defined in:
- lib/exa/shell.rb
Class Method Summary collapse
Instance Method Summary collapse
- #evaluate(shell) ⇒ Object
-
#initialize(title:, args:) ⇒ ShellCommand
constructor
A new instance of ShellCommand.
Constructor Details
#initialize(title:, args:) ⇒ ShellCommand
Returns a new instance of ShellCommand.
10 11 12 13 |
# File 'lib/exa/shell.rb', line 10 def initialize(title:,args:) @title = title @args = args end |
Class Method Details
.extract(string) ⇒ Object
39 40 41 42 43 44 45 |
# 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 |
Instance Method Details
#evaluate(shell) ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# 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.(@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 |