Class: Linen::CLI
Overview
Defined Under Namespace
Classes: AbstractAmbiguityError, AmbiguousCommandError, AmbiguousPluginError, CommandNotFoundError, PluginNotFoundError
Class Attribute Summary collapse
-
.prompt ⇒ Object
Returns the value of attribute prompt.
Class Method Summary collapse
Class Attribute Details
.prompt ⇒ Object
Returns the value of attribute prompt.
12 13 14 |
# File 'lib/linen/handlers/cli.rb', line 12 def prompt @prompt end |
Class Method Details
.parse_command(input) ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/linen/handlers/cli.rb', line 17 def self::parse_command( input ) ### * nil means ctrl-d, so exit. ### * if they said "quit" or "exit", do so ### * Size == 0 means empty command, so just return. ### ### otherwise, add to history. if input.nil? ### blank line to make ctrl-d not make the error live on the existing line puts ; cleanup and exit elsif input.chomp.size == 0 # empty string return else Readline::HISTORY.push( input ) end plugin, command, *arguments = input.split if ['quit', 'exit'].abbrev.include? plugin cleanup and exit elsif ['help', '?'].abbrev.include? plugin # they entered "help <plugin> <command> or some subset there of, which means # that we have the plugin in command and the command in the first element of args. plugin = command.dup rescue nil command = arguments.shift rescue nil if plugin and command plugin, command = canonicalize( "#{plugin} #{command}" ).split rescue nil # if either plugin or command is nil, lookup will fail; bail return unless plugin = Linen.plugins[ plugin ] return unless command = plugin.commands[ command ] puts command.help elsif plugin return unless plugin = Linen.plugins[ canonicalize( plugin ) ] puts plugin.help else help end elsif plugin.nil? or command.nil? puts "You must enter both a plugin name and a command." else plugin, command, *args = canonicalize( input ).split plugin = Linen.plugins[ plugin ] command = plugin.commands[ command ] execute_command plugin, command, args end end |
.start ⇒ Object
69 70 71 72 73 74 75 76 77 78 79 80 81 |
# File 'lib/linen/handlers/cli.rb', line 69 def self::start loop do begin input = Readline.readline( @prompt ) rescue Interrupt puts "\nPlease type 'quit' or 'exit' to quit." else parse_command input end puts # blank line to clean things up end end |