Class: GHI::CLI::Executable
- Inherits:
-
Object
- Object
- GHI::CLI::Executable
- Includes:
- FileHelper, FormattingHelper
- Defined in:
- lib/ghi/cli.rb
Instance Attribute Summary collapse
-
#action ⇒ Object
readonly
Returns the value of attribute action.
-
#api ⇒ Object
readonly
Returns the value of attribute api.
-
#args ⇒ Object
readonly
Returns the value of attribute args.
-
#body ⇒ Object
readonly
Returns the value of attribute body.
-
#local_repo ⇒ Object
readonly
Returns the value of attribute local_repo.
-
#local_user ⇒ Object
readonly
Returns the value of attribute local_user.
-
#message ⇒ Object
readonly
Returns the value of attribute message.
-
#number ⇒ Object
readonly
Returns the value of attribute number.
-
#repo ⇒ Object
readonly
Returns the value of attribute repo.
-
#search_term ⇒ Object
readonly
Returns the value of attribute search_term.
-
#tag ⇒ Object
readonly
Returns the value of attribute tag.
-
#title ⇒ Object
readonly
Returns the value of attribute title.
-
#use_ssl ⇒ Object
readonly
Returns the value of attribute use_ssl.
-
#user ⇒ Object
readonly
Returns the value of attribute user.
-
#verbosity ⇒ Object
readonly
Returns the value of attribute verbosity.
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
#action ⇒ Object (readonly)
Returns the value of attribute action.
209 210 211 |
# File 'lib/ghi/cli.rb', line 209 def action @action end |
#api ⇒ Object (readonly)
Returns the value of attribute api.
209 210 211 |
# File 'lib/ghi/cli.rb', line 209 def api @api end |
#args ⇒ Object (readonly)
Returns the value of attribute args.
209 210 211 |
# File 'lib/ghi/cli.rb', line 209 def args @args end |
#body ⇒ Object (readonly)
Returns the value of attribute body.
209 210 211 |
# File 'lib/ghi/cli.rb', line 209 def body @body end |
#local_repo ⇒ Object (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_user ⇒ Object (readonly)
Returns the value of attribute local_user.
209 210 211 |
# File 'lib/ghi/cli.rb', line 209 def local_user @local_user end |
#message ⇒ Object (readonly)
Returns the value of attribute message.
209 210 211 |
# File 'lib/ghi/cli.rb', line 209 def @message end |
#number ⇒ Object (readonly)
Returns the value of attribute number.
209 210 211 |
# File 'lib/ghi/cli.rb', line 209 def number @number end |
#repo ⇒ Object (readonly)
Returns the value of attribute repo.
209 210 211 |
# File 'lib/ghi/cli.rb', line 209 def repo @repo end |
#search_term ⇒ Object (readonly)
Returns the value of attribute search_term.
209 210 211 |
# File 'lib/ghi/cli.rb', line 209 def search_term @search_term end |
#tag ⇒ Object (readonly)
Returns the value of attribute tag.
209 210 211 |
# File 'lib/ghi/cli.rb', line 209 def tag @tag end |
#title ⇒ Object (readonly)
Returns the value of attribute title.
209 210 211 |
# File 'lib/ghi/cli.rb', line 209 def title @title end |
#use_ssl ⇒ Object (readonly)
Returns the value of attribute use_ssl.
209 210 211 |
# File 'lib/ghi/cli.rb', line 209 def use_ssl @use_ssl end |
#user ⇒ Object (readonly)
Returns the value of attribute user.
209 210 211 |
# File 'lib/ghi/cli.rb', line 209 def user @user end |
#verbosity ⇒ Object (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
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.}" puts option_parser exit 1 end rescue OptionParser::MissingArgument, OptionParser::AmbiguousOption => e warn "#{File.basename $0}: #{e.}" 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.} (#{user}/#{repo})" exit 1 rescue GHI::API::ResponseError => e warn "#{File.basename $0}: #{e.} (#{user}/#{repo})" exit 1 end |
#state ⇒ Object
280 281 282 |
# File 'lib/ghi/cli.rb', line 280 def state @state || :open end |