Sha256: 13c44d9b4025d8092554b5ed421e28c2c9e2209a83013408d193b3badfa4ef2d

Contents?: true

Size: 1.12 KB

Versions: 5

Compression:

Stored size: 1.12 KB

Contents

require 'optparse'

module <%= module_name %>
  class CLI
    def self.execute

      # NOTE: the option -p/--path= is given as an example, and should be replaced in your application.

      options = {
        :path     => '~'
      }
      mandatory_options = %w(  )

      parser = OptionParser.new do |opts|
        opts.banner = <<-BANNER.gsub(/^          /,'')
          This application is wonderful because...

          Usage: #{File.basename($0)} [options]

          Options are:
        BANNER
        opts.separator ""
        opts.on("-p", "--path=PATH", String,
                "This is a sample message.",
                "For multiple lines, add more strings.",
                "Default: ~") { |arg| OPTIONS[:path] = arg }
        opts.on("-h", "--help",
                "Show this help message.") { puts opts; exit }
        opts.parse!(ARGV)

        if mandatory_options && mandatory_options.find { |option| options[option.to_sym].nil? }
          puts opts; exit
        end
      end

      path = options[:path]

      # do stuff
      puts "To update this executable, look in lib/<%= bin_name %>/cli.rb"      
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
newgem-0.29.0 rubygems_generators/executable/templates/lib/app/cli.rb.erb
newgem-1.0.0 rubygems_generators/executable/templates/lib/app/cli.rb.erb
newgem-1.0.1 rubygems_generators/executable/templates/lib/app/cli.rb.erb
newgem-1.0.2 rubygems_generators/executable/templates/lib/app/cli.rb.erb
newgem-1.0.3 rubygems_generators/executable/templates/lib/app/cli.rb.erb