fig 0.1.81 → 0.2.1

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 +87 -0
  2. data/lib/fig.rb +1 -1
  3. data/lib/fig/command.rb +5 -0
  4. data/lib/fig/command/action/dump_package_definition_for_command_line.rb +62 -0
  5. data/lib/fig/command/action/dump_package_definition_parsed.rb +19 -2
  6. data/lib/fig/command/action/list_local.rb +9 -1
  7. data/lib/fig/command/action/list_remote.rb +9 -1
  8. data/lib/fig/command/action/role/list_variables_in_a_tree.rb +1 -1
  9. data/lib/fig/command/action/run_command_line.rb +1 -1
  10. data/lib/fig/command/action/run_command_statement.rb +4 -2
  11. data/lib/fig/command/options.rb +50 -18
  12. data/lib/fig/command/options/parser.rb +16 -15
  13. data/lib/fig/command/package_applier.rb +5 -3
  14. data/lib/fig/grammar/v0.rb +287 -289
  15. data/lib/fig/grammar/v0.treetop +66 -42
  16. data/lib/fig/grammar/v1.rb +629 -533
  17. data/lib/fig/grammar/v1.treetop +102 -39
  18. data/lib/fig/grammar_monkey_patches.rb +21 -0
  19. data/lib/fig/operating_system.rb +53 -36
  20. data/lib/fig/package_descriptor.rb +1 -12
  21. data/lib/fig/parser.rb +8 -33
  22. data/lib/fig/parser_package_build_state.rb +92 -31
  23. data/lib/fig/repository_package_publisher.rb +2 -2
  24. data/lib/fig/runtime_environment.rb +54 -120
  25. data/lib/fig/statement.rb +6 -6
  26. data/lib/fig/statement/asset.rb +1 -13
  27. data/lib/fig/statement/command.rb +47 -0
  28. data/lib/fig/statement/environment_variable.rb +64 -3
  29. data/lib/fig/statement/grammar_version.rb +4 -0
  30. data/lib/fig/statement/include.rb +4 -0
  31. data/lib/fig/statement/override.rb +4 -0
  32. data/lib/fig/statement/path.rb +40 -16
  33. data/lib/fig/statement/retrieve.rb +61 -5
  34. data/lib/fig/statement/set.rb +16 -19
  35. data/lib/fig/string_tokenizer.rb +63 -25
  36. data/lib/fig/tokenized_string.rb +31 -5
  37. data/lib/fig/tokenized_string/plain_segment.rb +32 -2
  38. data/lib/fig/tokenized_string/token.rb +12 -0
  39. data/lib/fig/unparser.rb +27 -12
  40. data/lib/fig/unparser/v0.rb +4 -5
  41. data/lib/fig/unparser/v1.rb +43 -6
  42. data/lib/fig/url.rb +13 -0
  43. metadata +44 -42
data/Changes CHANGED
@@ -1,3 +1,90 @@
1
+ v0.2.1
2
+
3
+ Backwards incompatibilities:
4
+
5
+ - In a retrieve statement, it is now an error to have an unescaped open
6
+ square bracket ("[") that is not followed by "ackage]". In other words,
7
+ the following was previously acceptable:
8
+
9
+ retrieve VARIABLE->foo[bar]baz
10
+
11
+ You now will need to use the v1 grammar and escape the square bracket:
12
+
13
+ grammar v1
14
+ retrieve VARIABLE->foo\[bar]baz
15
+
16
+ - Next version will not support Ruby v1.8.
17
+
18
+ Bug fix:
19
+
20
+ - Bad variable name with HTTP downloads fixed.
21
+
22
+ New features:
23
+
24
+ - New --dump-package-definition-for-command-line option, useful for
25
+ previewing a package defined via the --set, --append, --archive,
26
+ --resource, --include, and --override options.
27
+
28
+ - The long in-progress v1 grammar is available. It solves a lot of
29
+ inconsistencies in the original, now v0, grammar. The primary differences
30
+ are in allowing Bourne-shell like quoting and escaping of values (double
31
+ quotes allow whitespace, single quotes turns all interpolation off, etc.)
32
+ and the command statement now can be used without involving the shell.
33
+
34
+ For the most part, this should be transparent to you.
35
+
36
+ Command-line options are treated as if they were specified in the v1
37
+ grammar.
38
+
39
+ Older versions of fig cannot read v1 format, but versions since v0.1.75
40
+ will cleanly tell you that they can't handle it.
41
+
42
+ In order to be as compatible with older fig versions, the new fig will
43
+ publish packages using the v0 grammar, if it can find a way to do so, even
44
+ if the input package definition is given in the v1 grammar. Thus, given a
45
+ package.fig file containing
46
+
47
+ grammar v1
48
+
49
+ config default
50
+ set foo='bar'
51
+ end
52
+
53
+ the published package will look like
54
+
55
+ # grammar v0
56
+
57
+ config default
58
+ set foo=bar
59
+ end
60
+
61
+ If, when publishing, fig determines that it needs to use the v1 grammar, it
62
+ will tell you why:
63
+
64
+ > fig --set 'baz=foo#bar' --publish-local v1-grammar/test
65
+
66
+ Publishing v1-grammar/test locally.
67
+ Publishing using the v1 grammar.
68
+ Grammar v1 is required because the set statement (--set option) contains a comment ("#") character.
69
+
70
+ Documentation for the new grammar is available at
71
+ https://github.com/mfoemmel/fig/wiki/v1-grammar. It may be helpful to have
72
+ a look at the old one, as well:
73
+ https://github.com/mfoemmel/fig/wiki/v0-grammar
74
+
75
+ Miscellaneous:
76
+
77
+ - The restriction on using keywords in names introduced in v0.1.71 has been
78
+ reversed. If changes are required to deal with that, there'll just be a
79
+ new grammar version introduced.
80
+
81
+ - Fewer stack traces with network errors.
82
+
83
+ v0.2.0.beta.2
84
+ v0.2.0.beta.1
85
+
86
+ - Test releases
87
+
1
88
  v0.1.81
