fig 0.1.62 → 0.1.64

Sign up to get free protection for your applications and to get access to all the features.
Files changed (43) hide show
  1. data/Changes +156 -0
  2. data/VERSION +1 -1
  3. data/bin/fig +9 -2
  4. data/bin/fig-debug +9 -2
  5. data/lib/fig/applicationconfiguration.rb +3 -2
  6. data/lib/fig/atexit.rb +37 -0
  7. data/lib/fig/backtrace.rb +23 -6
  8. data/lib/fig/command.rb +131 -31
  9. data/lib/fig/command/coveragesupport.rb +40 -0
  10. data/lib/fig/command/listing.rb +8 -8
  11. data/lib/fig/command/optionerror.rb +8 -0
  12. data/lib/fig/{options.rb → command/options.rb} +248 -144
  13. data/lib/fig/command/packageload.rb +161 -62
  14. data/lib/fig/configfileerror.rb +2 -0
  15. data/lib/fig/environment.rb +350 -246
  16. data/lib/fig/environmentvariables/casesensitive.rb +1 -1
  17. data/lib/fig/figrc.rb +78 -78
  18. data/lib/fig/grammar.treetop +204 -219
  19. data/lib/fig/log4rconfigerror.rb +2 -0
  20. data/lib/fig/operatingsystem.rb +382 -334
  21. data/lib/fig/package.rb +11 -33
  22. data/lib/fig/packagecache.rb +1 -1
  23. data/lib/fig/packagedescriptor.rb +103 -21
  24. data/lib/fig/packagedescriptorparseerror.rb +16 -0
  25. data/lib/fig/parser.rb +36 -19
  26. data/lib/fig/parserpackagebuildstate.rb +56 -0
  27. data/lib/fig/repository.rb +504 -259
  28. data/lib/fig/statement.rb +30 -12
  29. data/lib/fig/statement/archive.rb +8 -5
  30. data/lib/fig/statement/asset.rb +19 -0
  31. data/lib/fig/statement/command.rb +2 -2
  32. data/lib/fig/statement/configuration.rb +20 -20
  33. data/lib/fig/statement/include.rb +13 -34
  34. data/lib/fig/statement/override.rb +21 -7
  35. data/lib/fig/statement/path.rb +22 -2
  36. data/lib/fig/statement/resource.rb +14 -4
  37. data/lib/fig/statement/retrieve.rb +34 -4
  38. data/lib/fig/statement/set.rb +22 -2
  39. data/lib/fig/workingdirectorymaintainer.rb +197 -0
  40. data/lib/fig/workingdirectorymetadata.rb +45 -0
  41. metadata +52 -46
  42. data/lib/fig/retriever.rb +0 -141
  43. data/lib/fig/statement/publish.rb +0 -15
@@ -0,0 +1,40 @@
1
+ # This is not a normal module/class. It contains code to be run by bin/fig and
2
+ # bin/fig-debug when doing coverage.
3
+
4
+ # Depends upon setup done by spec/spec_helper.rb.
5
+ if ! ENV['FIG_COVERAGE_RUN_COUNT'] || ! ENV['FIG_COVERAGE_ROOT_DIRECTORY']
6
+ $stderr.puts \
7
+ 'FIG_COVERAGE_RUN_COUNT or FIG_COVERAGE_ROOT_DIRECTORY not set. Cannot do coverage correctly.'
8
+ exit 1
9
+ end
10
+
11
+ require 'simplecov'
12
+
13
+ # Normal load of .simplecov does not work because SimpleCov assumes that
14
+ # everything is relative to the current directory. The manipulation of
15
+ # SimpleCov.root below takes care of most things, but that doesn't affect
16
+ # .simplecov handling done in the "require 'simplecov'" above.
17
+ load File.expand_path(
18
+ File.join(ENV['FIG_COVERAGE_ROOT_DIRECTORY'], '.simplecov')
19
+ )
20
+
21
+ # We may run the identical fig command-line multiple times, so we need to give
22
+ # additional value to make the run name unique.
23
+ SimpleCov.command_name(
24
+ "fig run #{ENV['FIG_COVERAGE_RUN_COUNT']} (#{ARGV.join(' ')})"
25
+ )
26
+ SimpleCov.root ENV['FIG_COVERAGE_ROOT_DIRECTORY']
27
+
28
+ SimpleCov.at_exit do
29
+ # Have to invoke result() in order to get coverage data saved.
30
+ #
31
+ # Default at_exit() further invokes format():
32
+ #
33
+ # 1) We save time by not doing it on each fig run and let the rspec run
34
+ # handle that.
35
+ # 2) The formatter emits a message to stdout, which screws up tests of
36
+ # the fig output.
37
+ SimpleCov.result
38
+ end
39
+
40
+ SimpleCov.start
@@ -28,7 +28,7 @@ module Fig::Command::Listing
28
28
  end
