Sha256: d3437e855ef8b655501d6504b5843483ec68ce29ffabffb4ff4e73032025aae2

Contents?: true

Size: 1.59 KB

Versions: 1

Compression:

Stored size: 1.59 KB

Contents

#! /usr/bin/ruby

require 'optparse'
require 'ostruct'
require 'rbconfig'
require 'git-bro'
require 'git-bro/commands'

module GitBro
  TARGET_OS = Config::CONFIG['target_os']
end

class GitBroApp
  attr_reader :options

  def initialize(arguments)
    @valid_commands = ['serve']
    @arguments = arguments
    @options = OpenStruct.new

    @options.gem_path = File.expand_path(File.dirname(__FILE__)) + "/.."
  end

  # parse options, check arguments, then process the command
  def run
    if parsed_options? and arguments_valid?
      process_arguments
      process_command
    else
      output_usage
    end
  end

protected
  include GitBro::ServeCommand

  def parsed_options?
    opts = OptionParser.new
    opts.on('-v', '--version'){ output_version; exit 0 }
    opts.on('-h', '--help'){ output_help; exit 0 }

    opts.parse!(@arguments) rescue return false

    true
  end

  def arguments_valid?
    @command = @arguments.delete_at(0)

    return false unless @valid_commands.include?(@command)
    self.send("#{@command}_arguments_valid?")
  end

  def process_arguments
    self.send("#{@command}_process_arguments")
  end

  def output_version
    puts "#{GitBro::VERSION}"
  end

  def output_help
    output_usage
    puts ""
    puts "Available commands:"
    puts "\s\s#{"serve".ljust(12)}Serve current or given folder"
  end

  def output_usage
    puts "Usage: git-bro [--version] [--help] COMMAND [ARGS]"
  end

  def process_command
    self.send("do_#{@command}")
  end
end

begin
  gb_app = GitBroApp.new(ARGV)
  gb_app.run
rescue SystemExit
  # do nothing
rescue Exception => e
  puts e.message
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
git-bro-0.2.0 bin/git-bro