class Replr::ArgumentProcessor
Processes command-line arguments
Constants
- COMMANDS
- STACKS
Attributes
arguments[R]
command[R]
libraries[R]
stack[R]
Public Class Methods
new()
click to toggle source
# File lib/replr/argument_processor.rb, line 10 def initialize @arguments = ARGV.map { |argument| argument.downcase.strip } check_argument_length! check_arguments! end
Public Instance Methods
check_argument_length!()
click to toggle source
# File lib/replr/argument_processor.rb, line 16 def check_argument_length! if arguments.empty? puts_usage exit end end
check_arguments!()
click to toggle source
# File lib/replr/argument_processor.rb, line 23 def check_arguments! detect_stack detect_command detect_libraries unless stack || command puts_error "First argument must be either be a command: \t#{COMMANDS.join(' ')}\nor one of a supported stack: \t#{STACKS.join(' ')}" puts_usage exit end end
detect_command()
click to toggle source
# File lib/replr/argument_processor.rb, line 49 def detect_command @command = COMMANDS.detect do |command| arguments[0] == command end end
detect_libraries()
click to toggle source
# File lib/replr/argument_processor.rb, line 55 def detect_libraries @libraries = arguments[1..-1].sort! end
detect_stack()
click to toggle source
# File lib/replr/argument_processor.rb, line 37 def detect_stack detected_stack = STACKS.detect do |stack| arguments[0].match(/^#{stack}:?.*?/) end # return the full stack string (that includes version) # instead of just the stack name if detected_stack @stack = arguments[0] end end
puts_error(string)
click to toggle source
# File lib/replr/argument_processor.rb, line 67 def puts_error(string) STDERR.puts(string) end
puts_usage()
click to toggle source
# File lib/replr/argument_processor.rb, line 59 def puts_usage puts_error "\nUsage: replr <stack> <libraries...>\n\n" puts_error "A single line REPL for your favorite languages & libraries\n\n" puts_error "\t<stack> is now one of #{STACKS.join(', ')}" puts_error "\t<libraries...> is a space separated list of libraries for the stack\n\n" puts_error "More commands:\n\n\treplr prune to delete all replr docker images (this saves space)" end