fig 0.1.69 → 0.1.71

Sign up to get free protection for your applications and to get access to all the features.
@@ -19,6 +19,10 @@ module Fig::Command::Action::Role::Publish
19
19
  return true
20
20
  end
21
21
 
22
+ def cares_about_package_content_options?()
23
+ return true
24
+ end
25
+
22
26
  def load_base_package?()
23
27
  return true
24
28
  end
@@ -1,6 +1,9 @@
1
1
  require 'fig/command/action/clean'
2
+ require 'fig/command/action/dump_package_definition_parsed'
3
+ require 'fig/command/action/dump_package_definition_text'
2
4
  require 'fig/command/action/get'
3
5
  require 'fig/command/action/help'
6
+ require 'fig/command/action/help_long'
4
7
  require 'fig/command/action/list_configs'
5
8
  require 'fig/command/action/list_dependencies'
6
9
  require 'fig/command/action/list_dependencies/all_configs'
@@ -14,6 +17,7 @@ require 'fig/command/action/list_variables/all_configs'
14
17
  require 'fig/command/action/list_variables/default'
15
18
  require 'fig/command/action/list_variables/tree'
16
19
  require 'fig/command/action/list_variables/tree_all_configs'
20
+ require 'fig/command/action/options'
17
21
  require 'fig/command/action/publish'
18
22
  require 'fig/command/action/publish_local'
19
23
  require 'fig/command/action/run_command_line'
@@ -35,27 +39,6 @@ class Fig::Command; end
35
39
 
36
40
  # Command-line processing.
37
41
  class Fig::Command::Options
38
- # Public version of #strip_shell_command() here so that it can be kept in
39
- # sync.
40
- def self.strip_shell_command(argv)
41
- argv.each_with_index do |arg, i|
42
- found_command_line_end = false
43
-
44
- case arg
45
- when '--'
46
- found_command_line_end = true
47
- when '--command-extra-args'
48
- found_command_line_end = true
49
- end
50
-
51
- if found_command_line_end
52
- return argv.slice(i..-1)
53
- end
54
- end
55
-
56
- return argv
57
- end
58
-
59
42
  attr_reader :command_extra_argv
60
43
  attr_reader :config
61
44
  attr_reader :descriptor
@@ -84,7 +67,6 @@ class Fig::Command::Options
84
67
  strip_shell_command(argv)
85
68
 
86
69
  set_up_parser()
87
- @help_message = @parser.help
88
70
 
89
71
  @parser.parse!(argv)
90
72
 
@@ -128,13 +110,16 @@ class Fig::Command::Options
128
110
  return @force
129
111
  end
130
112
 
131
- def help_message()
132
- return @help_message + <<-'END_MESSAGE'
133
- -- end of Fig options; anything after this is used as a command to run
134
- --command-extra-args end of Fig options; anything after this is appended to the end of a
135
- "command" statement in a "config" block.
113
+ def short_help_message()
114
+ return @parser.short_help
115
+ end
136
116
 
137
- END_MESSAGE
117
+ def full_help_message()
118
+ return @parser.full_help + EXTRA_OPTIONS_DESCRIPTION
119
+ end
120
+
121
+ def options_message()
122
+ return @parser.options_message + EXTRA_OPTIONS_DESCRIPTION
138
123
  end
139
124
 
140
125
  def login?()
@@ -151,7 +136,14 @@ class Fig::Command::Options
151
136
 
152
137
  private
153
138
 
154
- # Note that OptionParser insist that the regex match the entire value, not
139
+ EXTRA_OPTIONS_DESCRIPTION = <<-'END_DESCRIPTION'
140
+ -- end of Fig options; anything after this is used as a command to run
141
+ --command-extra-args end of Fig options; anything after this is appended to the end of a
142
+ "command" statement in a "config" block.
143
+
144
+ END_DESCRIPTION
145
+
146
+ # Note that OptionParser insists that the regex match the entire value, not
155
147
  # just matches the regex in general. In effect, OptionParser is wrapping the
156
148
  # regex with "\A" and "\z".
157
149
  STARTS_WITH_NON_HYPHEN = %r< \A [^-] .* >x
@@ -187,12 +179,12 @@ class Fig::Command::Options
187
179
  end
188
180
 
189
181
  def set_up_parser
182
+ set_up_package_configuration_source()
183
+ set_up_remote_repository_access()
190
184
  set_up_queries()
191
185
  set_up_commands()
192
- set_up_package_configuration_source()
193
186
  set_up_environment_statements()
194
187
  set_up_package_contents_statements()
195
- set_up_remote_repository_access()
196
188
  set_up_program_configuration()
197
189
 
198
190
  return
@@ -200,10 +192,20 @@ class Fig::Command::Options
200
192
 
201
193
  def set_up_queries()
