Class: GHI::CLI::Executable

Inherits:
Object
  • Object
show all
Includes:
FileHelper, FormattingHelper
Defined in:
lib/ghi/cli.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from FileHelper

#delete_message, #gets_from_editor, #launch_editor, #message_path

Methods included from FormattingHelper

#action_format, #edit_format, #indent, #list_format, #list_header, #show_format, #truncate

Instance Attribute Details

#actionObject (readonly)

Returns the value of attribute action.



209
210
211
# File 'lib/ghi/cli.rb', line 209

def action
  @action
end

#apiObject (readonly)

Returns the value of attribute api.



209
210
211
# File 'lib/ghi/cli.rb', line 209

def api
  @api
end

#argsObject (readonly)

Returns the value of attribute args.



209
210
211
# File 'lib/ghi/cli.rb', line 209

def args
  @args
end

#bodyObject (readonly)

Returns the value of attribute body.



209
210
211
# File 'lib/ghi/cli.rb', line 209

def body
  @body
end

#local_repoObject (readonly)

Returns the value of attribute local_repo.



209
210
211
# File 'lib/ghi/cli.rb', line 209

def local_repo
  @local_repo
end

#local_userObject (readonly)

Returns the value of attribute local_user.



209
210
211
# File 'lib/ghi/cli.rb', line 209

def local_user
  @local_user
end

#messageObject (readonly)

Returns the value of attribute message.



209
210
211
# File 'lib/ghi/cli.rb', line 209

def message
  @message
end

#numberObject (readonly)

Returns the value of attribute number.



209
210
211
# File 'lib/ghi/cli.rb', line 209

def number
  @number
end

#repoObject (readonly)

Returns the value of attribute repo.



209
210
211
# File 'lib/ghi/cli.rb', line 209

def repo
  @repo
end

#search_termObject (readonly)

Returns the value of attribute search_term.



209
210
211
# File 'lib/ghi/cli.rb', line 209

def search_term
  @search_term
end

#tagObject (readonly)

Returns the value of attribute tag.



209
210
211
# File 'lib/ghi/cli.rb', line 209

def tag
  @tag
end

#titleObject (readonly)

Returns the value of attribute title.



209
210
211
# File 'lib/ghi/cli.rb', line 209

def title
  @title
end

#use_sslObject (readonly)

Returns the value of attribute use_ssl.



209
210
211
# File 'lib/ghi/cli.rb', line 209

def use_ssl
  @use_ssl
end

#userObject (readonly)

Returns the value of attribute user.



209
210
211
# File 'lib/ghi/cli.rb', line 209

def user
  @user
end

#verbosityObject (readonly)

Returns the value of attribute verbosity.



209
210
211
# File 'lib/ghi/cli.rb', line 209

def verbosity
  @verbosity
end

Instance Method Details

#commenting?Boolean

Returns:

  • (Boolean)


276
277
278
# File 'lib/ghi/cli.rb', line 276

def commenting?
  @commenting
end

#parse!(*argv) ⇒ Object



213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
# File 'lib/ghi/cli.rb', line 213

def parse!(*argv)
  @args, @argv = argv, argv.dup

  remotes = `git config --get-regexp remote\..+\.url`.split /\n/
  repo_expression = %r{([^:/]+)/([^/\s]+)(?:\.git)$}
  if remote = remotes.find { |r| r.include? "github.com" }
    remote.match repo_expression
    @user, @repo = $1, $2
  end

  option_parser.parse!(*args)

  if action.nil? && fallback_parsing(*args).nil?
    puts option_parser
    exit
  end
rescue OptionParser::InvalidOption, OptionParser::InvalidArgument => e
  if fallback_parsing(*e.args).nil?
    warn "#{File.basename $0}: #{e.message}"
    puts option_parser
    exit 1
  end
rescue OptionParser::MissingArgument, OptionParser::AmbiguousOption => e
  warn "#{File.basename $0}: #{e.message}"
  puts option_parser
  exit 1
ensure
  run!
  $stdout.close_write
end

#run!Object



244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
# File 'lib/ghi/cli.rb', line 244

def run!
  @api = GHI::API.new user, repo, use_ssl

  case action
    when :search        then search
    when :list          then list
    when :show          then show
    when :open          then open
    when :edit          then edit
    when :close         then close
    when :reopen        then reopen
    when :comment       then prepare_comment && comment
    when :label, :claim then prepare_label   && label
    when :unlabel       then prepare_label   && unlabel
    when :url           then url
  end
rescue GHI::API::InvalidConnection
  if action
    code = 1
    warn "#{File.basename $0}: not a GitHub repo"
    puts option_parser if args.flatten.empty?
    exit 1
  end
rescue GHI::API::InvalidRequest => e
  warn "#{File.basename $0}: #{e.message} (#{user}/#{repo})"
  delete_message
  exit 1
rescue GHI::API::ResponseError => e
  warn "#{File.basename $0}: #{e.message} (#{user}/#{repo})"
  exit 1
end

#stateObject



280
281
282
# File 'lib/ghi/cli.rb', line 280

def state
  @state || :open
end