Class: Gitlab::Shell

Inherits:
Object
  • Object
show all
Extended by:
CLI::Helpers
Defined in:
lib/gitlab/shell.rb

Class Method Summary collapse

Methods included from CLI::Helpers

actions_table, confirm_command, excluded_fields, gitlab_helper, multiple_record_table, output_table, required_fields, single_record_table, valid_command?

Class Method Details

.startObject



9
10
11
12
13
14
15
16
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
# File 'lib/gitlab/shell.rb', line 9

def self.start
  actions = Gitlab.actions

  comp = proc { |s| actions.map(&:to_s).grep(/^#{Regexp.escape(s)}/) }

  Readline.completion_proc = comp
  Readline.completion_append_character = ' '

  client = Gitlab::Client.new(endpoint: '')

  while buf = Readline.readline("gitlab> ", true)
    next if buf.nil? || buf.empty?
    buf = buf.split.map(&:chomp)
    cmd = buf.shift
    args = buf.count > 0 ? buf : []

    if cmd == 'help'
      methods = []

      actions.each do |action|
        methods << {
          name: action.to_s,
          owner: client.method(action).owner.to_s
        }
      end

      args[0].nil? ? Gitlab::Help.get_help(methods) : Gitlab::Help.get_help(methods, args[0])
      next
    end

    data = if actions.include?(cmd.to_sym)
      confirm_command(cmd)
      gitlab_helper(cmd, args)
    else
      "'#{cmd}' is not a valid command.  See the 'help' for a list of valid commands."
    end

    output_table(cmd, args, data)
  end
end