202
194
  @parser.on_tail(
203
- '-?', '-h','--help','display this help text'
195
+ '-?', '-h', '--help', 'display short usage summary'
204
196
  ) do
205
197
  set_base_action(Fig::Command::Action::Help)
206
198
  end
199
+ @parser.on_tail(
200
+ '--help-long', 'display full usage'
201
+ ) do
202
+ set_base_action(Fig::Command::Action::HelpLong)
203
+ end
204
+ @parser.on_tail(
205
+ '--options', 'just list Fig options'
206
+ ) do
207
+ set_base_action(Fig::Command::Action::Options)
208
+ end
207
209
 
208
210
  @parser.on_tail('-v', '--version', 'print Fig version') do
209
211
  set_base_action(Fig::Command::Action::Version)
@@ -221,6 +223,19 @@ class Fig::Command::Options
221
223
 
222
224
  set_up_listings()
223
225
 
226
+ @parser.on(
227
+ '--dump-package-definition-text',
228
+ 'emit the unparsed definition of the base package, if there is one'
229
+ ) do
230
+ set_base_action(Fig::Command::Action::DumpPackageDefinitionText)
231
+ end
232
+ @parser.on(
233
+ '--dump-package-definition-parsed',
234
+ 'emit the parsed definition of the base package'
235
+ ) do
236
+ set_base_action(Fig::Command::Action::DumpPackageDefinitionParsed)
237
+ end
238
+
224
239
  return
225
240
  end
226
241
 
@@ -297,6 +312,14 @@ class Fig::Command::Options
297
312
  set_base_action(Fig::Command::Action::PublishLocal)
298
313
  end
299
314
 
315
+ @force = nil
316
+ @parser.on(
317
+ '--force',
318
+ 'force-overwrite existing version of a package to the remote repo'
319
+ ) do |force|
320
+ @force = force
321
+ end
322
+
300
323
  return
301
324
  end
302
325
 
@@ -418,7 +441,7 @@ class Fig::Command::Options
418
441
  'include PATH archive in package (when using --publish)'
419
442
  ) do |path|
420
443
  @package_contents_statements <<
421
- Fig::Statement::Archive.new(nil, '--archive option', path)
444
+ new_content_statement('--archive', path, Fig::Statement::Archive)
422
445
  end
423
446
 
424
447
  @parser.on(
@@ -427,7 +450,7 @@ class Fig::Command::Options
427
450
  'include PATH resource in package (when using --publish)'
428
451
  ) do |path|
429
452
  @package_contents_statements <<
430
- Fig::Statement::Resource.new(nil, '--resource option', path)
453
+ new_content_statement('--resource', path, Fig::Statement::Resource)
431
454
  end
432
455
 
433
456
  return
@@ -456,14 +479,6 @@ class Fig::Command::Options
456
479
  @login = true
457
480
  end
458
481
 
459
- @force = nil
460
- @parser.on(
461
- '--force',
462
- 'force-overwrite existing version of a package to the remote repo'
463
- ) do |force|
464
- @force = force
465
- end
466
-
467
482
  return
468
483
  end
469
484
 
@@ -500,14 +515,14 @@ class Fig::Command::Options
500
515
  @log_level = log_level
501
516
  end
502
517
 
503
- @update_lock_response = :fail
504
- update_lock_responses = [:fail, :wait, :ignore]
518
+ @update_lock_response = nil # Nil means wait, but warn.
519
+ update_lock_responses = [:wait, :fail, :ignore]
505
520
  response_list = update_lock_responses.join(', ')
506
521
  @parser.on(
507
522
  '--update-lock-response TYPE',
508
523
  update_lock_responses,
509
524
  'what to do when update lock already exists',
510
- " (#{response_list}, default is fail)"
525
+ " (#{response_list}, default is wait)"
511
526
  ) do |response|
512
527
  @update_lock_response = response
513
528
  end
@@ -563,6 +578,16 @@ class Fig::Command::Options
563
578
  return statement_class.new(nil, "#{option} option", variable, value)
564
579
  end
565
580
 
581
+ def new_content_statement(option, path, statement_class)
582
+ statement_class.validate_url(path) {
583
+ |error_description|
584
+
585
+ @parser.raise_invalid_argument(option, path, error_description)
586
+ }
587
+
588
+ return statement_class.new(nil, "#{option} option", path)
589
+ end
590
+
566
591
  def set_up_sub_actions()
567
592
  if @base_action and @base_action.sub_action?
568
593
  # This is a cheat because the only things with sub-actions at present are
@@ -10,58 +10,105 @@ class Fig::Command::Options; end
10
10
  class Fig::Command::Options::Parser
11
11
  # This class knows way too much about how OptionParser works.
12
12
 
13
- USAGE = <<-EOF
14
- Usage:
13
+ SHORT_USAGE = <<-'END_SHORT_USAGE'
14
+ Short usage summary (use --help-long for everything):
15
15
 
