Class: Johnson::CLI::Options

Inherits:
Object
  • Object
show all
Defined in:
lib/johnson/cli/options.rb

Overview

:nodoc:

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(*args) ⇒ Options

Returns a new instance of Options.



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# File 'lib/johnson/cli/options.rb', line 17

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

Instance Attribute Details

#argumentsObject (readonly)

Returns the value of attribute arguments.



10
11
12
# File 'lib/johnson/cli/options.rb', line 10

def arguments
  @arguments
end

#expressionsObject (readonly)

Returns the value of attribute expressions.



11
12
13
# File 'lib/johnson/cli/options.rb', line 11

def expressions
  @expressions
end

#files_to_evaluateObject (readonly)

Returns the value of attribute files_to_evaluate.



13
14
15
# File 'lib/johnson/cli/options.rb', line 13

def files_to_evaluate
  @files_to_evaluate
end

#files_to_preloadObject (readonly)

Returns the value of attribute files_to_preload.



12
13
14
# File 'lib/johnson/cli/options.rb', line 12

def files_to_preload
  @files_to_preload
end

#load_pathsObject (readonly)

Returns the value of attribute load_paths.



14
15
16
# File 'lib/johnson/cli/options.rb', line 14

def load_paths
  @load_paths
end

#paths_to_requireObject (readonly)

Returns the value of attribute paths_to_require.



15
16
17
# File 'lib/johnson/cli/options.rb', line 15

def paths_to_require
  @paths_to_require
end