29
29
 
30
30
  def display_configs_in_local_packages_list()
31
- @package.configs.each do |config|
31
+ @base_package.configs.each do |config|
32
32
  puts config.name
33
33
  end
34
34
 
@@ -71,7 +71,7 @@ module Fig::Command::Listing
71
71
  end
72
72
 
73
73
  def display_dependencies_in_tree()
74
- walk_dependency_tree(@package, derive_base_display_config_names(), nil, 0) do
74
+ walk_dependency_tree(@base_package, derive_base_display_config_names(), nil, 0) do
75
75
  |package, config_name, depth|
76
76
 
77
77
  print ' ' * (depth * 4)
@@ -150,7 +150,7 @@ module Fig::Command::Listing
150
150
 
151
151
  def derive_base_display_config_names()
152
152
  if @options.list_all_configs?
153
- return @package.config_names
153
+ return @base_package.config_names
154
154
  end
155
155
 
156
156
  return [ base_config() ]
@@ -160,11 +160,11 @@ module Fig::Command::Listing
160
160
  packages = {}
161
161
  starting_config_names = derive_base_display_config_names()
162
162
 
163
- if ! @package.name.nil?
164
- packages[@package] = starting_config_names.to_set
163
+ if ! @base_package.name.nil?
164
+ packages[@base_package] = starting_config_names.to_set
165
165
  end
166
166
 
167
- walk_dependency_tree(@package, starting_config_names, nil, 0) do
167
+ walk_dependency_tree(@base_package, starting_config_names, nil, 0) do
168
168
  |package, config_name, depth|
169
169
 
