Sha256: 75a05cc12286efbd12cec27e04f9bf866f627745e9d919ad73877b3d8e2c506b

Contents?: true

Size: 1.29 KB

Versions: 1

Compression:

Stored size: 1.29 KB

Contents

#!/usr/bin/env ruby

require 'commander'

init_commander(
    :name => 'Commander', 
    :version => Commander::VERSION, 
    :description => 'Commander utility program.'
  )

command :init do |c|
	c.syntax = 'commander init <filepath>'
	c.description = 'Initialize an empty file with a commander skeleton.'
	c.example 'Create a new file with a commander skeleton.', 'commander init ./bin/my_executable'
	c.when_called do |args|
	  abort "Provide a filepath." if args.empty?
	  puts
		name = ask 'What is your programs machine name?'
		description = ask 'Describe your program:'
		commands = ask 'List the sub-commands you wish to create:', Array
		begin
		  filepath = args.shift
      File.open(filepath, 'w') do |f|
        f.write <<-CODE
#!/usr/bin/env ruby

require 'rubygems'
require 'commander'

init_commander(
    :name => '#{name.capitalize}', 
    :version => #{name.capitalize}::VERSION, 
    :description => '#{description}'
  )
  
CODE
        commands.each do |command|
          f.write <<-CODE
command :#{command} do |c|
  c.syntax = ''
  c.description = ''
  c.example 'description', 'code'
  c.when_called do |args|
    # Do something
  end
end

CODE
        end
       end
       say "Created commander skeleton at '#{filepath}'."
       puts
		 rescue Exception => e
       abort e
		 end
	end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
visionmedia-commander-1.2.2 bin/commander