Class: Gitlab::CLI
- Inherits:
-
Object
- Object
- Gitlab::CLI
- Extended by:
- Helpers
- Defined in:
- lib/gitlab/cli.rb,
lib/gitlab/cli_helpers.rb
Defined Under Namespace
Modules: Helpers
Class Method Summary collapse
-
.render_output(cmd, args, data) ⇒ nil
Helper method that checks whether we want to get the output as json.
-
.run(cmd, args = []) ⇒ nil
Processes a CLI command and outputs a result to the stream (stdout).
-
.start(args) ⇒ Object
Starts a new CLI session.
Methods included from Helpers
actions, client, confirm_command, excluded_fields, get_keys, gitlab_helper, help, method_owners, output_json, output_table, record_hash, record_table, required_fields, symbolize_keys, valid_command?, yaml_load
Class Method Details
.render_output(cmd, args, data) ⇒ nil
Helper method that checks whether we want to get the output as json
82 83 84 85 86 87 88 |
# File 'lib/gitlab/cli.rb', line 82 def self.render_output(cmd, args, data) if @json_output output_json(cmd, args, data) else output_table(cmd, args, data) end end |
.run(cmd, args = []) ⇒ nil
Processes a CLI command and outputs a result to the stream (stdout).
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 67 68 69 70 71 72 73 74 75 76 77 78 |
# File 'lib/gitlab/cli.rb', line 33 def self.run(cmd, args=[]) case cmd when 'help' 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}" puts "Ruby Version is #{RUBY_VERSION}" puts "Gitlab Ruby Gem #{Gitlab::VERSION}" 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 if args.any? && (args.last.start_with?('--only=') || args.last.start_with?('--except=')) command_args = args[0..-2] else command_args = args end begin command_args.map! { |arg| symbolize_keys(yaml_load(arg)) } rescue => e puts e. exit 1 end confirm_command(cmd) data = gitlab_helper(cmd, command_args) { exit(1) } render_output(cmd, args, data) end end |
.start(args) ⇒ Object
Starts a new CLI session.
19 20 21 22 |
# File 'lib/gitlab/cli.rb', line 19 def self.start(args) command = args.shift.strip rescue 'help' run(command, args) end |