bin/commander in visionmedia-commander-2.5.7 vs bin/commander in visionmedia-commander-3.0.0

- old
+ new

@@ -8,46 +8,47 @@ program :description, 'Commander utility program.' command :init do |c| 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.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? + file = args.shift || abort('file argument required.') name = ask 'Machine name of program: ' description = ask 'Describe your program: ' - commands = ask 'List the sub-commands you wish to create: ', Array + commands = ask_for_array 'List the sub-commands you wish to create: ' begin - File.open(args.first, 'w') do |f| - f.write <<-CODE -#!/usr/bin/env ruby - -require 'rubygems' -require 'commander' -require '#{name}' - -program :name, '#{name}' -program :version, #{name.camelcase}::VERSION -program :description, '#{description}' - -CODE + File.open(file, 'w') do |f| + f.write <<-"...".gsub!(/^ {10}/, '') + #!/usr/bin/env ruby + + require 'rubygems' + require 'commander' + require '#{name}' + + program :name, '#{name}' + program :version, #{name.capitalize}::VERSION + program :description, '#{description}' + + ... commands.each do |command| - f.write <<-CODE -command :#{command} do |c| - c.syntax = '' - c.description = '' - 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 + f.write <<-"...".gsub!(/^ {12}/, '') + command :#{command} do |c| + c.syntax = '#{name} #{command} [options]' + c.summary = '' + c.description = '' + 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.capitalize}::Commands::#{command.capitalize} + end + end -CODE + ... end end - say "Initialized template in #{args.first}" + say "Initialized template in #{file}" rescue Exception => e abort e end end end \ No newline at end of file