Module: Pray::Invocation
- Defined in:
- lib/pray/invocation.rb
Class Method Summary collapse
- .context ⇒ Object
- .context=(value) ⇒ Object
- .initialize(arguments) ⇒ Object
- .invocation_context ⇒ Object
- .lockfile_path ⇒ Object
- .manifest_path ⇒ Object
- .parse_global_options(arguments) ⇒ Object
- .project_root ⇒ Object
- .require_environment_value(flag, value) ⇒ Object
- .require_option_value(flag, value) ⇒ Object
- .resolve_current_project(options = ResolveOptions.new) ⇒ Object
- .resolve_current_project_with_git_refresh_fallback(options = ResolveOptions.new, allow_git_refresh_fallback: false) ⇒ Object
- .top_level_command?(token) ⇒ Boolean
Class Method Details
.context ⇒ Object
15 16 17 |
# File 'lib/pray/invocation.rb', line 15 def context Thread.current[:pray_invocation_context] end |
.context=(value) ⇒ Object
19 20 21 |
# File 'lib/pray/invocation.rb', line 19 def context=(value) Thread.current[:pray_invocation_context] = value end |
.initialize(arguments) ⇒ Object
9 10 11 12 13 |
# File 'lib/pray/invocation.rb', line 9 def initialize(arguments) , remaining = (arguments) self.context = ProjectContext.() remaining end |
.invocation_context ⇒ Object
23 24 25 |
# File 'lib/pray/invocation.rb', line 23 def invocation_context context || ProjectContext.from_current_directory end |
.lockfile_path ⇒ Object
31 32 33 |
# File 'lib/pray/invocation.rb', line 31 def lockfile_path invocation_context.lockfile_path end |
.manifest_path ⇒ Object
27 28 29 |
# File 'lib/pray/invocation.rb', line 27 def manifest_path invocation_context.manifest_path end |
.parse_global_options(arguments) ⇒ Object
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 |
# File 'lib/pray/invocation.rb', line 61 def (arguments) = ProjectInvocationOptions.new remaining = [] index = 0 while index < arguments.length argument = arguments[index] case argument when "--path" index += 1 .project_root = require_option_value("--path", arguments[index]) when "--file-path" index += 1 .manifest_path = require_option_value("--file-path", arguments[index]) when "--env", "--environment" index += 1 .environment = require_environment_value(argument, arguments[index]) else if top_level_command?(argument) || argument.start_with?("-") remaining.concat(arguments[index..]) break end remaining.concat(arguments[index..]) break end index += 1 end [, remaining] end |
.project_root ⇒ Object
35 36 37 |
# File 'lib/pray/invocation.rb', line 35 def project_root invocation_context.project_root end |
.require_environment_value(flag, value) ⇒ Object
96 97 98 99 100 |
# File 'lib/pray/invocation.rb', line 96 def require_environment_value(flag, value) raise Error.usage("#{flag} requires a value") if value.nil? value end |
.require_option_value(flag, value) ⇒ Object
90 91 92 93 94 |
# File 'lib/pray/invocation.rb', line 90 def require_option_value(flag, value) raise Error.usage("#{flag} requires a value") if value.nil? || value.empty? value end |
.resolve_current_project(options = ResolveOptions.new) ⇒ Object
39 40 41 42 43 44 |
# File 'lib/pray/invocation.rb', line 39 def resolve_current_project( = ResolveOptions.new) context = invocation_context = .dup .environment ||= context.environment Resolve.resolve_project_in_context(context.manifest_path, context.project_root, ) end |
.resolve_current_project_with_git_refresh_fallback(options = ResolveOptions.new, allow_git_refresh_fallback: false) ⇒ Object
46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/pray/invocation.rb', line 46 def resolve_current_project_with_git_refresh_fallback( = ResolveOptions.new, allow_git_refresh_fallback: false) resolve_current_project() rescue Error => error if allow_git_refresh_fallback && !.offline && !.refresh && Resolve.resolution_may_benefit_from_git_source_refresh?(error) refreshed = .dup refreshed.refresh = true resolve_current_project(refreshed) else raise end end |
.top_level_command?(token) ⇒ Boolean
102 103 104 105 106 107 108 |
# File 'lib/pray/invocation.rb', line 102 def top_level_command?(token) %w[ manifest init prayer repo install add remove update unlock render plan apply verify drift format fmt package publish login serve confess list outdated explain vendor clean tree sync trust version -V --version -h --help help ].include?(token) end |