class Sshez::Command
Keeps track of the which command the user called
Constants
- ALL
a list of all commands
- PRINTER
Attributes
args[R]
Exposes the name and arguments
name[R]
Exposes the name and arguments
Public Class Methods
new(name, validator, correct_format, args_processor = nil)
click to toggle source
no one should create a command except from this class!
name: can only be one of these [add, remove, list] validator: a proc that returns true only if the input is valid for the command args: the args it self! correct_format: the way the user should run this command args_processor: (optional) a proc that will process the args before setting them
# File lib/sshez/command.rb, line 19 def initialize(name, validator, correct_format, args_processor = nil) @name = name @validator = validator @args = [] @correct_format = correct_format @args_processor = args_processor end
Public Instance Methods
args=(value)
click to toggle source
processes the value passed if a processor was defined
# File lib/sshez/command.rb, line 47 def args=(value) @args = @args_processor ? @args_processor.call(value) : value end
error()
click to toggle source
returns the text that should appear for a user in case of invalid input for this command
# File lib/sshez/command.rb, line 60 def error "Invalid input `#{args.join(',')}` for #{@name}.\nUsage: #{@correct_format}" end
valid?(args)
click to toggle source
validateds the args using the proc previously defined
# File lib/sshez/command.rb, line 53 def valid?(args) @validator.call(args) end