bin/commander in visionmedia-commander-1.2.2 vs bin/commander in visionmedia-commander-2.4.2

- old
+ new

@@ -1,56 +1,53 @@ #!/usr/bin/env ruby +require 'rubygems' require 'commander' -init_commander( - :name => 'Commander', - :version => Commander::VERSION, - :description => 'Commander utility program.' - ) +program :name, 'commander' +program :version, Commander::VERSION::STRING +program :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| + c.syntax = 'commander init <file>' + c.summary = 'Initialize a commander template' + c.description = 'Initialize an empty file with a commander template, allowing extremely quick creation of commader executables.' + c.example 'Create a new file with a commander template.', 'commander init ./bin/my_executable' + c.when_called do |args, options| 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 + name = ask 'Machine name of program: ' + 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| + File.open(args.first, 'w') do |f| f.write <<-CODE #!/usr/bin/env ruby require 'rubygems' require 'commander' +require '#{name}' -init_commander( - :name => '#{name.capitalize}', - :version => #{name.capitalize}::VERSION, - :description => '#{description}' - ) - +program :name, '#{name}' +program :version, #{name.camelcase}::VERSION::STRING +program :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 + c.example 'description', 'command example' + c.option '--some-switch', 'Some switch that does something' + c.when_called do |args, options| + # Do something or c.when_called #{name.camelcase}::Commands::#{command.camelcase} end end CODE end end - say "Created commander skeleton at '#{filepath}'." - puts + say "Initialized template in #{args.first}" rescue Exception => e abort e end end end \ No newline at end of file