170
170
  if (
@@ -230,7 +230,7 @@ module Fig::Command::Listing
230
230
  prior_node = nil
231
231
  current_parent = tree
232
232
 
233
- walk_dependency_tree(@package, derive_base_display_config_names(), nil, 0) do
233
+ walk_dependency_tree(@base_package, derive_base_display_config_names(), nil, 0) do
234
234
  |package, config_name, depth|
235
235
 
236
236
  if depth < prior_depth
@@ -327,7 +327,7 @@ module Fig::Command::Listing
327
327
  def display_variables_flat_from_repository()
328
328
  variable_names = Set.new()
329
329
 
330
- walk_dependency_tree(@package, derive_base_display_config_names(), nil, 0) do
330
+ walk_dependency_tree(@base_package, derive_base_display_config_names(), nil, 0) do
331
331
  |package, config_name, depth|
332
332
 
333
333
  package[config_name].walk_statements() do |statement|
@@ -0,0 +1,8 @@
1
+ require 'fig/userinputerror'
2
+
3
+ module Fig; end
4
+ class Fig::Command; end
5
+
6
+ # Bad command-line option.
7
+ class Fig::Command::OptionError < Fig::UserInputError
8
+ end
@@ -1,5 +1,6 @@
1
1
  require 'optparse'
2
2
 
3
+ require 'fig/command/optionerror'
3
4
  require 'fig/package'
4
5
  require 'fig/packagedescriptor'
5
6
  require 'fig/statement/archive'
@@ -7,14 +8,13 @@ require 'fig/statement/include'
7
8
  require 'fig/statement/path'
8
9
  require 'fig/statement/resource'
9
10
  require 'fig/statement/set'
10
- require 'fig/userinputerror'
11
11
 
12
12
  module Fig; end
13
+ class Fig::Command; end
13
14
 
14
15
  # Command-line processing.
15
- class Fig::Options
16
+ class Fig::Command::Options
16
17
  USAGE = <<-EOF
17
-
18
18
  Usage:
19
19
 
20
20
  fig [...] [DESCRIPTOR] [--update | --update-if-missing] [-- COMMAND]
@@ -24,6 +24,7 @@ Usage:
24
24
  [--resource PATH]
25
25
  [--archive PATH]
26
26
  [--include DESCRIPTOR]
27
+ [--override DESCRIPTOR]
27
28
  [--force]
28
29
  [...]
29
30
 
@@ -40,7 +41,7 @@ Usage:
40
41
 
41
42
  A DESCRIPTOR looks like <package name>[/<version>][:<config>] e.g. "foo",
42
43
  "foo/1.2.3", and "foo/1.2.3:default". Whether ":<config>" and "/<version>" are
43
- required or allowed is dependent upon what your are doing
44
+ required or allowed is dependent upon what your are doing.
44
45
 
45
46
  Standard options (represented as "[...]" above):
46
47
 
@@ -57,7 +58,6 @@ Environment variables:
57
58
 
58
59
  FIG_REMOTE_URL (required),
59
60
  FIG_HOME (path to local repository cache, defaults to $HOME/.fighome).
60
-
61
61
  EOF
62
62
 
63
63
  LOG_LEVELS = %w[ off fatal error warn info debug all ]
@@ -69,57 +69,7 @@ Environment variables:
69
69
  attr_reader :exit_code
70
70
 
71
71
  def initialize(argv)
72
- argv = argv.clone
73
- strip_shell_command(argv)
74
-
75
- @options = {}
76
-
77
- @options[:home] = ENV['FIG_HOME'] || File.expand_path('~/.fighome')
78
-
79
- parser = new_parser()
80
-
81
- begin
82
- parser.parse!(argv)
83
- rescue OptionParser::MissingArgument => error
84
- $stderr.puts "Please provide the #{error}."
85
- @exit_code = 1
86
- return
87
- end
88
-
89
- if not exit_code.nil?
90
- return
91
- end
92
-
93
- if argv.size > 1
94
- $stderr.puts %q<Extra arguments. Should only have a package/version after all other options. Had "> + argv.join(%q<", ">) + %q<" left over.>
95
- @exit_code = 1
96
- return
97
- end
98
-
99
- package_text = argv.first
100
- if package_text
101
- @descriptor = Fig::PackageDescriptor.parse(package_text)
102
- if not @descriptor.name
103
- $stderr.puts %Q<No package name specified in descriptor "#{package_text}".>
104
- @exit_code = 1
105
- return
106
- end
107
-
108
- if not @descriptor.version
109
- $stderr.puts %Q<No version specified in descriptor "#{package_text}".>
110
- @exit_code = 1
111
- return
112
- end
113
-
114
- if @descriptor.config && config()
115
- $stderr.puts \
116
- %Q<Cannot specify both --config and a config in the descriptor "#{package_text}".>
117
- @exit_code = 1
118
- return
119
- end
120
- end
121
-
122
- return
72
+ process_command_line(argv)
123
73
  end
124
74
 
125
75
  def archives()
@@ -146,6 +96,10 @@ Environment variables:
146
96
  return @options[:get]
147
97
  end
148
98
 
99
+ def help?()
100
+ return @options[:help]
101
+ end
102
+
149
103
  def home()
150
104
  return @options[:home]
151
105
  end
@@ -178,12 +132,12 @@ Environment variables:
178
132
  return @options[:no_figrc]
179
133
  end
180
134
 
181
- def non_command_package_statements()
182
- return @options[:non_command_package_statements]
135
+ def environment_statements()
136
+ return @options[:environment_statements]
183
137
  end
184
138
 
185
- def package_config_file()
186
- return @options[:package_config_file]
139
+ def package_definition_file()
140
+ return @options[:package_definition_file]
187
141
  end
188
142
 
189
143
  def publish?()
@@ -218,6 +172,10 @@ Environment variables:
218
172
  return update? || update_if_missing?
219
173
  end
220
174
 
175
+ def version?()
176
+ return @options[:version]
177
+ end
178
+
221
179
  # Answers whether we should reset the environment to nothing, sort of like
222
180
  # the standardized environment that cron(1) creates. At present, we're only
223
181
  # setting this when we're listing variables. One could imagine allowing this
@@ -228,8 +186,7 @@ Environment variables:
228
186
  return listing() == :variables
229
187
  end
230
188
 
231
- private
232
-
189
+ # This needs to be public for efficient use of custom command.rb wrappers.
233
190
  def strip_shell_command(argv)
234
191
  argv.each_with_index do |arg, i|
235
192
  terminating_option = nil
@@ -252,30 +209,132 @@ Environment variables:
252
209
  return
253
210
  end
254
211
 
212
+ # This needs to be public for efficient use of custom command.rb wrappers.
213
+ def help()
214
+ puts @help_message
215
+ puts <<-'END_MESSAGE'
216
+ -- end of Fig options; anything after this is used as a command to run
217
+ --command-extra-args end of Fig options; anything after this is appended to the end of a
218
+ "command" statement in a "config" block.
219
+
220
+ END_MESSAGE
221
+
222
+ return 0
223
+ end
224
+
225
+ private
226
+
227
+ # Note that OptionParser insist that the regex match the entire value, not
228
+ # just matches the regex in general. In effect, OptionParser is wrapping the
229
+ # regex with "\A" and "\z".
230
+ STARTS_WITH_NON_HYPHEN = %r< \A [^-] .* >x
231
+
232
+ ARGUMENT_DESCRIPTION = {
233
+ '--set' => Fig::Statement::Set::ARGUMENT_DESCRIPTION,
234
+ '--append' => Fig::Statement::Path::ARGUMENT_DESCRIPTION
235
+ }
236
+
237
+ def process_command_line(argv)
238
+ argv = argv.clone
239
+ strip_shell_command(argv)
240
+
241
+ @switches = []
242
+ @options = {}
243
+
244
+ @options[:home] = ENV['FIG_HOME'] || File.expand_path('~/.fighome')
245
+
246
+ parser = new_parser()
247
+ @help_message = parser.help
248
+
249
+ begin
250
+ parser.parse!(argv)
251
+ rescue OptionParser::InvalidArgument => error
252
+ raise_invalid_argument(error.args[0], error.args[1])
253
+ rescue OptionParser::MissingArgument => error
254
+ raise_missing_argument(error.args[0])
255
+ rescue OptionParser::InvalidOption => error
256
+ raise Fig::Command::OptionError.new(
257
+ "Unknown option #{error.args[0]}.\n\n#{USAGE}"
258
+ )
259
+ rescue OptionParser::ParseError => error
260
+ raise Fig::Command::OptionError.new(error.to_s)
261
+ end
262
+
263
+ if not exit_code.nil?
264
+ return
265
+ end
266
+
267
+ if argv.size > 1
268
+ $stderr.puts %q<Extra arguments. Should only have a package/version after all other options. Had "> + argv.join(%q<", ">) + %q<" left over.>
269
+ @exit_code = 1
270
+ return
271
+ end
272
+
273
+ derive_primary_descriptor(argv.first)
274
+
275
+ return
276
+ end
277
+
278
+ def raise_missing_argument(option)
279
+ raise Fig::Command::OptionError.new(
280
+ "Please provide a value for #{option}."
281
+ )
282
+ end
283
+
284
+ def raise_invalid_argument(option, value)
285
+ # *sigh* OptionParser does not raise MissingArgument for the case of an
286
+ # option with a required value being followed by another option. It
287
+ # assigns the next option as the value instead. E.g. for
288
+ #
289
+ # fig --set --get FOO
290
+ #
291
+ # it assigns "--get" as the value of the "--set" option.
292
+ switch_strings =
293
+ (@switches.collect {|switch| [switch.short, switch.long]}).flatten
294
+ if switch_strings.any? {|string| string == value}
295
+ raise_missing_argument(option)
296
+ end
297
+
298
+ description = ARGUMENT_DESCRIPTION[option]
299
+ if description.nil?
300
+ description = ''
301
+ else
302
+ description = ' ' + description
303
+ end
304
+
305
+ raise Fig::Command::OptionError.new(
306
+ %Q<Invalid value for #{option}: "#{value}".#{description}>
307
+ )
308
+ end
309
+
255
310
  def new_parser
256
311
  return OptionParser.new do |parser|
257
312
  set_up_queries(parser)
258
313
  set_up_commands(parser)
259
314
  set_up_package_configuration_source(parser)
260
- set_up_package_statements(parser)
315
+ set_up_environment_statements(parser)
316
+ set_up_package_contents_statements(parser)
261
317
  set_up_remote_repository_access(parser)
262
318
  set_up_program_configuration(parser)
263
319
  end
264
320
  end
265
321
 
266
322
  def set_up_queries(parser)
267
- parser.banner = USAGE
268
- parser.on_tail('-?', '-h','--help','display this help text') do
269
- help(parser)
323
+ parser.banner = "#{USAGE}\n"
324
+ @switches << parser.define_tail(
325
+ '-?', '-h','--help','display this help text'
326
+ ) do
327
+ @options[:help] = true
270
328
  end
271
329
 
272
- parser.on_tail('-v', '--version', 'print Fig version') do
273
- version()
330
+ @switches << parser.define_tail('-v', '--version', 'print Fig version') do
331
+ @options[:version] = true
274
332
  end
275
333
 
276
- parser.on(
334
+ @switches << parser.define(
277
335
  '-g',
278
336
  '--get VARIABLE',
337
+ STARTS_WITH_NON_HYPHEN,
279
338
  'print value of environment variable VARIABLE'
280
339
  ) do |get|
281
340
  @options[:get] = get
@@ -310,7 +369,7 @@ Environment variables:
310
369
  option_mapping.each_pair do
311
370
  | type, specification |
312
371
 
313
- parser.on(*specification) do
372
+ @switches << parser.define(*specification) do
314
373
  if @options[:listing]
315
374
  options_string =
316
375
  (
@@ -325,11 +384,16 @@ Environment variables:
325
384
  end
326
385
  end
327
386
 
328
- parser.on('--list-tree', 'for listings, output a tree instead of a list') do
387
+ @switches << parser.define(
388
+ '--list-tree', 'for listings, output a tree instead of a list'
389
+ ) do
329
390
  @options[:list_tree] = true
330
391
  end
331
392
 
332
- parser.on('--list-all-configs', 'for listings, follow all configurations of the base package') do
393
+ @switches << parser.define(
394
+ '--list-all-configs',
395
+ 'for listings, follow all configurations of the base package'
396
+ ) do
333
397
  @options[:list_all_configs] = true
334
398
  end
335
399
 
@@ -337,17 +401,17 @@ Environment variables:
337
401
  end
338
402
 
339
403
  def set_up_commands(parser)
340
- parser.on('--clean', 'remove package from $FIG_HOME') do
404
+ @switches << parser.define('--clean', 'remove package from $FIG_HOME') do
341
405
  @options[:clean] = true
342
406
  end
343
407
 
344
- parser.on(
408
+ @switches << parser.define(
345
409
  '--publish', 'install package in $FIG_HOME and in remote repo'
346
410
  ) do |publish|
347
411
  @options[:publish] = true
348
412
  end
349
413
 
350
- parser.on(
414
+ @switches << parser.define(
351
415
  '--publish-local', 'install package only in $FIG_HOME'
352
416
  ) do |publish_local|
353
417
  @options[:publish_local] = true
@@ -356,86 +420,136 @@ Environment variables:
356
420
  return
357
421
  end
358
422
 
423
+ FILE_OPTION_VALUE_PATTERN =
424
+ %r<
425
+ \A
426
+ (?:
427
+ - # Solely a hyphen, to allow for stdin
428
+ | [^-] .* # or anything not starting with a hyphen.
429
+ )
430
+ \z
431
+ >x
432
+
359
433
  def set_up_package_configuration_source(parser)
360
- parser.on(
434
+ @switches << parser.define(
361
435
  '-c',
362
436
  '--config CONFIG',
437
+ STARTS_WITH_NON_HYPHEN,
363
438
  %q<apply configuration CONFIG, default is "default">
364
439
  ) do |config|
365
440
  @options[:config] = config
366
441
  end
367
442
 
368
- @options[:package_config_file] = nil
369
- parser.on(
443
+ @options[:package_definition_file] = nil
444
+ @switches << parser.define(
370
445
  '--file FILE',
446
+ FILE_OPTION_VALUE_PATTERN,
371
447
  %q<read Fig file FILE. Use '-' for stdin. See also --no-file>
372
448
  ) do |path|
373
- @options[:package_config_file] = path
449
+ @options[:package_definition_file] = path
374
450
  end
375
451
 
376
- parser.on(
452
+ @switches << parser.define(
377
453
  '--no-file', 'ignore package.fig file in current directory'
378
454
  ) do |path|
379
- @options[:package_config_file] = :none
455
+ @options[:package_definition_file] = :none
380
456
  end
381
457
 
382
458
  return
383
459
  end
384
460
 
385
- def set_up_package_statements(parser)
386
- @options[:non_command_package_statements] = []
387
- parser.on(
461
+ def set_up_environment_statements(parser)
462
+ @options[:environment_statements] = []
463
+ @switches << parser.define(
388
464
  '-p',
389
465
  '--append VARIABLE=VALUE',
466
+ STARTS_WITH_NON_HYPHEN,
390
467
  'append (actually, prepend) VALUE to PATH-like environment variable VARIABLE'
391
- ) do |var_val|
392
- var, val = var_val.split('=')
393
- @options[:non_command_package_statements] <<
394
- Fig::Statement::Path.new(nil, var, val)
468
+ ) do |name_value|
469
+ @options[:environment_statements] <<
470
+ new_variable_statement('--append', name_value, Fig::Statement::Path)
471
+ end
472
+
473
+ @switches << parser.define(
474
+ '-s',
475
+ '--set VARIABLE=VALUE',
476
+ STARTS_WITH_NON_HYPHEN,
477
+ 'set environment variable VARIABLE to VALUE'
478
+ ) do |name_value|
479
+ @options[:environment_statements] <<
480
+ new_variable_statement('--set', name_value, Fig::Statement::Set)
395
481
  end
396
482
 
397
- parser.on(
483
+ @switches << parser.define(
398
484
  '-i',
399
485
  '--include DESCRIPTOR',
486
+ STARTS_WITH_NON_HYPHEN,
400
487
  'include package/version:config specified in DESCRIPTOR in environment'
401
488
  ) do |descriptor_string|
402
489
  statement =
403
490
  Fig::Statement::Include.new(
404
- nil, Fig::PackageDescriptor.parse(descriptor_string), {}, nil
491
+ nil,
492
+ '--include option',
493
+ Fig::Statement::Include.parse_descriptor(
494
+ descriptor_string,
495
+ :validation_context => ' given in a --include option'
496
+ ),
497
+ nil
405
498
  )
499
+
500
+ # We've never allowed versionless includes from the command-line. Hooray!
406
501
  statement.complain_if_version_missing()
407
- @options[:non_command_package_statements] << statement
502
+
503
+ @options[:environment_statements] << statement
408
504
  end
409
505
 
410
- parser.on(
411
- '-s', '--set VARIABLE=VALUE', 'set environment variable VARIABLE to VALUE'
412
- ) do |var_val|
413
- var, val = var_val.split('=')
414
- @options[:non_command_package_statements] <<
415
- Fig::Statement::Set.new(nil, var, val)
506
+ @switches << parser.define(
507
+ '--override DESCRIPTOR',
508
+ STARTS_WITH_NON_HYPHEN,
509
+ 'dictate version of package as specified in DESCRIPTOR'
510
+ ) do |descriptor_string|
511
+ descriptor =
512
+ Fig::Statement::Override.parse_descriptor(
513
+ descriptor_string,
514
+ :validation_context => ' given in a --override option'
515
+ )
516
+ statement =
517
+ Fig::Statement::Override.new(
518
+ nil, '--override option', descriptor.name, descriptor.version
519
+ )
520
+
521
+ @options[:environment_statements] << statement
416
522
  end
417
523
 
524
+ return
525
+ end
526
+
527
+ def set_up_package_contents_statements(parser)
418
528
  @options[:archives] = []
419
- parser.on(
529
+ @switches << parser.define(
420
530
  '--archive PATH',
531
+ STARTS_WITH_NON_HYPHEN,
421
532
  'include PATH archive in package (when using --publish)'
422
533
  ) do |path|
423
- @options[:archives] << Fig::Statement::Archive.new(nil, path)
534
+ @options[:archives] <<
535
+ Fig::Statement::Archive.new(nil, '--archive option', path)
424
536
  end
425
537
 
426
538
  @options[:resources] =[]
427
- parser.on(
539
+ @switches << parser.define(
428
540
  '--resource PATH',
541
+ STARTS_WITH_NON_HYPHEN,
429
542
  'include PATH resource in package (when using --publish)'
430
543
  ) do |path|
431
- @options[:resources] << Fig::Statement::Resource.new(nil, path)
544
+ @options[:resources] <<
545
+ Fig::Statement::Resource.new(nil, '--resource option', path)
432
546
  end
433
547
 
434
548
  return
435
549
  end
436
550
 
437
551
  def set_up_remote_repository_access(parser)
438
- parser.on(
552
+ @switches << parser.define(
439
553
  '-u',
440
554
  '--update',
441
555
  'check remote repo for updates and download to $FIG_HOME as necessary'
@@ -443,7 +557,7 @@ Environment variables:
443
557
  @options[:update] = true
444
558
  end
445
559
 
446
- parser.on(
560
+ @switches << parser.define(
447
561
  '-m',
448
562
  '--update-if-missing',
449
563
  'check remote repo for updates only if package missing from $FIG_HOME'
@@ -451,14 +565,14 @@ Environment variables:
451
565
  @options[:update_if_missing] = true
452
566
  end
453
567
 
454
- parser.on(
568
+ @switches << parser.define(
455
569
  '-l', '--login', 'login to remote repo as a non-anonymous user'
456
570
  ) do
457
571
  @options[:login] = true
458
572
  end
459
573
 
460
574
  @options[:force] = nil
461
- parser.on(
575
+ @switches << parser.define(
462
576
  '--force',
463
577
  'force-overwrite existing version of a package to the remote repo'
464
578
  ) do |force|
@@ -469,22 +583,26 @@ Environment variables:
469
583
  end
470
584
 
471
585
  def set_up_program_configuration(parser)
472
- parser.on(
473
- '--figrc PATH', 'add PATH to configuration used for Fig'
586
+ @switches << parser.define(
587
+ '--figrc PATH',
588
+ STARTS_WITH_NON_HYPHEN,
589
+ 'add PATH to configuration used for Fig'
474
590
  ) do |path|
475
591
  @options[:figrc] = path
476
592
  end
477
593
 
478
- parser.on('--no-figrc', 'ignore ~/.figrc') { @options[:no_figrc] = true }
594
+ @switches << parser.define('--no-figrc', 'ignore ~/.figrc') { @options[:no_figrc] = true }
479
595
 
480
- parser.on(
481
- '--log-config PATH', 'use PATH file as configuration for Log4r'
596
+ @switches << parser.define(
597
+ '--log-config PATH',
598
+ STARTS_WITH_NON_HYPHEN,
599
+ 'use PATH file as configuration for Log4r'
482
600
  ) do |path|
483
601
  @options[:log_config] = path
484
602
  end
485
603
 
486
604
  level_list = LOG_LEVELS.join(', ')
487
- parser.on(
605
+ @switches << parser.define(
488
606
  '--log-level LEVEL',
489
607
  LOG_LEVELS,
490
608
  LOG_ALIASES,
@@ -494,7 +612,7 @@ Environment variables:
494
612
  @options[:log_level] = log_level
495
613
  end
496
614
 
497
- parser.on(
615
+ @switches << parser.define(
498
616
  '--suppress-warning-include-statement-missing-version',
499
617
  %q<don't complain about "include package" without a version>
500
618
  ) do
@@ -504,46 +622,32 @@ Environment variables:
504
622
  return
505
623
  end
506
624
 
507
- def help(parser)
508
- puts parser.help
509
- puts <<-'END_MESSAGE'
510
- -- end of Fig options; anything after this is used as a command to run
511
- --command-extra-args end of Fig options; anything after this is appended to the end of a
512
- "command" statement in a "config" block.
513
-
514
- END_MESSAGE
515
-
516
- @exit_code = 0
625
+ def new_variable_statement(option, name_value, statement_class)
626
+ variable, value = statement_class.parse_name_value(name_value) {
627
+ raise_invalid_argument(option, name_value)
628
+ }
517
629
 
518
- return
630
+ return statement_class.new(nil, "#{option} option", variable, value)
519
631
  end
520
632
 
521
- def version()
522
- line = nil
633
+ # This will be the base package, unless we're publishing (in which case it's
634
+ # the name to publish to.
635
+ def derive_primary_descriptor(raw_string)
636
+ return if raw_string.nil?
523
637
 
524
- begin
525
- File.open(
526
- "#{File.expand_path(File.dirname(__FILE__) + '/../../VERSION')}"
527
- ) do |file|
528
- line = file.gets
529
- end
530
- rescue
531
- $stderr.puts 'Could not retrieve version number. Something has mucked with your Fig install.'
638
+ @descriptor = Fig::PackageDescriptor.parse(
639
+ raw_string,
640
+ :name => :required,
641
+ :version => :required,
642
+ :validation_context => ' specified on command line'
643
+ )
532
644
 
645
+ if @descriptor.config && config()
646
+ $stderr.puts \
647
+ %Q<Cannot specify both --config and a config in the descriptor "#{raw_string}".>
533
648
  @exit_code = 1
534
- return
535
649
  end
536
650
 
537
- if line !~ /\d+\.\d+\.\d+/
538
- $stderr.puts %Q<"#{line}" does not look like a version number. Something has mucked with your Fig install.>
539
-
540
- @exit_code = 1
541
- return
542
- end
543
-
544
- puts File.basename($0) + ' v' + line
545
-
546
- @exit_code = 0
547
651
  return
548
652
  end
549
653
  end