2
89
 
3
90
  Backwards incompatibilities:
data/lib/fig.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Fig
2
- VERSION = '0.1.81'
2
+ VERSION = '0.2.1'
3
3
  end
data/lib/fig/command.rb CHANGED
@@ -66,6 +66,7 @@ class Fig::Command
66
66
 
67
67
  context = ExecutionContext.new(
68
68
  @base_package,
69
+ @synthetic_package_for_command_line,
69
70
  base_config(),
70
71
  @environment,
71
72
  @repository,
@@ -124,6 +125,7 @@ class Fig::Command
124
125
  ExecutionContext =
125
126
  Struct.new(
126
127
  :base_package,
128
+ :synthetic_package_for_command_line,
127
129
  :base_config,
128
130
  :environment,
129
131
  :repository,
@@ -280,6 +282,9 @@ class Fig::Command
280
282
  applier.apply_config_to_environment(! apply_base_config)
281
283
  end
282
284
 
285
+ @synthetic_package_for_command_line =
286
+ applier.synthetic_package_for_command_line
287
+
283
288
  return
284
289
  end
285
290
 
@@ -0,0 +1,62 @@
1
+ require 'fig/command/action'
2
+ require 'fig/command/action/role/has_no_sub_action'
3
+ require 'fig/package_definition_text_assembler'
4
+
5
+ module Fig; end
6
+ class Fig::Command; end
7
+ module Fig::Command::Action; end
8
+
9
+ class Fig::Command::Action::DumpPackageDefinitionForCommandLine
10
+ include Fig::Command::Action
11
+ include Fig::Command::Action::Role::HasNoSubAction
12
+
13
+ def options()
14
+ return %w<--dump-package-definition-for-command-line>
15
+ end
16
+
17
+ def descriptor_requirement()
18
+ return nil
19
+ end
20
+
21
+ def modifies_repository?()
22
+ return false
23
+ end
24
+
25
+ def load_base_package?()
26
+ return true
27
+ end
28
+
29
+ def register_base_package?()
30
+ return false
31
+ end
32
+
33
+ def apply_config?()
34
+ return false
35
+ end
36
+
37
+ def configure(options)
38
+ @environment_statements = options.environment_statements
39
+ @package_contents_statements = options.package_contents_statements
40
+
41
+ return
42
+ end
43
+
44
+ def execute()
45
+ text_assembler = Fig::PackageDefinitionTextAssembler.new :emit_as_input
46
+ text_assembler.add_output @package_contents_statements
47
+ text_assembler.add_output [
48
+ Fig::Statement::Configuration.new(
49
+ nil,
50
+ nil,
51
+ Fig::Package::DEFAULT_CONFIG,
52
+ @environment_statements
53
+ )
54
+ ]
55
+
56
+
57
+ unparsed, explanations = text_assembler.assemble_package_definition
58
+ print unparsed
59
+
60
+ return EXIT_SUCCESS
61
+ end
62
+ end
@@ -35,12 +35,29 @@ class Fig::Command::Action::DumpPackageDefinitionParsed
35
35
  end
36
36
 
37
37
  def execute()
38
+ if @execution_context.synthetic_package_for_command_line
39
+ # Purposely syntactically incorrect so that nothing attempts to round
40
+ # trip this.
41
+ puts "---- synthetic package for command-line ----\n"
42
+ dump_package @execution_context.synthetic_package_for_command_line
43
+
44
+ puts "\n---- base package ----\n"
45
+ end
46
+
47
+ dump_package @execution_context.base_package
48
+
49
+ return EXIT_SUCCESS
50
+ end
51
+
52
+ private
53
+
54
+ def dump_package(package)
38
55
  text_assembler = Fig::PackageDefinitionTextAssembler.new :emit_as_input
39
- text_assembler.add_output @execution_context.base_package.statements
56
+ text_assembler.add_output package.statements
40
57
 
41
58
  unparsed, explanations = text_assembler.assemble_package_definition
42
59
  print unparsed
43
60
 
44
- return EXIT_SUCCESS
61
+ return
45
62
  end
46
63
  end
@@ -26,7 +26,15 @@ class Fig::Command::Action::ListLocal
26
26
  end
27
27
 
28
28
  def execute()
29
- @execution_context.repository.list_packages.sort.each {|item| puts item}
29
+ packages = @execution_context.repository.list_packages
30
+
31
+ if packages.empty?
32
+ if $stdout.tty?
33
+ puts 'No local packages exist.'
34
+ end
35
+ else
36
+ packages.sort.each {|item| puts item}
37
+ end
30
38
 
31
39
  return EXIT_SUCCESS
32
40
  end
@@ -30,7 +30,15 @@ class Fig::Command::Action::ListRemote
30
30
  end
31
31
 
32
32
  def execute()
33
- @execution_context.repository.list_remote_packages.sort.each {|item| puts item}
33
+ packages = @execution_context.repository.list_remote_packages
34
+
35
+ if packages.empty?
36
+ if $stdout.tty?
37
+ puts 'No local packages exist.'
38
+ end
39
+ else
40
+ packages.sort.each {|item| puts item}
41
+ end
34
42
 
35
43
  return EXIT_SUCCESS
36
44
  end
@@ -135,7 +135,7 @@ module Fig::Command::Action::Role::ListVariablesInATree
135
135
 
136
136
  print "#{variable_indent}"
137
137
  print "#{statement.name().ljust(name_width)}"
138
- print " = #{statement.value}"
138
+ print " = #{statement.tokenized_value.to_escaped_string}"
139
139
  if statement.is_a?(Fig::Statement::Path)
140
140
  print ":$#{statement.name}"
141
141
  end
@@ -49,7 +49,7 @@ class Fig::Command::Action::RunCommandLine
49
49
  base_package = @execution_context.base_package
50
50
  base_config = @execution_context.base_config
51
51
 
52
- environment.execute_command_line(
52
+ environment.expand_command_line(
53
53
  base_package, base_config, @descriptor, @command_line
54
54
  ) do
55
55
  |command| @execution_context.operating_system.plain_or_shell_exec command
@@ -49,9 +49,11 @@ class Fig::Command::Action::RunCommandStatement
49
49
  base_package = @execution_context.base_package
50
50
  base_config = @execution_context.base_config
51
51
 
52
- environment.execute_config(
52
+ environment.expand_command_statement_from_config(
53
53
  base_package, base_config, @descriptor, @extra_argv || []
54
- ) { |command| @execution_context.operating_system.shell_exec command }
54
+ ) {
55
+ |command| @execution_context.operating_system.plain_or_shell_exec command
56
+ }
55
57
 
56
58
  # Will never get here.
57
59
  end
@@ -1,4 +1,5 @@
1
1
  require 'fig/command/action/clean'
2
+ require 'fig/command/action/dump_package_definition_for_command_line'
2
3
  require 'fig/command/action/dump_package_definition_parsed'
3
4
  require 'fig/command/action/dump_package_definition_text'
4
5
  require 'fig/command/action/get'
@@ -30,6 +31,7 @@ require 'fig/command/option_error'
30
31
  require 'fig/command/options/parser'
31
32
  require 'fig/package_descriptor'
32
33
  require 'fig/statement/archive'
34
+ require 'fig/statement/command'
33
35
  require 'fig/statement/include'
34
36
  require 'fig/statement/path'
35
37
  require 'fig/statement/resource'
@@ -162,10 +164,17 @@ class Fig::Command::Options
162
164
  case arg
163
165
  when '--'
164
166
  set_base_action(Fig::Command::Action::RunCommandLine)
165
- @shell_command = argv[(i+1)..-1]
167
+ @shell_command = tokenize_command_arguments '--', argv[(i+1)..-1]
168
+
169
+ if @shell_command.empty?
170
+ raise Fig::Command::OptionError.new(
171
+ %q<The "--" option was used, but no command was specified.>
172
+ )
173
+ end
166
174
  when '--command-extra-args'
167
175
  set_base_action(Fig::Command::Action::RunCommandStatement)
168
- @command_extra_argv = argv[(i+1)..-1]
176
+ @command_extra_argv =
177
+ tokenize_command_arguments '--command-extra-args', argv[(i+1)..-1]
169
178
  end
170
179
 
171
180
  if @base_action
@@ -177,13 +186,13 @@ class Fig::Command::Options
177
186
  return
178
187
  end
179
188
 
180
- def set_up_parser
189
+ def set_up_parser()
181
190
  set_up_package_configuration_source()
182
191
  set_up_remote_repository_access()
183
- set_up_queries()
184
192
  set_up_commands()
185
193
  set_up_environment_statements()
186
194
  set_up_package_contents_statements()
195
+ set_up_queries()
187
196
  set_up_program_configuration()
188
197
 
189
198
  return
@@ -239,6 +248,12 @@ class Fig::Command::Options
239
248
  ) do
240
249
  set_base_action(Fig::Command::Action::DumpPackageDefinitionParsed)
241
250
  end
251
+ @parser.on(
252
+ '--dump-package-definition-for-command-line',
253
+ 'emit the synthetic package for the other options (--set/--archive/etc.)'
254
+ ) do
255
+ set_base_action(Fig::Command::Action::DumpPackageDefinitionForCommandLine)
256
+ end
242
257
 
243
258
  return
244
259
  end
@@ -300,16 +315,6 @@ class Fig::Command::Options
300
315
  end
301
316
 
302
317
  def set_up_commands()
303
- @parser.on('--clean', 'remove package from $FIG_HOME') do
304
- set_base_action(Fig::Command::Action::Clean)
305
- end
306
-
307
- @parser.on(
308
- '--run-command-statement', 'run the command in even in local file'
309
- ) do
310
- set_base_action(Fig::Command::Action::RunCommandStatement)
311
- end
312
-
313
318
  @parser.on(
314
319
  '--publish', 'install package in $FIG_HOME and in remote repo'
315
320
  ) do |publish|
@@ -330,6 +335,17 @@ class Fig::Command::Options
330
335
  @force = force
331
336
  end
332
337
 
338
+ @parser.on('--clean', 'remove package from $FIG_HOME') do
339
+ set_base_action(Fig::Command::Action::Clean)
340
+ end
341
+
342
+ @parser.on(
343
+ '--run-command-statement',
344
+ 'run the command in even in package definition file (i.e. no descriptor)'
345
+ ) do
346
+ set_base_action(Fig::Command::Action::RunCommandStatement)
347
+ end
348
+
333
349
  return
334
350
  end
335
351
 
@@ -357,7 +373,7 @@ class Fig::Command::Options
357
373
  @parser.on(
358
374
  '--file FILE',
359
375
  FILE_OPTION_VALUE_PATTERN,
360
- %q<read Fig file FILE. Use '-' for stdin. See also --no-file>
376
+ %q<read package definition FILE. Use '-' for stdin. See also --no-file>
361
377
  ) do |path|
362
378
  @package_definition_file = path
363
379
  end
@@ -383,7 +399,7 @@ class Fig::Command::Options
383
399
  new_variable_statement('--append', name_value, Fig::Statement::Path)
384
400
  end
385
401
  @parser.add_argument_description(
386
- %w<-p --append>, Fig::Statement::Path::ARGUMENT_DESCRIPTION
402
+ %w<-p --append>, %q<The value of this option must look like "NAME=VALUE".>
387
403
  )
388
404
 
389
405
  @parser.on(
@@ -396,7 +412,7 @@ class Fig::Command::Options
396
412
  new_variable_statement('--set', name_value, Fig::Statement::Set)
397
413
  end
398
414
  @parser.add_argument_description(
399
- %w<-s --set>, Fig::Statement::Set::ARGUMENT_DESCRIPTION
415
+ %w<-s --set>, %q<The value of this option must look like "NAME=VALUE".>
400
416
  )
401
417
 
402
418
  @parser.on(
@@ -584,7 +600,9 @@ class Fig::Command::Options
584
600
 
585
601
  def new_variable_statement(option, name_value, statement_class)
586
602
  variable, value = statement_class.parse_name_value(name_value) {
587
- @parser.raise_invalid_argument(option, name_value)
603
+ |message|
604
+
605
+ @parser.raise_invalid_argument(option, name_value, message)
588
606
  }
589
607
 
590
608
  return statement_class.new(nil, "#{option} option", variable, value)
@@ -640,4 +658,18 @@ class Fig::Command::Options
640
658
 
641
659
  return
642
660
  end
661
+
662
+ def tokenize_command_arguments(option, arguments)
663
+ return arguments.map do
664
+ |argument|
665
+
666
+ Fig::Statement::Command.validate_and_process_escapes_in_argument(
667
+ argument
668
+ ) do
669
+ |error_description|
670
+
671
+ @parser.raise_invalid_argument(option, argument, error_description)
672
+ end
673
+ end
674
+ end
643
675
  end
@@ -18,17 +18,17 @@ Running under Fig:
18
18
  fig [...] [DESCRIPTOR] --command-extra-args VALUES
19
19
  fig [...] [DESCRIPTOR] --run-command-statement
20
20
 
21
- Querying:
22
- fig {-g | --get} VARIABLE [DESCRIPTOR] [...]
23
- fig --list-dependencies [--list-tree] [--list-all-configs] [DESCRIPTOR] [...]
24
- fig --list-variables [--list-tree] [--list-all-configs] [DESCRIPTOR] [...]
25
-
26
21
  Publishing packages:
27
22
  fig {--publish | --publish-local} DESCRIPTOR
28
23
  [--resource PATH] [--archive PATH]
29
24
  [--include DESCRIPTOR] [--override DESCRIPTOR]
30
25
  [...]
31
26
 
27
+ Querying:
28
+ fig {-g | --get} VARIABLE [DESCRIPTOR] [...]
29
+ fig --list-dependencies [--list-tree] [--list-all-configs] [DESCRIPTOR] [...]
30
+ fig --list-variables [--list-tree] [--list-all-configs] [DESCRIPTOR] [...]
31
+
32
32
  Standard options (represented as "[...]" above):
33
33
  [--update | --update-if-missing]
34
34
  [--set VARIABLE=VALUE]
@@ -45,16 +45,6 @@ Running under Fig:
45
45
  fig [...] [DESCRIPTOR] --command-extra-args VALUES
46
46
  fig [...] [DESCRIPTOR] --run-command-statement
47
47
 
48
- Querying:
49
-
50
- fig {-g | --get} VARIABLE [DESCRIPTOR] [...]
51
- fig --list-dependencies [--list-tree] [--list-all-configs] [DESCRIPTOR] [...]
52
- fig --list-variables [--list-tree] [--list-all-configs] [DESCRIPTOR] [...]
53
- fig --list-configs [DESCRIPTOR] [...]
54
- fig --dump-package-definition-text [DESCRIPTOR] [...]
55
- fig --dump-package-definition-parsed [DESCRIPTOR] [...]
56
- fig {--list-local | --list-remote} [...]
57
-
58
48
  Publishing packages:
59
49
 
60
50
  fig {--publish | --publish-local} DESCRIPTOR
@@ -69,6 +59,17 @@ Local repository maintenance:
69
59
 
70
60
  fig --clean DESCRIPTOR [...]
71
61
 
62
+ Querying:
63
+
64
+ fig {--list-local | --list-remote} [...]
65
+ fig {-g | --get} VARIABLE [DESCRIPTOR] [...]
66
+ fig --list-dependencies [--list-tree] [--list-all-configs] [DESCRIPTOR] [...]
67
+ fig --list-variables [--list-tree] [--list-all-configs] [DESCRIPTOR] [...]
68
+ fig --list-configs [DESCRIPTOR] [...]
69
+ fig --dump-package-definition-text [DESCRIPTOR] [...]
70
+ fig --dump-package-definition-parsed [DESCRIPTOR] [...]
71
+ fig --dump-package-definition-for-command-line [DESCRIPTOR] [...]
72
+
72
73
  Standard options (represented as "[...]" above):
73
74
 
74
75
  [-u | --update | -m | --update-if-missing]