Class: Caphub::Runner
- Inherits:
-
Object
- Object
- Caphub::Runner
- Defined in:
- lib/caphub/runner.rb
Instance Attribute Summary collapse
-
#options ⇒ Object
readonly
Returns the value of attribute options.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(args) ⇒ Runner
constructor
A new instance of Runner.
- #parse_options! ⇒ Object
- #run! ⇒ Object
- #skeleton_dir ⇒ Object
Constructor Details
#initialize(args) ⇒ Runner
Returns a new instance of Runner.
14 15 16 17 |
# File 'lib/caphub/runner.rb', line 14 def initialize(args) @args = args.dup @options = { cap: 3 } end |
Instance Attribute Details
#options ⇒ Object (readonly)
Returns the value of attribute options.
19 20 21 |
# File 'lib/caphub/runner.rb', line 19 def @options end |
Class Method Details
.run ⇒ Object
7 8 9 10 11 |
# File 'lib/caphub/runner.rb', line 7 def run runner = new(ARGV) runner. runner.run! end |
Instance Method Details
#parse_options! ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/caphub/runner.rb', line 21 def OptionParser.new do |opts| opts. = "Usage: #{File.basename($0)} [path]" opts.on("-c", "--cap VERSION", "Capistrano version 2 or 3") { |v| [:cap] = v } opts.on_tail("-h", "--help", "Show this message") { puts opts; exit } opts.on_tail('-v', '--version', "Show version") { puts Caphub::VERSION; exit } begin opts.parse!(@args) rescue OptionParser::ParseError => e warn e. puts opts exit 1 end end abort "Please specify the directory for capistrano hub" if @args.empty? abort "'#{@args.first}' exists." if File.exists?(@args.first) @options[:target] = @args.first end |
#run! ⇒ Object
47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/caphub/runner.rb', line 47 def run! target = [:target] puts "Creating directory #{target}" FileUtils.mkdir(target) puts "Creating capistrano skeleton in #{target}" FileUtils.cp_r("#{skeleton_dir}/.", target) puts "Initializating git repository in #{target}" Dir.chdir(target) { `git init`; `git add .` } end |
#skeleton_dir ⇒ Object
43 44 45 |
# File 'lib/caphub/runner.rb', line 43 def skeleton_dir File.("../../../skeletons/cap#{[:cap]}", __FILE__) end |