Class: Bugsink::CLI
- Inherits:
-
Object
- Object
- Bugsink::CLI
- Defined in:
- lib/bugsink/cli.rb
Overview
CLI command parser and router for BugSink API
Instance Attribute Summary collapse
-
#client ⇒ Object
readonly
Returns the value of attribute client.
-
#config ⇒ Object
readonly
Returns the value of attribute config.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
Instance Method Summary collapse
-
#initialize(args = ARGV) ⇒ CLI
constructor
A new instance of CLI.
- #run ⇒ Object
Constructor Details
#initialize(args = ARGV) ⇒ CLI
Returns a new instance of CLI.
13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/bugsink/cli.rb', line 13 def initialize(args = ARGV) @args = args @options = { format: 'table', project_id: nil } @config = Config.new @client = Client.new(@config) rescue Config::ConfigError => e error("Configuration error: #{e.}") exit 1 end |
Instance Attribute Details
#client ⇒ Object (readonly)
Returns the value of attribute client.
11 12 13 |
# File 'lib/bugsink/cli.rb', line 11 def client @client end |
#config ⇒ Object (readonly)
Returns the value of attribute config.
11 12 13 |
# File 'lib/bugsink/cli.rb', line 11 def config @config end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
11 12 13 |
# File 'lib/bugsink/cli.rb', line 11 def @options end |
Instance Method Details
#run ⇒ Object
26 27 28 29 30 31 32 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 |
# File 'lib/bugsink/cli.rb', line 26 def run return show_help if @args.empty? resource = @args[0] action = @args[1] case resource when 'help', '--help', '-h' show_help(action) when '--version', '-v' show_version when 'config' handle_config(action) when 'teams' handle_teams(action, @args[2..]) when 'projects' handle_projects(action, @args[2..]) when 'issues' handle_issues(action, @args[2..]) when 'events' handle_events(action, @args[2..]) when 'releases' handle_releases(action, @args[2..]) else error("Unknown resource: #{resource}") show_help exit 1 end rescue Client::ClientError => e error("API error: #{e.}") exit 1 rescue ArgumentError => e error("Argument error: #{e.}") exit 1 rescue StandardError => e error("Unexpected error: #{e.class} - #{e.}") error(e.backtrace.join("\n")) if ENV['DEBUG'] exit 1 end |