Sha256: a522f1468f6cb28f2696c16be48bbcd92e50ee9dcf77d4f912f6dae57e20675a

Contents?: true

Size: 1.78 KB

Versions: 23

Compression:

Stored size: 1.78 KB

Contents

require "optparse"

module Johnson #:nodoc:
  module CLI #:nodoc:
    class Options #:nodoc:
      class << self
        alias_method :parse!, :new
      end
      
      attr_reader :arguments
      attr_reader :expressions
      attr_reader :files_to_preload
      attr_reader :files_to_evaluate
      attr_reader :load_paths
      attr_reader :paths_to_require
    
      def initialize(*args)
        @arguments = []
        @expressions = []
        @load_paths = []
        @files_to_preload = []
        @paths_to_require = []

        argv = args.flatten
        
        if index = argv.index("--")
          @arguments = argv[(index+1)..-1]
          argv = argv[0..index]
        end

        parser = OptionParser.new do |parser|
          parser.banner = "Usage: johnson [options] [file.js...] [-- jsargs...]"
          parser.version = Johnson::VERSION

          parser.on("-e [EXPRESSION]", "Evaluate [EXPRESSION] and exit") do |expression|
            @expressions << expression
          end
      
          parser.on("-I [DIRECTORY]", "Specify $LOAD_PATH directories") do |dir|
            @load_paths << dir
          end

          parser.on("-i [FILE]", "Evaluate [FILE] before interaction") do |file|
            @files_to_preload << file
          end
          
          parser.on("-r [PATH]", "Require [PATH] before executing") do |path|
            @paths_to_require << path
          end
      
          parser.on("-h", "-?", "--help", "Show this message") do
            puts parser
            exit
          end
      
          parser.on("-v", "--version", "Show Johnson's version (#{Johnson::VERSION})") do
            puts Johnson::VERSION
            exit
          end  
        end
        
        parser.parse!(argv)
        @files_to_evaluate = argv.dup
      end 
    end
  end
end

Version data entries

23 entries across 23 versions & 5 rubygems

Version Path
jbarnette-johnson-1.0.0.200811251942 lib/johnson/cli/options.rb
jbarnette-johnson-1.0.0.20081126120511 lib/johnson/cli/options.rb
jbarnette-johnson-1.0.0.20090127202936 lib/johnson/cli/options.rb
jbarnette-johnson-1.0.0.20090225110820 lib/johnson/cli/options.rb
jbarnette-johnson-1.0.0.20090326122910 lib/johnson/cli/options.rb
jbarnette-johnson-1.0.0.20090326154650 lib/johnson/cli/options.rb
jbarnette-johnson-1.0.0.20090326161333 lib/johnson/cli/options.rb
jbarnette-johnson-1.0.0.20090402144841 lib/johnson/cli/options.rb
jbarnette-johnson-1.0.0.20090402155420 lib/johnson/cli/options.rb
johnson19-2.0.0.pre3 lib/johnson/cli/options.rb
pre-johnson-2.0.0 lib/johnson/cli/options.rb
johnson-2.0.0.pre3 lib/johnson/cli/options.rb
johnson-2.0.0.pre2 lib/johnson/cli/options.rb
johnson-2.0.0.pre1 lib/johnson/cli/options.rb
johnson-2.0.0.pre0 lib/johnson/cli/options.rb
johnson-1.2.0 lib/johnson/cli/options.rb
smparkes-johnson-1.1.2.6 lib/johnson/cli/options.rb
smparkes-johnson-1.1.2.5 lib/johnson/cli/options.rb
smparkes-johnson-1.1.2.4 lib/johnson/cli/options.rb
smparkes-johnson-1.1.2.3 lib/johnson/cli/options.rb