class Gitlab::Shell
Attributes
arguments[R]
command[R]
Public Class Methods
completion()
click to toggle source
Gets called when user hits TAB key to do completion
# File lib/gitlab/shell.rb, line 60 def completion proc { |str| actions.map(&:to_s).grep(/^#{Regexp.escape(str)}/) } end
execute(cmd=command, args=arguments)
click to toggle source
Execute a given command with arguements
# File lib/gitlab/shell.rb, line 65 def execute(cmd=command, args=arguments) if actions.include?(cmd.to_sym) confirm_command(cmd) gitlab_helper(cmd, args) else fail "Unknown command: #{cmd}. " \ "See the 'help' for a list of valid commands." end end
history()
click to toggle source
# File lib/gitlab/shell.rb, line 80 def history @history ||= History.new end
parse_input(buffer)
click to toggle source
# File lib/gitlab/shell.rb, line 45 def parse_input(buffer) buf = Shellwords.shellwords(buffer) @command = buf.shift @arguments = buf.count > 0 ? buf : [] end
quit_shell()
click to toggle source
# File lib/gitlab/shell.rb, line 75 def quit_shell history.save exit end
setup()
click to toggle source
# File lib/gitlab/shell.rb, line 52 def setup history.load Readline.completion_proc = completion Readline.completion_append_character = ' ' end
start()
click to toggle source
# File lib/gitlab/shell.rb, line 14 def start trap('INT') { quit_shell } # capture ctrl-c setup while buffer = Readline.readline('gitlab> ') begin parse_input buffer @arguments.map! { |arg| symbolize_keys(yaml_load(arg)) } case buffer when nil, '' next when 'exit' quit_shell when /^\bhelp\b+/ puts help(arguments[0]) { |out| out.gsub!(/Gitlab\./, 'gitlab> ') } else history << buffer data = execute command, arguments output_table command, arguments, data end rescue => e puts e.message end end quit_shell # save history if user presses ctrl-d end