Sha256: f27aac56abfbca1b77b296b5b4ba8ca38d81065f350e986adcc7e570ce0c1ac7

Contents?: true

Size: 1.31 KB

Versions: 1

Compression:

Stored size: 1.31 KB

Contents

require 'rebuild'
require 'optparse'

module Rebuild
  class CLI
    class << self
      def start
        options = {}

        opt = OptionParser.new
        opt.on('-d', '--directory=VAL') { |v| options[:directory] = v }

        args = opt.parse!(ARGV)
        return show_usage if args.empty? && CommandLineTools.installed?

        CommandLineTools.install unless CommandLineTools.installed?
        License.agree            unless License.agreed?

        if args.any?
          stdin = STDIN.gets unless STDIN.isatty
          bootstrap(args, stdin, options)
        end
      end

      private

      def bootstrap(args, stdin, options)
        repo_path       = Repository.new(args.first, options[:directory]).fetch
        primary_scripts = stdin

        runner = Runner.new(repo_path, primary_scripts)
        runner.run
      end

      def show_usage
        puts unindent(<<-EOS)
          Commands:
            rebuild USER/PROJECT # execute all scripts in GitHub repo's root directory

          Options:
            -d, [--directory=/path/to/clone] # Default: /tmp/USER/PROJECT

        EOS
      end

      def unindent(text)
        indent = text.split("\n").select {|line| !line.strip.empty? }.map {|line| line.index(/[^\s]/) }.compact.min || 0
        text.gsub(/^[[:blank:]]{#{indent}}/, '')
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
rebuild-0.2.2 lib/rebuild/cli.rb