Class: GlassFish::CommandLineParser

Inherits:
Object
  • Object
show all
Defined in:
lib/command_line_parser.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#configObject

Returns the value of attribute config.



51
52
53
# File 'lib/command_line_parser.rb', line 51

def config
  @config
end

Instance Method Details

#parseObject



54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
# File 'lib/command_line_parser.rb', line 54

def parse

  check_java

  @config = Config.init_opts

  opts = GetoptLong.new(
  [ '--port', '-p', GetoptLong::REQUIRED_ARGUMENT ],
  [ '--address', '-a', GetoptLong::REQUIRED_ARGUMENT ],
  [ '--environment', '-e', GetoptLong::REQUIRED_ARGUMENT ],
  [ '--contextroot', '-c', GetoptLong::REQUIRED_ARGUMENT ],
  [ '--config', GetoptLong::REQUIRED_ARGUMENT ],
  [ '--daemon', '-d', GetoptLong::NO_ARGUMENT ],
  [ '--pid', '-P', GetoptLong::REQUIRED_ARGUMENT ],
  [ '--log', '-l', GetoptLong::OPTIONAL_ARGUMENT ],
  [ '--log-level', GetoptLong::REQUIRED_ARGUMENT ],
  [ '--runtimes', '-n', GetoptLong::REQUIRED_ARGUMENT ],
  [ '--runtimes-min', GetoptLong::REQUIRED_ARGUMENT ],
  [ '--runtimes-max', GetoptLong::REQUIRED_ARGUMENT ],
  [ '--version', '-v', GetoptLong::NO_ARGUMENT ],
  [ '--help', '-h', GetoptLong::NO_ARGUMENT ]
  )

  config_file = File.join(config[:app_dir], "config", "glassfish.yml")
  opts.each do |opt, arg|
    case opt
    when '--version'
      require 'version'
      puts "#{GlassFish::FULLVERSION}"
      exit(0)
    when '--help'
      RDoc::usage
    when '--contextroot'
      config[:contextroot] = arg
    when '--address'
      config[:address] = arg
    when '--port'
      config[:port] = arg.to_i
    when '--environment'
      config[:environment] = arg
    when '--runtimes'
      config[:runtimes] = arg.to_i
    when '--runtimes-min'
      config[:runtimes_min] = arg.to_i
    when '--runtimes-max'
      config[:runtimes_max] = arg.to_i
    when '--daemon'
      config[:daemon] = true
    when '--pid'
      config[:pid] = File.expand_path arg
    when '--log'
      #if user just mentioned 'glassfish -l', it means he wants to log the messages on console
      if(arg.nil? or arg.empty?)
        config[:log_console] = true
      else
        config[:log] = File.expand_path arg
      end
    when '--log-level'
      if arg =~ /^[0-7]$/
        config[:log_level] = arg.to_i
      else
        config[:log_level] = org.glassfish.scripting.gem.Options::LogLevel.value_of(arg.to_s.upcase).ordinal
      end
    when '--config'
      config_file = arg
    end
  end


  config[:app_dir] = ARGV.shift unless ARGV.empty?

  #Read the config file from config/glasfish.yml
  config_file = Config::absolutize config[:app_dir],config_file
  read_glassfish_config(config_file, config)

  config

end