16
- fig [...] [DESCRIPTOR] [--update | --update-if-missing] [-- COMMAND]
17
- fig [...] [DESCRIPTOR] [--update | --update-if-missing] [--command-extra-args VALUES]
16
+ Running under Fig:
17
+ fig [...] [DESCRIPTOR] [-- COMMAND]
18
+ fig [...] [DESCRIPTOR] --command-extra-args VALUES
18
19
 
20
+ Querying:
21
+ fig {-g | --get} VARIABLE [DESCRIPTOR] [...]
22
+ fig --list-dependencies [--list-tree] [--list-all-configs] [DESCRIPTOR] [...]
23
+ fig --list-variables [--list-tree] [--list-all-configs] [DESCRIPTOR] [...]
24
+
25
+ Publishing packages:
19
26
  fig {--publish | --publish-local} DESCRIPTOR
20
- [--resource PATH]
21
- [--archive PATH]
22
- [--include DESCRIPTOR]
23
- [--override DESCRIPTOR]
24
- [--force]
27
+ [--resource PATH] [--archive PATH]
28
+ [--include DESCRIPTOR] [--override DESCRIPTOR]
25
29
  [...]
26
30
 
27
- fig --clean DESCRIPTOR [...]
31
+ Standard options (represented as "[...]" above):
32
+ [--update | --update-if-missing]
33
+ [--set VARIABLE=VALUE]
34
+ [--append VARIABLE=VALUE]
35
+ [--file PATH] [--no-file]
28
36
 
29
- fig --get VARIABLE [DESCRIPTOR] [...]
30
- fig --list-configs [DESCRIPTOR] [...]
37
+ (--options for full option list; --help-long for everything)
38
+ END_SHORT_USAGE
39
+
40
+ FULL_USAGE = <<-'END_FULL_USAGE'
41
+ Running under Fig:
42
+
43
+ fig [...] [DESCRIPTOR] [-- COMMAND]
44
+ fig [...] [DESCRIPTOR] --command-extra-args VALUES
45
+
46
+ Querying:
47
+
48
+ fig {-g | --get} VARIABLE [DESCRIPTOR] [...]
31
49
  fig --list-dependencies [--list-tree] [--list-all-configs] [DESCRIPTOR] [...]
32
- fig --list-variables [--list-tree] [--list-all-configs] [DESCRIPTOR] [...]
50
+ fig --list-variables [--list-tree] [--list-all-configs] [DESCRIPTOR] [...]
51
+ fig --list-configs [DESCRIPTOR] [...]
52
+ fig --dump-package-definition-text [DESCRIPTOR] [...]
53
+ fig --dump-package-definition-parsed [DESCRIPTOR] [...]
33
54
  fig {--list-local | --list-remote} [...]
34
55
 
35
- fig {--version | --help}
56
+ Publishing packages:
36
57
 
58
+ fig {--publish | --publish-local} DESCRIPTOR
59
+ [--resource PATH]
60
+ [--archive PATH]
61
+ [{-i | --include} DESCRIPTOR]
62
+ [--override DESCRIPTOR]
63
+ [--force]
64
+ [...]
37
65
 
38
- A DESCRIPTOR looks like <package name>[/<version>][:<config>] e.g. "foo",
39
- "foo/1.2.3", and "foo/1.2.3:default". Whether ":<config>" and "/<version>" are
40
- required or allowed is dependent upon what your are doing.
66
+ Local repository maintenance:
67
+
68
+ fig --clean DESCRIPTOR [...]
41
69
 
42
70
  Standard options (represented as "[...]" above):
43
71
 
44
- [--set VARIABLE=VALUE]
45
- [--append VARIABLE=VALUE]
72
+ [-u | --update | -m | --update-if-missing]
73
+ --update-lock-response TYPE
74
+
75
+ [{-s | --set} VARIABLE=VALUE]
76
+ [{-p | --append} VARIABLE=VALUE]
77
+
46
78
  [--file PATH] [--no-file]
47
- [--config CONFIG]
48
- [--login]
79
+ [{-c | --config} CONFIG]
80
+
81
+ [-l | --login]
82
+
49
83
  [--log-level LEVEL] [--log-config PATH]
50
- [--figrc PATH] [--no-figrc]
84
+ [--figrc PATH] [--no-figrc]
85
+
51
86
  [--suppress-warning-include-statement-missing-version]
52
87
 
88
+ Information:
89
+
90
+ fig --help
91
+ fig --help-long
92
+ fig --options
93
+ fig {-v | --version}
94
+
95
+
96
+ A DESCRIPTOR looks like <package name>[/<version>][:<config>] e.g. "foo",
97
+ "foo/1.2.3", and "foo/1.2.3:default". Whether ":<config>" and "/<version>" are
98
+ required or allowed is dependent upon what your are doing.
99
+
53
100
  Environment variables:
54
101
 
55
- FIG_REMOTE_URL (required),
56
- FIG_HOME (path to local repository cache, defaults to $HOME/.fighome).
57
- EOF
102
+ FIG_REMOTE_URL location of remote repository, required for remote operations
103
+ FIG_HOME path to local repository, defaults to $HOME/.fighome
104
+ END_FULL_USAGE
58
105
 
59
106
  def initialize()
60
107
  @switches = {}
61
108
  @argument_description = {}
62
109
  @parser = OptionParser.new
63
110
 
64
- @parser.banner = "#{USAGE}\n"
111
+ @parser.banner = "#{FULL_USAGE}\nAll options:\n\n"
65
112
  end
66
113
 
67
114
  def add_argument_description(options, description)
@@ -108,10 +155,18 @@ Environment variables:
108
155
  return
109
156
  end
110
157
 
111
- def help()
158
+ def short_help()
159
+ return SHORT_USAGE
160
+ end
161
+
162
+ def full_help()
112
163
  return @parser.help
113
164
  end
114
165
 
166
+ def options_message()
167
+ return @parser.summarize('')
168
+ end
169
+
115
170
  def parse!(argv)
116
171
  begin
117
172
  @parser.parse!(argv)
@@ -121,7 +176,7 @@ Environment variables:
121
176
  raise_missing_argument(error.args[0])
122
177
  rescue OptionParser::InvalidOption => error
123
178
  raise Fig::Command::OptionError.new(
124
- "Unknown option #{error.args[0]}.\n\n#{USAGE}"
179
+ "Unknown option #{error.args[0]}.\n\n#{SHORT_USAGE}"
125
180
  )
126
181
  rescue OptionParser::ParseError => error
127
182
  raise Fig::Command::OptionError.new(error.to_s)
@@ -130,7 +185,7 @@ Environment variables:
130
185
  return
131
186
  end
132
187
 
133
- def raise_invalid_argument(option, value)
188
+ def raise_invalid_argument(option, value, description = nil)
134
189
  # *sigh* OptionParser does not raise MissingArgument for the case of an
135
190
  # option with a required value being followed by another option. It
136
191
  # assigns the next option as the value instead. E.g. for
@@ -142,7 +197,7 @@ Environment variables:
142
197
  raise_missing_argument(option)
143
198
  end
144
199
 
145
- description = @argument_description[option]
200
+ description ||= @argument_description[option]
146
201
  if description.nil?
147
202
  description = ''
148
203
  else
@@ -157,6 +212,9 @@ Environment variables:
157
212
  private
158
213
 
159
214
  def make_switch_array(arguments, block)
215
+ # This method is a means of interjecting ourselves between the creation of
216
+ # a Switch object and putting it into the list of actual switches.
217
+ #
160
218
  # From the OptionParser code, the contents of the array:
161
219
  #
162
220
  # +switch+:: OptionParser::Switch instance to be inserted.
data/lib/fig/figrc.rb CHANGED
@@ -14,12 +14,23 @@ class Fig::FigRC
14
14
  "#{Fig::Repository::METADATA_SUBDIRECTORY}/figrc"
15
15
 
16
16
  def self.find(
17
- override_path, repository_url, login, fig_home, disable_figrc = false
17
+ override_path,
18
+ specified_repository_url,
19
+ login,
20
+ fig_home,
21
+ disable_figrc = false
18
22
  )
19
- configuration = Fig::ApplicationConfiguration.new(repository_url)
23
+ configuration = Fig::ApplicationConfiguration.new()
20
24
 
21
25
  handle_override_configuration(configuration, override_path)
22
26
  handle_figrc(configuration) if not disable_figrc
27
+
28
+ repository_url =
29
+ derive_repository_url(specified_repository_url, configuration)
30
+
31
+ configuration.base_whitelisted_url = repository_url
32
+ configuration.remote_repository_url = repository_url
33
+
23
34
  handle_repository_configuration(
24
35
  configuration, repository_url, login, fig_home
25
36
  )
@@ -58,6 +69,12 @@ class Fig::FigRC
58
69
  return
59
70
  end
60
71
 
72
+ def self.derive_repository_url(specified_repository_url, configuration)
73
+ return specified_repository_url if specified_repository_url
74
+
75
+ return configuration['default FIG_REMOTE_URL']
76
+ end
77
+
61
78
  def self.handle_repository_configuration(
62
79
  configuration, repository_url, login, fig_home
63
80
  )
@@ -77,7 +94,7 @@ class Fig::FigRC
77
94
  repo_config_exists = false
78
95
  end
79
96
 
80
- return configuration if not repo_config_exists
97
+ return if not repo_config_exists
81
98
 
82
99
  begin
83
100
  configuration.push_dataset(