atli 0.1.2 → 0.1.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.yardopts +1 -2
- data/atli.gemspec +34 -3
- data/lib/thor.rb +202 -204
- data/lib/thor/base.rb +247 -185
- data/lib/thor/base/common_class_options.rb +56 -0
- data/lib/thor/command.rb +9 -1
- data/lib/thor/error.rb +16 -0
- data/lib/thor/execution.rb +276 -0
- data/lib/thor/version.rb +11 -2
- metadata +35 -5
@@ -0,0 +1,56 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
# Requirements
|
5
|
+
# =======================================================================
|
6
|
+
|
7
|
+
# Deps
|
8
|
+
# -----------------------------------------------------------------------
|
9
|
+
require 'nrser'
|
10
|
+
|
11
|
+
|
12
|
+
# Refinements
|
13
|
+
# =======================================================================
|
14
|
+
|
15
|
+
using NRSER
|
16
|
+
using NRSER::Types
|
17
|
+
|
18
|
+
# Declarations
|
19
|
+
# =======================================================================
|
20
|
+
|
21
|
+
module Thor::Base; end
|
22
|
+
|
23
|
+
|
24
|
+
# Definitions
|
25
|
+
# =======================================================================
|
26
|
+
|
27
|
+
# Mixin that provides "macros" for including common class options.
|
28
|
+
#
|
29
|
+
module Thor::Base::CommonClassOptions
|
30
|
+
@@messages = Concurrent::Hash.new
|
31
|
+
|
32
|
+
def self.define name, *args, &block
|
33
|
+
@@messages[name.to_sym] = \
|
34
|
+
NRSER::Message.new :class_option, name, *args, &block
|
35
|
+
end
|
36
|
+
|
37
|
+
|
38
|
+
define :backtrace,
|
39
|
+
desc: "Print stack traces with error messages",
|
40
|
+
type: :boolean
|
41
|
+
|
42
|
+
|
43
|
+
def common_class_options *names
|
44
|
+
messages = Hamster::Hash.new @@messages
|
45
|
+
|
46
|
+
names.map( &:to_sym ).each do |name|
|
47
|
+
unless messages.key? name
|
48
|
+
raise KeyError,
|
49
|
+
"No common class option named #{ name }"
|
50
|
+
end
|
51
|
+
|
52
|
+
messages[name].send_to self
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
end # module Thor::Base::CommonClassOptions
|
data/lib/thor/command.rb
CHANGED
@@ -57,7 +57,15 @@ class Thor
|
|
57
57
|
raise e
|
58
58
|
end
|
59
59
|
rescue Exception => error
|
60
|
-
instance
|
60
|
+
# NOTE Need to use `#__send__` because the instance may define a
|
61
|
+
# command (method) `#send` - and one of the test fixtures **does**:
|
62
|
+
#
|
63
|
+
# //spec/fixtures/script.thor:100
|
64
|
+
#
|
65
|
+
# That's why the Thor code above uses `#__send__`, and we need to
|
66
|
+
# too.
|
67
|
+
#
|
68
|
+
instance.__send__ :on_run_error, error, self, args
|
61
69
|
|
62
70
|
# We should not get here!!!
|
63
71
|
# {Thor::Base#on_run_error} should exit or re-raise :(
|
data/lib/thor/error.rb
CHANGED
@@ -29,4 +29,20 @@ class Thor
|
|
29
29
|
|
30
30
|
class MalformattedArgumentError < InvocationError
|
31
31
|
end
|
32
|
+
|
33
|
+
# Raised when a combination of conflicting arguments is provided.
|
34
|
+
#
|
35
|
+
# @todo
|
36
|
+
# It would be nice to parametrize this.
|
37
|
+
#
|
38
|
+
class ConflictingArgumentError < InvocationError
|
39
|
+
end
|
40
|
+
|
41
|
+
# Raised when an argument is not allowed.
|
42
|
+
#
|
43
|
+
# @todo
|
44
|
+
# It would be nice to parametrize this.
|
45
|
+
#
|
46
|
+
class ProhibitedArgumentError < InvocationError
|
47
|
+
end
|
32
48
|
end
|
@@ -0,0 +1,276 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
# Requirements
|
5
|
+
# =======================================================================
|
6
|
+
|
7
|
+
# Stdlib
|
8
|
+
# -----------------------------------------------------------------------
|
9
|
+
|
10
|
+
# Deps
|
11
|
+
# -----------------------------------------------------------------------
|
12
|
+
|
13
|
+
# Project / Package
|
14
|
+
# -----------------------------------------------------------------------
|
15
|
+
|
16
|
+
|
17
|
+
# Refinements
|
18
|
+
# =======================================================================
|
19
|
+
|
20
|
+
using NRSER
|
21
|
+
using NRSER::Types
|
22
|
+
|
23
|
+
|
24
|
+
# Declarations
|
25
|
+
# =======================================================================
|
26
|
+
|
27
|
+
|
28
|
+
# Definitions
|
29
|
+
# =======================================================================
|
30
|
+
|
31
|
+
|
32
|
+
# An execution is an object created by {Thor::Base::ClassMethods#exec!} that
|
33
|
+
# holds references to all relevant objects for running a {Thor} instance as
|
34
|
+
# an executable and manages that execution.
|
35
|
+
#
|
36
|
+
class Thor::Execution
|
37
|
+
|
38
|
+
# Constants
|
39
|
+
# ======================================================================
|
40
|
+
|
41
|
+
BUILT_IN_ENV_PREFIXES = Hamster::Vector['ATLI', 'THOR']
|
42
|
+
|
43
|
+
|
44
|
+
# Mixins
|
45
|
+
# ============================================================================
|
46
|
+
|
47
|
+
include SemanticLogger::Loggable
|
48
|
+
|
49
|
+
|
50
|
+
# Attributes
|
51
|
+
# ======================================================================
|
52
|
+
|
53
|
+
# The {Thor} subclass that is being executed.
|
54
|
+
#
|
55
|
+
# @return [Class<Thor>]
|
56
|
+
#
|
57
|
+
attr_reader :thor_class
|
58
|
+
|
59
|
+
|
60
|
+
# The command line arguments given for execution.
|
61
|
+
#
|
62
|
+
# @return [Array<String>]
|
63
|
+
#
|
64
|
+
attr_reader :given_args
|
65
|
+
|
66
|
+
|
67
|
+
# The configuration hash, which includes any config values passed to
|
68
|
+
# {Thor::Base::ClassMethods#exec!}, and is mutated in {Thor::Base#initialize}
|
69
|
+
# to include things like the current command.
|
70
|
+
#
|
71
|
+
# @return [Hash]
|
72
|
+
#
|
73
|
+
attr_reader :thor_config
|
74
|
+
|
75
|
+
|
76
|
+
# The instance or {Thor} being executed, if it has been successfully
|
77
|
+
# constructed.
|
78
|
+
#
|
79
|
+
# @return [Class<Thor>?]
|
80
|
+
#
|
81
|
+
attr_reader :thor_instance
|
82
|
+
|
83
|
+
|
84
|
+
# Constructor
|
85
|
+
# ======================================================================
|
86
|
+
|
87
|
+
# Instantiate a new `Thor::Execution`.
|
88
|
+
def initialize thor_class:, given_args:, thor_config:
|
89
|
+
@thor_class = thor_class
|
90
|
+
@given_args = given_args.dup
|
91
|
+
@thor_config = thor_config
|
92
|
+
@thor_instance = nil
|
93
|
+
end # #initialize
|
94
|
+
|
95
|
+
|
96
|
+
# Instance Methods
|
97
|
+
# ======================================================================
|
98
|
+
|
99
|
+
# @todo Document env_prefixes method.
|
100
|
+
#
|
101
|
+
# @param [type] arg_name
|
102
|
+
# @todo Add name param description.
|
103
|
+
#
|
104
|
+
# @return [return_type]
|
105
|
+
# @todo Document return value.
|
106
|
+
#
|
107
|
+
def env_prefixes
|
108
|
+
BUILT_IN_ENV_PREFIXES
|
109
|
+
end # #env_prefixes
|
110
|
+
|
111
|
+
|
112
|
+
|
113
|
+
# @todo Document env_key method.
|
114
|
+
#
|
115
|
+
# @param [type] arg_name
|
116
|
+
# @todo Add name param description.
|
117
|
+
#
|
118
|
+
# @return [return_type]
|
119
|
+
# @todo Document return value.
|
120
|
+
#
|
121
|
+
def env_key_for prefix:, key:
|
122
|
+
"#{ prefix }_#{ key.upcase }"
|
123
|
+
end # #env_key
|
124
|
+
|
125
|
+
|
126
|
+
# @todo Document get_from_env method.
|
127
|
+
#
|
128
|
+
# @param key (see #get_context_value)
|
129
|
+
# @param with_source: (see #get_context_value)
|
130
|
+
#
|
131
|
+
# @return [String?]
|
132
|
+
# When +with_source:+ is +false+, just returns the value that was found,
|
133
|
+
# or +nil+ if none was.
|
134
|
+
#
|
135
|
+
# @return [Array<(nil, nil, nil)>]
|
136
|
+
# When +with_source:+ is +true+ and no value was found.
|
137
|
+
#
|
138
|
+
# @return [Array<(String, :env, String)>]
|
139
|
+
# When +with_source:+ is +true+ and the value was found.
|
140
|
+
#
|
141
|
+
# The first entry is the value, the last is the +ENV+ key it was at.
|
142
|
+
#
|
143
|
+
def get_from_env key, with_source: false
|
144
|
+
env_prefixes.each do |prefix|
|
145
|
+
env_key = env_key_for prefix: prefix, key: key
|
146
|
+
if ENV.key? env_key
|
147
|
+
if with_source
|
148
|
+
return [ENV[env_key], :env, env_key]
|
149
|
+
else
|
150
|
+
return ENV[env_key]
|
151
|
+
end
|
152
|
+
end
|
153
|
+
end
|
154
|
+
|
155
|
+
if with_source
|
156
|
+
[nil, nil, nil]
|
157
|
+
else
|
158
|
+
nil
|
159
|
+
end
|
160
|
+
end # #get_from_env
|
161
|
+
|
162
|
+
|
163
|
+
# Get the value for a key from the "context", which is the hierarchy of
|
164
|
+
# {Thor} instance class options, Thor config values and ENV variables.
|
165
|
+
#
|
166
|
+
# @param [Symbol] key
|
167
|
+
# The key to get the value for.
|
168
|
+
#
|
169
|
+
# @param [Boolean] with_source:
|
170
|
+
# When +true+, returns where the value was found as well (see below).
|
171
|
+
#
|
172
|
+
# @return [Object]
|
173
|
+
# When +with_source:+ is +false+, just returns the value that was found,
|
174
|
+
# or +nil+ if none was.
|
175
|
+
#
|
176
|
+
# @return [Array<(Object, Symbol?, (String | Symbol)?>)]
|
177
|
+
# When +with_source:+ is +true+ returns an Array triple:
|
178
|
+
#
|
179
|
+
# 1. The value that was found, or `nil` if none was.
|
180
|
+
#
|
181
|
+
# 2. A symbol indicating where the value was found:
|
182
|
+
# 1. +:thor_instance_options+ The `#options` hash of the
|
183
|
+
# {#thor_instance}. You will only see this result if the Thor
|
184
|
+
# instance successfully constructed and became available to the
|
185
|
+
# execution.
|
186
|
+
# 2. +:thor_config+ The {#thor_config} hash.
|
187
|
+
# 3. +:env+ The +ENV+.
|
188
|
+
#
|
189
|
+
# If the value isn't found, this will be +nil+.
|
190
|
+
#
|
191
|
+
# 3. The key used to get the value from the source hash-like. This is only
|
192
|
+
# really important when it came from the +ENV+.
|
193
|
+
#
|
194
|
+
# If the value is not found, this will be +nil+.
|
195
|
+
#
|
196
|
+
def get_context_value key, with_source: false
|
197
|
+
# 1. First stop is the Thor instance's options (if we have a Thor instance)
|
198
|
+
if thor_instance && thor_instance.options.key?( key )
|
199
|
+
if with_source
|
200
|
+
return [thor_instance.options[key], :thor_instance_options, key]
|
201
|
+
else
|
202
|
+
return thor_instance.options[key]
|
203
|
+
end
|
204
|
+
end
|
205
|
+
|
206
|
+
# 2. Next, check the config that was handed to `.exec!`
|
207
|
+
if thor_config.key? key
|
208
|
+
if with_source
|
209
|
+
return [thor_config[key], :thor_config, key]
|
210
|
+
else
|
211
|
+
return thor_config[key]
|
212
|
+
end
|
213
|
+
end
|
214
|
+
|
215
|
+
# 3. Last, check the ENV (returns `nil` if nothing found)
|
216
|
+
get_from_env key, with_source: with_source
|
217
|
+
end # #get_context_value
|
218
|
+
|
219
|
+
|
220
|
+
# Are we in debug mode?
|
221
|
+
def debug?
|
222
|
+
get_context_value( :debug ).truthy?
|
223
|
+
end
|
224
|
+
|
225
|
+
|
226
|
+
# Should we print backtraces with errors?
|
227
|
+
def backtrace?
|
228
|
+
debug? || get_context_value( :backtrace ).truthy?
|
229
|
+
end
|
230
|
+
|
231
|
+
|
232
|
+
# Should we raise errors (versus print them and exit)?
|
233
|
+
def raise_errors?
|
234
|
+
debug? || get_context_value( :raise_errors ).truthy?
|
235
|
+
end
|
236
|
+
|
237
|
+
|
238
|
+
# Let's do this thang!
|
239
|
+
def exec!
|
240
|
+
thor_config[:shell] ||= Thor::Base.shell.new
|
241
|
+
|
242
|
+
thor_class.send(
|
243
|
+
:dispatch,
|
244
|
+
nil,
|
245
|
+
given_args,
|
246
|
+
nil,
|
247
|
+
thor_config
|
248
|
+
) { |thor_instance|
|
249
|
+
@thor_instance = thor_instance
|
250
|
+
|
251
|
+
logger.debug "Got Thor instance",
|
252
|
+
options: thor_instance.options
|
253
|
+
}
|
254
|
+
rescue SystemExit
|
255
|
+
# `exit` was called; we want to just let this keep going
|
256
|
+
raise
|
257
|
+
rescue Errno::EPIPE
|
258
|
+
# This happens if a thor command is piped to something like `head`,
|
259
|
+
# which closes the pipe when it's done reading. This will also
|
260
|
+
# mean that if the pipe is closed, further unnecessary
|
261
|
+
# computation will not occur.
|
262
|
+
exit true
|
263
|
+
rescue Exception => error
|
264
|
+
raise if raise_errors?
|
265
|
+
|
266
|
+
if backtrace?
|
267
|
+
logger.error error
|
268
|
+
else
|
269
|
+
logger.error error.message
|
270
|
+
end
|
271
|
+
|
272
|
+
exit false
|
273
|
+
end # #start
|
274
|
+
|
275
|
+
|
276
|
+
end # class Thor::Execution
|
data/lib/thor/version.rb
CHANGED
@@ -1,11 +1,20 @@
|
|
1
|
+
require 'pathname'
|
2
|
+
|
1
3
|
class Thor
|
4
|
+
# Absolute, expanded path to the gem's root directory.
|
5
|
+
#
|
6
|
+
# @return [Pathname]
|
7
|
+
#
|
8
|
+
ROOT = Pathname.new( __dir__ ).join( '..', '..' ).expand_path
|
9
|
+
|
10
|
+
|
2
11
|
# Gem version string.
|
3
12
|
#
|
4
13
|
# See {file:doc/files/notes/versioning.md} for details.
|
5
14
|
#
|
6
15
|
# @return [String]
|
7
16
|
#
|
8
|
-
VERSION =
|
17
|
+
VERSION = '0.1.3'
|
9
18
|
|
10
19
|
|
11
20
|
# The version of Thor that Atli is up to date with.
|
@@ -18,5 +27,5 @@ class Thor
|
|
18
27
|
#
|
19
28
|
# @return [String]
|
20
29
|
#
|
21
|
-
THOR_VERSION = '0.
|
30
|
+
THOR_VERSION = '0.1.3'
|
22
31
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: atli
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Neil Souza (Atli)
|
@@ -10,7 +10,7 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date: 2018-02-
|
13
|
+
date: 2018-02-27 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: bundler
|
@@ -32,14 +32,42 @@ dependencies:
|
|
32
32
|
requirements:
|
33
33
|
- - ">="
|
34
34
|
- !ruby/object:Gem::Version
|
35
|
-
version: 0.2.0.pre.
|
35
|
+
version: 0.2.0.pre.2
|
36
36
|
type: :runtime
|
37
37
|
prerelease: false
|
38
38
|
version_requirements: !ruby/object:Gem::Requirement
|
39
39
|
requirements:
|
40
40
|
- - ">="
|
41
41
|
- !ruby/object:Gem::Version
|
42
|
-
version: 0.2.0.pre.
|
42
|
+
version: 0.2.0.pre.2
|
43
|
+
- !ruby/object:Gem::Dependency
|
44
|
+
name: yard
|
45
|
+
requirement: !ruby/object:Gem::Requirement
|
46
|
+
requirements:
|
47
|
+
- - "~>"
|
48
|
+
- !ruby/object:Gem::Version
|
49
|
+
version: 0.9.12
|
50
|
+
type: :development
|
51
|
+
prerelease: false
|
52
|
+
version_requirements: !ruby/object:Gem::Requirement
|
53
|
+
requirements:
|
54
|
+
- - "~>"
|
55
|
+
- !ruby/object:Gem::Version
|
56
|
+
version: 0.9.12
|
57
|
+
- !ruby/object:Gem::Dependency
|
58
|
+
name: redcarpet
|
59
|
+
requirement: !ruby/object:Gem::Requirement
|
60
|
+
requirements:
|
61
|
+
- - "~>"
|
62
|
+
- !ruby/object:Gem::Version
|
63
|
+
version: '3.4'
|
64
|
+
type: :development
|
65
|
+
prerelease: false
|
66
|
+
version_requirements: !ruby/object:Gem::Requirement
|
67
|
+
requirements:
|
68
|
+
- - "~>"
|
69
|
+
- !ruby/object:Gem::Version
|
70
|
+
version: '3.4'
|
43
71
|
description: Atli is a fork of Thor that's better or worse.
|
44
72
|
email: neil@atli.nrser.com
|
45
73
|
executables:
|
@@ -63,11 +91,13 @@ files:
|
|
63
91
|
- lib/thor/actions/file_manipulation.rb
|
64
92
|
- lib/thor/actions/inject_into_file.rb
|
65
93
|
- lib/thor/base.rb
|
94
|
+
- lib/thor/base/common_class_options.rb
|
66
95
|
- lib/thor/command.rb
|
67
96
|
- lib/thor/core_ext/hash_with_indifferent_access.rb
|
68
97
|
- lib/thor/core_ext/io_binary_read.rb
|
69
98
|
- lib/thor/core_ext/ordered_hash.rb
|
70
99
|
- lib/thor/error.rb
|
100
|
+
- lib/thor/execution.rb
|
71
101
|
- lib/thor/group.rb
|
72
102
|
- lib/thor/invocation.rb
|
73
103
|
- lib/thor/line_editor.rb
|
@@ -107,7 +137,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
107
137
|
version: 1.3.5
|
108
138
|
requirements: []
|
109
139
|
rubyforge_project:
|
110
|
-
rubygems_version: 2.5.2
|
140
|
+
rubygems_version: 2.5.2.2
|
111
141
|
signing_key:
|
112
142
|
specification_version: 4
|
113
143
|
summary: Atli is a fork of Thor that's better or worse.
|