lib/gitlab/cli.rb in gitlab-3.3.0 vs lib/gitlab/cli.rb in gitlab-3.4.0
- old
+ new
@@ -4,19 +4,35 @@
require_relative 'shell'
class Gitlab::CLI
extend Helpers
+ # Starts a new CLI session.
+ #
+ # @example
+ # Gitlab::CLI.start(['help'])
+ # Gitlab::CLI.start(['help', 'issues'])
+ #
+ # @param [Array] args The command and it's optional arguments.
def self.start(args)
command = args.shift.strip rescue 'help'
run(command, args)
end
+ # Processes a CLI command and outputs a result to the stream (stdout).
+ #
+ # @example
+ # Gitlab::CLI.run('help')
+ # Gitlab::CLI.run('help', ['issues'])
+ #
+ # @param [String] cmd The name of a command.
+ # @param [Array] args The optional arguments for a command.
+ # @return [nil]
def self.run(cmd, args=[])
case cmd
when 'help'
- puts actions_table
+ puts help(args.shift) { |out| out.gsub!(/Gitlab\./, 'gitlab ') }
when 'info'
endpoint = Gitlab.endpoint ? Gitlab.endpoint : 'not set'
private_token = Gitlab.private_token ? Gitlab.private_token : 'not set'
puts "Gitlab endpoint is #{endpoint}"
puts "Gitlab private token is #{private_token}"
@@ -37,11 +53,13 @@
else
command_args = args
end
begin
- yaml_load_and_symbolize_hash!(command_args)
- rescue
+ yaml_load_arguments! command_args
+ command_args.map! {|arg| symbolize_keys arg }
+ rescue => e
+ puts e.message
exit 1
end
confirm_command(cmd)