Sha256: ffcee22c4c825a30d32f41531810d181d6f00270cc5f1eb6947ef88b3aa13561

Contents?: true

Size: 1.71 KB

Versions: 8

Compression:

Stored size: 1.71 KB

Contents

#!/usr/bin/env ruby

require 'rubygems'
require 'commander/import'

program :name, 'commander'
program :version, Commander::VERSION
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 very quick creation of commander executables.'
  c.example 'Create a new file with a commander template.', 'commander init bin/my_executable'
  c.action do |args, _options|
    file = args.shift || abort('file argument required.')
    name = ask 'Machine name of program: '
    description = ask 'Describe your program: '
    commands = ask_for_array 'List the commands you wish to create: '
    begin
      File.open(file, 'w') do |f|
        f.write <<-"...".gsub!(/^ {10}/, '')
          #!/usr/bin/env ruby

          require 'rubygems'
          require 'commander/import'

          program :version, '0.0.1'
          program :description, '#{description}'

        ...
        commands.each do |command|
          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.action do |args, options|
                # Do something or c.when_called #{name.capitalize}::Commands::#{command.capitalize}
              end
            end

          ...
        end
      end
      File.chmod 0755, file
      say "Initialized template in #{file}"
    rescue => e
      abort e
    end
  end
end

Version data entries

8 entries across 8 versions & 2 rubygems

Version Path
commander-4.3.8 bin/commander
commander-4.3.7 bin/commander
commander-4.3.5 bin/commander
scoot-0.0.4 .bundle/gems/ruby/2.2.0/gems/commander-4.3.4/bin/commander
commander-4.3.4 bin/commander
commander-4.3.3 bin/commander
commander-4.3.2 bin/commander
commander-4.3.1 bin/commander