lib/exctl/cli.rb in exctl-0.0.2 vs lib/exctl/cli.rb in exctl-0.0.3
- old
+ new
@@ -1,10 +1,6 @@
-# TODO: Yes, at some point this will be bootstrapped by exctl itself.
-
module Exctl
- def self.cli(argv) Exctl::CLI.new(argv).run! end
-
class CLI
def initialize(argv)
@args = argv.clone
@cmd = (@args.shift || 'help').strip.downcase
@cmd = 'help' if [nil,'-h','--help','h'].include?(@cmd)
@@ -20,29 +16,55 @@
$stderr.puts "USAGE: exctl (#{avail_cmds.join('|')}) [OPTIONS]"
exit 1
end
end
- def avail_cmds()
- @avail_cmds ||= (self.methods-Object.methods).map(&:to_s).select{|m|m[0..3]=='cmd_'}.map{|m|m[4..-1]}
- end
+ def avail_cmds; @avail_cmds ||= (self.methods-Object.methods).map(&:to_s).select{|m|m[0..3]=='cmd_'}.map{|m|m[4..-1]} end
+ def cmd_version; puts Exctl.version end
def doc_help; 'Output this help.' end
def cmd_help
puts "exctl - Execution control; project command-line generator."
puts " v#{Exctl.version}\n\n"
puts "USAGE: exctl (#{avail_cmds.join('|')}) [OPTIONS]\n\n"
puts avail_cmds.map{|c| hc='doc_'+c; respond_to?(hc) ? ' ' + c.ljust(10) + ': ' + send(hc) : nil}.compact.join("\n") + "\n\n"
end
- def cmd_version
- puts Exctl.version
- end
-
def doc_init; 'BIN-NAME [DIR=.] - Creates/updates main ctl script and support files in the given DIR.' end
def cmd_init
+ require 'erb'
+ binname = @args.shift
+ dir = @args.shift || '.'
+ if binname.nil?
+ $stderr.puts "ERROR: project/binary name not specified."
+ $stderr.puts "USAGE: exctl init BIN-NAME [DIR=.]"
+ exit 3
+ end
- $stderr.puts "just kidding, not implemented yet."
- exit 1
+ b = binding
+
+ libdest = Path["./.exctl"]
+ $stderr.puts " create dir: #{libdest}/"
+ libdest.dir!
+
+ LIB_DIR['**/**',false].each do |f|
+ relative = f.short(LIB_DIR)
+ unless relative.to_s[0..0]=='.' || relative.to_s == 'exctl/cli.rb'
+ dest = libdest ** relative
+ if f.dir?
+ $stderr.puts " create dir: #{dest}/"
+ dest.dir!
+ else
+ $stderr.puts " create file: #{dest}"
+ system "cp", f, dest
+ end
+ end
+ end
+
+ $stderr.puts " create file: #{binname}"
+ dispatch_wrapper = ERB.new(File.read(TEMPLATE_DIR ** 'dispatch-wrapper.erb')).result(b)
+ File.write(binname, dispatch_wrapper)
+ $stderr.puts " chmod file: #{binname}"
+ File.chmod(0774, binname)
end
end
end