Sha256: 2dabe09407256765f45f4b5626f4481110444308849b9c50edc4082cac4382be

Contents?: true

Size: 1.72 KB

Versions: 1

Compression:

Stored size: 1.72 KB

Contents

require 'colorize'
require 'tmpdir'
require 'fileutils'
require 'gito/version'
require 'gito/project'
require 'openssl'
require 'open3'
require 'optparse'

class MainApp
  def initialize(arguments)

    @url = %w(-h --help -v --version).include?(arguments.first) ? nil : arguments.shift

    # defaults
    @app_path = nil
    @should_edit = false
    @should_open = false
    @dryrun = false

    # Parse Options
    create_options_parser(arguments)
  end

  def create_options_parser(args)
    args.options do |opts|
      opts.banner = 'Usage: gito GIT_URL [OPTIONS]'
      opts.separator ''
      opts.separator 'Options'

      opts.on('-e', '--edit', 'Open the project on an editor') do |edit|
        @should_edit = true
      end

      opts.on('-o', '--open', 'Open the project on Finder') do |edit|
        @should_open = true
      end

      opts.on('-d', '--dryrun', 'Doesn\'t install the dependencies') do |dryrun|
        @dryrun = true
      end

      opts.on('-h', '--help', 'Displays help') do
        puts opts.help
        exit
      end

      opts.on('-v', '--version', 'Displays the version') do
        puts Gito::VERSION
        exit
      end

      opts.parse!
    end
  end

  def call

    if @url.nil?
      puts 'You need to insert a valid GIT URL/folder'
      exit 1
    end

    project = Project.new(@url)

    # Clone the repository
    project.clone

    # Detect project type
    project.detect_project_type

    # Open in editor
    if @should_edit
      project.open_editor
    end

    # Open in Finder
    if @should_open
      project.open_folder
    end

    unless @dryrun
      # Install dependencies
      project.install_dependencies
    end

    # Change to directory
    project.change_directory

  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
gito-0.2.4 lib/gito.rb