Sha256: a3d7e199ef101ca8079e4e52b51370104976340e3ffab3b20046a96a7131d07a

Contents?: true

Size: 1.61 KB

Versions: 1

Compression:

Stored size: 1.61 KB

Contents

require 'git/browse/remote/core'
require 'git/browse/remote/version'
require 'optparse'

module Git::Browse::Remote
  class Runner
    def initialize(args)
      @args = args
      @core = Core.new
    end

    def parse_args!
      OptionParser.new do |opt|
        opt.banner  = 'git browse-remote [options] [<commit> | <remote>] [--] [<file>]'
        opt.version = VERSION
        opt.on('-r', '--remote=<remote>', 'specify remote') { |r| @core.remote = r }

        opt.on('--stdout', 'prints URL instead of opening browser') { @stdout = true }

        opt.on('--top', 'open `top` page') { @core.mode = :top }
        opt.on('--rev', 'open `rev` page') { @core.mode = :rev }
        opt.on('--ref', 'open `ref` page') { @core.mode = :ref }
        opt.on('--pr',  'open `pr` page')  { @core.mode = :pr  }
        opt.on('--init [<host>=<recipe>]', 'initialize default url mappings') do |config|
          if config
            host, name = *config.split(/=/, 2)
          else
            host, name = 'github.com', 'github'
          end

          STDERR.puts "Writing config for #{host}..."

          @core.init!(host, name.to_sym)

          STDERR.puts 'Mappings generated:'
          exec "git config --get-regexp ^browse-remote\\.#{host}\\."
        end
        opt.on('-L <n>[,<m>]', 'specify line number (only meaningful on file mode)') { |lines| @core.lines = lines.split(/[,\-]/).map(&:to_i).uniq  }
      end.parse!(@args)

      @core.target, @core.file = *@args[0..1]
    end

    def run
      parse_args!

      if @stdout
        puts @core.url
      else
        exec 'git', 'web--browse', @core.url
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
git-browse-remote-0.2.0 lib/git/browse/remote/runner.rb