Module: GHI
- Defined in:
- lib/ghi.rb,
lib/ghi/web.rb,
lib/ghi/editor.rb,
lib/ghi/commands.rb,
lib/ghi/formatting.rb,
lib/ghi/authorization.rb,
lib/ghi/commands/edit.rb,
lib/ghi/commands/help.rb,
lib/ghi/commands/list.rb,
lib/ghi/commands/open.rb,
lib/ghi/commands/show.rb,
lib/ghi/commands/close.rb,
lib/ghi/commands/label.rb,
lib/ghi/commands/assign.rb,
lib/ghi/commands/config.rb,
lib/ghi/commands/enable.rb,
lib/ghi/commands/status.rb,
lib/ghi/commands/command.rb,
lib/ghi/commands/comment.rb,
lib/ghi/commands/disable.rb,
lib/ghi/commands/version.rb,
lib/ghi/formatting/colors.rb,
lib/ghi/commands/milestone.rb,
lib/ghi/client.rb
Defined Under Namespace
Modules: Authorization, Commands, Formatting Classes: Client, Editor, Web
Class Attribute Summary collapse
-
.v ⇒ Object
(also: v?)
Returns the value of attribute v.
Class Method Summary collapse
Class Attribute Details
.v ⇒ Object Also known as: v?
Returns the value of attribute v.
123 124 125 |
# File 'lib/ghi.rb', line 123 def v @v end |
Class Method Details
.config(key, options = {}) ⇒ Object
112 113 114 115 116 117 118 119 120 121 |
# File 'lib/ghi.rb', line 112 def config key, = {} upcase = .fetch :upcase, true flags = [:flags] var = key.gsub('core', 'git').gsub '.', '_' var.upcase! if upcase value = ENV[var] || `git config #{flags} #{key}` value = `#{value[1..-1]}` if value.start_with? '!' value = value.chomp value unless value.empty? end |
.execute(args) ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 23 24 25 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 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 |
# File 'lib/ghi.rb', line 12 def execute args STDOUT.sync = true double_dash = args.index { |arg| arg == '--' } if index = args.index { |arg| arg !~ /^-/ } if double_dash.nil? || index < double_dash command_name = args.delete_at index command_args = args.slice! index, args.length end end command_args ||= [] option_parser = OptionParser.new do |opts| opts. = <<EOF usage: ghi [--version] [-p|--paginate|--no-pager] [--help] <command> [<args>] [ -- [<user>/]<repo>] EOF opts.on('--version') { command_name = 'version' } opts.on '-p', '--paginate', '--[no-]pager' do |paginate| GHI::Formatting.paginate = paginate end opts.on '--help' do command_args.unshift(*args) command_args.unshift command_name if command_name args.clear command_name = 'help' end opts.on '--[no-]color' do |colorize| Formatting::Colors.colorize = colorize end opts.on '-l' do if command_name raise OptionParser::InvalidOption else command_name = 'list' end end opts.on '-v' do command_name ? self.v = true : command_name = 'version' end opts.on('-V') { command_name = 'version' } end begin option_parser.parse! args rescue OptionParser::InvalidOption => e warn e..capitalize abort option_parser. end if command_name.nil? command_name = 'list' end if command_name == 'help' Commands::Help.execute command_args, option_parser. else command_name = fetch_alias command_name, command_args begin command = Commands.const_get command_name.capitalize rescue NameError abort "ghi: '#{command_name}' is not a ghi command. See 'ghi --help'." end # Post-command help option parsing. Commands::Help.execute [command_name] if command_args.first == '--help' begin command.execute command_args rescue OptionParser::ParseError, Commands::MissingArgument => e warn "#{e..capitalize}\n" abort command.new([])..to_s rescue Client::Error => e if e.response.is_a?(Net::HTTPNotFound) && Authorization.token.nil? raise Authorization::Required else abort e. end rescue SocketError => e abort "Couldn't find internet." rescue Errno::ECONNREFUSED, Errno::ETIMEDOUT => e abort "Couldn't find GitHub." end end rescue Authorization::Required => e retry if Authorization. warn e. if Authorization.token warn <<EOF.chomp Not authorized for this action with your token. To regenerate a new token: EOF end warn <<EOF Please run 'ghi config --auth <username>' EOF exit 1 end |