lib/gitlab/cli.rb in gitlab-3.4.0 vs lib/gitlab/cli.rb in gitlab-3.5.0

- old
+ new

@@ -4,10 +4,13 @@ require_relative 'shell' class Gitlab::CLI extend Helpers + # If set to true, JSON will be rendered as output + @render_json = false + # Starts a new CLI session. # # @example # Gitlab::CLI.start(['help']) # Gitlab::CLI.start(['help', 'issues']) @@ -41,10 +44,15 @@ when '-v', '--version' puts "Gitlab Ruby Gem #{Gitlab::VERSION}" when 'shell' Gitlab::Shell.start else + if args.include? '--json' + @json_output = true + args.delete '--json' + end + unless valid_command?(cmd) puts "Unknown command. Run `gitlab help` for a list of available commands." exit(1) end @@ -53,19 +61,29 @@ else command_args = args end begin - yaml_load_arguments! command_args - command_args.map! {|arg| symbolize_keys arg } + command_args.map! { |arg| symbolize_keys(yaml_load(arg)) } rescue => e puts e.message exit 1 end confirm_command(cmd) data = gitlab_helper(cmd, command_args) { exit(1) } + + render_output(cmd, args, data) + end + end + + # Helper method that checks whether we want to get the output as json + # @return [nil] + def self.render_output(cmd,args,data) + if @json_output + output_json(cmd, args, data) + else output_table(cmd, args, data) end end end