Sha256: 21447cb12311dca2088f3cad01ef7ac39f152b7fda39d018bff4ea1a9624584e
Contents?: true
Size: 1.78 KB
Versions: 3
Compression:
Stored size: 1.78 KB
Contents
require 'rebuild' require 'optparse' module Rebuild class CLI DEFAULT_OPTIONS = { update: false, } class << self def start options = DEFAULT_OPTIONS opt = OptionParser.new opt.on('-f', '--force-update') { |v| options[:update] = true } opt.on('-d', '--directory=VAL') { |v| options[:directory] = v } opt.on('-s', '--scriptdir=VAL') { |v| options[:scriptdir] = 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).fetch primary_scripts = stdin runner = Runner.new(repo_path, primary_scripts, options[:scriptdir]) runner.run end def show_usage puts unindent(<<-EOS) Commands: rebuild # install command line tools, done rebuild USER/PROJECT # execute all scripts in GitHub repo's root directory Options: -f, [--force-update] # By default, git pull is not executed -d, [--directory=/path/to/clone] # Default: /tmp/USER/PROJECT -s, [--scriptdir=/script/placed/dir] # Default: '' (root) 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
3 entries across 3 versions & 1 rubygems
Version | Path |
---|---|
rebuild-0.2.6 | lib/rebuild/cli.rb |
rebuild-0.2.5 | lib/rebuild/cli.rb |
rebuild-0.2.4 | lib/rebuild/cli.rb |