consoleappsupport 0.5.1 → 0.6.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -11,3 +11,17 @@
11
11
  * Automatically loads a Logr4 config file, if config option "--log4r-file" is
12
12
  defined and enabled.
13
13
  * Displays RDoc usage message if config option "--help" is defined and enabled.
14
+
15
+ === 0.5.1 / 2009-06-11
16
+
17
+ * Minor bug fixes and documentation
18
+
19
+ * Renamed LICENSE.txt to License.txt
20
+ * Fixed gem dependencies in Rakefile.
21
+ * Moved location of 'require' statements in Mixin module
22
+
23
+ === 0.6.0 / 2009-06-29
24
+
25
+ * Minor feature enhancements
26
+
27
+ * Added ability to specify an app option as 'required'
@@ -14,7 +14,7 @@
14
14
  # console_app_example.rb [options] argument1 arg2 etc...
15
15
  #
16
16
  # == Options (all options can be put into the config file)
17
- # -n, --repeat-output [INTEGER] Number of times to echo back the arguments. default = 1
17
+ # -n, --repeat-output [INTEGER] Number of times to echo back the arguments. Required.
18
18
  # -c, --config-file [FILE] Use config file [FILE]. default = console_app_example.conf
19
19
  # -l, --log-level [LEVEL] Sets Log4r level for console output. default = INFO
20
20
  # -r, --log4r-file [FILE] Optional Log4r config file. default = example_log4r.xml
@@ -14,7 +14,7 @@
14
14
  # cat [log files] | convert_logs_to_csv.rb [options] > [output file.csv]
15
15
  #
16
16
  # == Options (all options can be put into the config file)
17
- # -p, --log-pattern [REGEX] Regular expression for matching log lines.
17
+ # -p, --log-pattern [REGEX] Regular expression for matching log lines. REQUIRED
18
18
  # -f, --log-fields [LIST] A list of field names to assign to the parenthesized log-pattern matches.
19
19
  # -c, --config-file [FILE] Use config file [FILE], default = apache_log_to_csv.conf
20
20
  # -l, --log-level [LEVEL] Sets log level to DEBUG, INFO, WARN, ERROR or FATAL. default = INFO
@@ -20,7 +20,7 @@
20
20
  # * Call helper.read_configuration_files at any time to reload the appliation and
21
21
  # Log4r configuration files.
22
22
 
23
- require "#{File.dirname(__FILE__)}/../lib/ConsoleAppMixin.rb"
23
+ require "#{File.dirname(__FILE__)}/../lib/consoleappmixin.rb"
24
24
 
25
25
  module ConsoleAppSupport
26
26
  class ConsoleAppHelper
@@ -56,6 +56,8 @@ module ConsoleAppSupport
56
56
  OPTION_VALUE_EXPRESSION = %r{^\s*\[(\w+)\]}
57
57
  # Regexp used to determine the default value of each application option
58
58
  DEFAULT_VALUE_EXPRESSION = %r{default[^=]*=\s*(.*\S)\s*$}i
59
+ # Regexp used to determine if application option is required
60
+ REQUIRED_VALUE_EXPRESSION = %r{required}i
59
61
 
60
62
  # Predefined names for application options
61
63
  # that trigger this module's specialized behavior:
@@ -85,6 +87,7 @@ module ConsoleAppSupport
85
87
  setup_default_options
86
88
  parse_command_line
87
89
  read_configuration_files unless skip_config
90
+ verify_required_options
88
91
  end
89
92
 
90
93
  # Reads the application config file for configuration options, then
@@ -128,6 +131,8 @@ module ConsoleAppSupport
128
131
  if (DEFAULT_VALUE_EXPRESSION.match description) then
129
132
  @log.debug "This parameter defaults to '#{$1}'"
130
133
  new_app_option[:default] = convert_string($1, new_app_option[:type])
134
+ elsif (REQUIRED_VALUE_EXPRESSION.match description) then
135
+ new_app_option[:required] = true
131
136
  end
132
137
  end
133
138
  @_app_options[param] = new_app_option
@@ -274,6 +279,18 @@ module ConsoleAppSupport
274
279
  end
275
280
  end
276
281
 
282
+ def verify_required_options
283
+ @_app_options.each do |option, option_parameters|
284
+ if (not @opts.has_key? option.gsub('-','_').intern) then
285
+ if option_parameters.has_key? :required then
286
+ flag = option_parameters[:switch]
287
+ @log.fatal "Application option '#{option}' (-#{flag}) is required."
288
+ output_help
289
+ end
290
+ end
291
+ end
292
+ end
293
+
277
294
  #########################################################
278
295
  # Utility methods
279
296
 
@@ -6,7 +6,7 @@
6
6
  # See that module's documentation for usage.
7
7
 
8
8
  module ConsoleAppSupport
9
- VERSION = '0.5.1'
9
+ VERSION = '0.6.1'
10
10
  end
11
11
 
12
- require "#{File.dirname(__FILE__)}/ConsoleAppHelper.rb"
12
+ require "#{File.dirname(__FILE__)}/consoleapphelper.rb"
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: consoleappsupport
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.1
4
+ version: 0.6.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - benton
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-06-11 00:00:00 -04:00
12
+ date: 2009-10-01 00:00:00 -04:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
@@ -40,7 +40,7 @@ dependencies:
40
40
  requirements:
41
41
  - - ">="
42
42
  - !ruby/object:Gem::Version
43
- version: 2.0.0
43
+ version: 2.3.3
44
44
  version:
45
45
  description: |-
46
46
  The ConsoleAppSupport module provides some commonly-desired behavior
@@ -99,7 +99,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
99
99
  requirements: []
100
100
 
101
101
  rubyforge_project: consolesupport
102
- rubygems_version: 1.3.4
102
+ rubygems_version: 1.3.5
103
103
  signing_key:
104
104
  specification_version: 3
105
105
  summary: "The ConsoleAppSupport module provides some commonly-desired behavior for command-line programs: currently command-line parsing; config file loading; and log4r integration"