thor 0.19.4 → 1.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/lib/thor.rb CHANGED
@@ -1,7 +1,7 @@
1
- require "set"
2
- require "thor/base"
1
+ require_relative "thor/base"
3
2
 
4
3
  class Thor
4
+ $thor_runner ||= false
5
5
  class << self
6
6
  # Allows for custom "Command" package naming.
7
7
  #
@@ -90,9 +90,14 @@ class Thor
90
90
  # ==== Parameters
91
91
  # Hash[String|Array => Symbol]:: Maps the string or the strings in the array to the given command.
92
92
  #
93
- def map(mappings = nil)
93
+ def map(mappings = nil, **kw)
94
94
  @map ||= from_superclass(:map, {})
95
95
 
96
+ if mappings && !kw.empty?
97
+ mappings = kw.merge!(mappings)
98
+ else
99
+ mappings ||= kw
100
+ end
96
101
  if mappings
97
102
  mappings.each do |key, value|
98
103
  if key.respond_to?(:each)
@@ -158,10 +163,6 @@ class Thor
158
163
  end
159
164
  alias_method :option, :method_option
160
165
 
161
- def disable_class_options
162
- @disable_class_options = true
163
- end
164
-
165
166
  # Prints help information for the given command.
166
167
  #
167
168
  # ==== Parameters
@@ -174,7 +175,7 @@ class Thor
174
175
  handle_no_command_error(meth) unless command
175
176
 
176
177
  shell.say "Usage:"
177
- shell.say " #{banner(command)}"
178
+ shell.say " #{banner(command).split("\n").join("\n ")}"
178
179
  shell.say
179
180
  class_options_help(shell, nil => command.options.values)
180
181
  if command.long_description
@@ -241,6 +242,9 @@ class Thor
241
242
  invoke_args.unshift "help" if opts.delete("--help") || opts.delete("-h")
242
243
  invoke subcommand_class, *invoke_args
243
244
  end
245
+ subcommand_class.commands.each do |_meth, command|
246
+ command.ancestor_name = subcommand
247
+ end
244
248
  end
245
249
  alias_method :subtask, :subcommand
246
250
 
@@ -319,17 +323,36 @@ class Thor
319
323
  # ==== Parameters
320
324
  # Symbol ...:: A list of commands that should be affected.
321
325
  def stop_on_unknown_option!(*command_names)
322
- stop_on_unknown_option.merge(command_names)
326
+ @stop_on_unknown_option = stop_on_unknown_option | command_names
323
327
  end
324
328
 
325
329
  def stop_on_unknown_option?(command) #:nodoc:
326
330
  command && stop_on_unknown_option.include?(command.name.to_sym)
327
331
  end
328
332
 
333
+ # Disable the check for required options for the given commands.
334
+ # This is useful if you have a command that does not need the required options
335
+ # to work, like help.
336
+ #
337
+ # ==== Parameters
338
+ # Symbol ...:: A list of commands that should be affected.
339
+ def disable_required_check!(*command_names)
340
+ @disable_required_check = disable_required_check | command_names
341
+ end
342
+
343
+ def disable_required_check?(command) #:nodoc:
344
+ command && disable_required_check.include?(command.name.to_sym)
345
+ end
346
+
329
347
  protected
330
348
 
331
349
  def stop_on_unknown_option #:nodoc:
332
- @stop_on_unknown_option ||= Set.new
350
+ @stop_on_unknown_option ||= []
351
+ end
352
+
353
+ # help command has the required check disabled by default.
354
+ def disable_required_check #:nodoc:
355
+ @disable_required_check ||= [:help]
333
356
  end
334
357
 
335
358
  # The method responsible for dispatching given the args.
@@ -375,7 +398,9 @@ class Thor
375
398
  # the namespace should be displayed as arguments.
376
399
  #
377
400
  def banner(command, namespace = nil, subcommand = false)
378
- "#{basename} #{command.formatted_usage(self, $thor_runner, subcommand)}"
401
+ command.formatted_usage(self, $thor_runner, subcommand).split("\n").map do |formatted_usage|
402
+ "#{basename} #{formatted_usage}"
403
+ end.join("\n")
379
404
  end
380
405
 
381
406
  def baseclass #:nodoc:
@@ -390,12 +415,12 @@ class Thor
390
415
  @usage ||= nil
391
416
  @desc ||= nil
392
417
  @long_desc ||= nil
393
- @disable_class_options ||= nil
418
+ @hide ||= nil
394
419
 
395
420
  if @usage && @desc
396
421
  base_class = @hide ? Thor::HiddenCommand : Thor::Command
397
- commands[meth] = base_class.new(meth, @desc, @long_desc, @usage, method_options, @disable_class_options)
398
- @usage, @desc, @long_desc, @method_options, @hide, @disable_class_options = nil
422
+ commands[meth] = base_class.new(meth, @desc, @long_desc, @usage, method_options)
423
+ @usage, @desc, @long_desc, @method_options, @hide = nil
399
424
  true
400
425
  elsif all_commands[meth] || meth == "method_missing"
401
426
  true
@@ -477,7 +502,6 @@ class Thor
477
502
  map HELP_MAPPINGS => :help
478
503
 
479
504
  desc "help [COMMAND]", "Describe available commands or one specific command"
480
- disable_class_options
481
505
  def help(command = nil, subcommand = false)
482
506
  if command
483
507
  if self.class.subcommands.include? command
data/thor.gemspec CHANGED
@@ -4,7 +4,7 @@ $LOAD_PATH.unshift lib unless $LOAD_PATH.include?(lib)
4
4
  require "thor/version"
5
5
 
6
6
  Gem::Specification.new do |spec|
7
- spec.add_development_dependency "bundler", "~> 1.0"
7
+ spec.add_development_dependency "bundler", ">= 1.0", "< 3"
8
8
  spec.authors = ["Yehuda Katz", "José Valim"]
9
9
  spec.description = "Thor is a toolkit for building powerful command-line interfaces."
10
10
  spec.email = "ruby-thor@googlegroups.com"
@@ -13,8 +13,16 @@ Gem::Specification.new do |spec|
13
13
  spec.homepage = "http://whatisthor.com/"
14
14
  spec.licenses = %w(MIT)
15
15
  spec.name = "thor"
16
+ spec.metadata = {
17
+ "bug_tracker_uri" => "https://github.com/rails/thor/issues",
18
+ "changelog_uri" => "https://github.com/rails/thor/releases/tag/v#{Thor::VERSION}",
19
+ "documentation_uri" => "http://whatisthor.com/",
20
+ "source_code_uri" => "https://github.com/rails/thor/tree/v#{Thor::VERSION}",
21
+ "wiki_uri" => "https://github.com/rails/thor/wiki",
22
+ "rubygems_mfa_required" => "true",
23
+ }
16
24
  spec.require_paths = %w(lib)
17
- spec.required_ruby_version = ">= 1.8.7"
25
+ spec.required_ruby_version = ">= 2.0.0"
18
26
  spec.required_rubygems_version = ">= 1.3.5"
19
27
  spec.summary = spec.description
20
28
  spec.version = Thor::VERSION
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: thor
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.19.4
4
+ version: 1.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Yehuda Katz
@@ -9,22 +9,28 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2016-11-28 00:00:00.000000000 Z
12
+ date: 2022-01-04 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: bundler
16
16
  requirement: !ruby/object:Gem::Requirement
17
17
  requirements:
18
- - - "~>"
18
+ - - ">="
19
19
  - !ruby/object:Gem::Version
20
20
  version: '1.0'
21
+ - - "<"
22
+ - !ruby/object:Gem::Version
23
+ version: '3'
21
24
  type: :development
22
25
  prerelease: false
23
26
  version_requirements: !ruby/object:Gem::Requirement
24
27
  requirements:
25
- - - "~>"
28
+ - - ">="
26
29
  - !ruby/object:Gem::Version
27
30
  version: '1.0'
31
+ - - "<"
32
+ - !ruby/object:Gem::Version
33
+ version: '3'
28
34
  description: Thor is a toolkit for building powerful command-line interfaces.
29
35
  email: ruby-thor@googlegroups.com
30
36
  executables:
@@ -33,7 +39,6 @@ extensions: []
33
39
  extra_rdoc_files: []
34
40
  files:
35
41
  - ".document"
36
- - CHANGELOG.md
37
42
  - CONTRIBUTING.md
38
43
  - LICENSE.md
39
44
  - README.md
@@ -49,14 +54,13 @@ files:
49
54
  - lib/thor/base.rb
50
55
  - lib/thor/command.rb
51
56
  - lib/thor/core_ext/hash_with_indifferent_access.rb
52
- - lib/thor/core_ext/io_binary_read.rb
53
- - lib/thor/core_ext/ordered_hash.rb
54
57
  - lib/thor/error.rb
55
58
  - lib/thor/group.rb
56
59
  - lib/thor/invocation.rb
57
60
  - lib/thor/line_editor.rb
58
61
  - lib/thor/line_editor/basic.rb
59
62
  - lib/thor/line_editor/readline.rb
63
+ - lib/thor/nested_context.rb
60
64
  - lib/thor/parser.rb
61
65
  - lib/thor/parser/argument.rb
62
66
  - lib/thor/parser/arguments.rb
@@ -74,7 +78,13 @@ files:
74
78
  homepage: http://whatisthor.com/
75
79
  licenses:
76
80
  - MIT
77
- metadata: {}
81
+ metadata:
82
+ bug_tracker_uri: https://github.com/rails/thor/issues
83
+ changelog_uri: https://github.com/rails/thor/releases/tag/v1.2.1
84
+ documentation_uri: http://whatisthor.com/
85
+ source_code_uri: https://github.com/rails/thor/tree/v1.2.1
86
+ wiki_uri: https://github.com/rails/thor/wiki
87
+ rubygems_mfa_required: 'true'
78
88
  post_install_message:
79
89
  rdoc_options: []
80
90
  require_paths:
@@ -83,15 +93,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
83
93
  requirements:
84
94
  - - ">="
85
95
  - !ruby/object:Gem::Version
86
- version: 1.8.7
96
+ version: 2.0.0
87
97
  required_rubygems_version: !ruby/object:Gem::Requirement
88
98
  requirements:
89
99
  - - ">="
90
100
  - !ruby/object:Gem::Version
91
101
  version: 1.3.5
92
102
  requirements: []
93
- rubyforge_project:
94
- rubygems_version: 2.5.2
103
+ rubygems_version: 3.2.32
95
104
  signing_key:
96
105
  specification_version: 4
97
106
  summary: Thor is a toolkit for building powerful command-line interfaces.
data/CHANGELOG.md DELETED
@@ -1,163 +0,0 @@
1
- ## 0.19.1, release 2014-03-24
2
- * Fix `say` non-String break regression
3
-
4
- ## 0.19.0, release 2014-03-22
5
- * Add support for a default to #ask
6
- * Avoid @namespace not initialized warning
7
- * Avoid private attribute? warning
8
- * Fix initializing with unknown options
9
- * Loosen required_rubygems_version for compatibility with Ubuntu 10.04
10
- * Shell#ask: support a noecho option for stdin
11
- * Shell#ask: change API to be :echo => false
12
- * Display a message without a stack trace for ambiguous commands
13
- * Make say and say_status thread safe
14
- * Dependency for console io version check
15
- * Alias --help to help on subcommands
16
- * Use mime-types 1.x for Ruby 1.8.7 compatibility for Ruby 1.8 only
17
- * Accept .tt files as templates
18
- * Check if numeric value is in enum
19
- * Use Readline for user input
20
- * Fix dispatching of subcommands (concerning :help and *args)
21
- * Fix warnings when running specs with `$VERBOSE = true`
22
- * Make subcommand help more consistent
23
- * Make the current command chain accessible in command
24
-
25
- ## 0.18.1, release 2013-03-30
26
- * Revert regressions found in 0.18.0
27
-
28
- ## 0.18.0, release 2013-03-26
29
- * Remove rake2thor
30
- * Only display colors if output medium supports colors
31
- * Pass parent_options to subcommands
32
- * Fix non-dash-prefixed aliases
33
- * Make error messages more helpful
34
- * Rename "task" to "command"
35
- * Add the method to allow for custom package name
36
-
37
- ## 0.17.0, release 2013-01-24
38
- * Add better support for tasks that accept arbitrary additional arguments (e.g. things like `bundle exec`)
39
- * Add #stop_on_unknown_option!
40
- * Only strip from stdin.gets if it wasn't ended with EOF
41
- * Allow "send" as a task name
42
- * Allow passing options as arguments after "--"
43
- * Autoload Thor::Group
44
-
45
- ## 0.16.0, release 2012-08-14
46
- * Add enum to string arguments
47
-
48
- ## 0.15.4, release 2012-06-29
49
- * Fix regression when destination root contains reserved regexp characters
50
-
51
- ## 0.15.3, release 2012-06-18
52
- * Support strict_args_position! for backwards compatibility
53
- * Escape Dir glob characters in paths
54
-
55
- ## 0.15.2, released 2012-05-07
56
- * Added print_in_columns
57
- * Exposed terminal_width as a public API
58
-
59
- ## 0.15.1, release 2012-05-06
60
- * Fix Ruby 1.8 truncation bug with unicode chars
61
- * Fix shell delegate methods to pass their block
62
- * Don't output trailing spaces when printing the last column in a table
63
-
64
- ## 0.15, released 2012-04-29
65
- * Alias method_options to options
66
- * Refactor say to allow multiple colors
67
- * Exposed error as a public API
68
- * Exposed file_collision as a public API
69
- * Exposed print_wrapped as a public API
70
- * Exposed set_color as a public API
71
- * Fix number-formatting bugs in print_table
72
- * Fix "indent" typo in print_table
73
- * Fix Errno::EPIPE when piping tasks to `head`
74
- * More friendly error messages
75
-
76
- ## 0.14, released 2010-07-25
77
- * Added CreateLink class and #link_file method
78
- * Made Thor::Actions#run use system as default method for system calls
79
- * Allow use of private methods from superclass as tasks
80
- * Added mute(&block) method which allows to run block without any output
81
- * Removed config[:pretend]
82
- * Enabled underscores for command line switches
83
- * Added Thor::Base.basename which is used by both Thor.banner and Thor::Group.banner
84
- * Deprecated invoke() without arguments
85
- * Added :only and :except to check_unknown_options
86
-
87
- ## 0.13, released 2010-02-03
88
- * Added :lazy_default which is only triggered if a switch is given
89
- * Added Thor::Shell::HTML
90
- * Added subcommands
91
- * Decoupled Thor::Group and Thor, so it's easier to vendor
92
- * Added check_unknown_options! in case you want error messages to be raised in valid switches
93
- * run(command) should return the results of command
94
-
95
- ## 0.12, released 2010-01-02
96
- * Methods generated by attr_* are automatically not marked as tasks
97
- * inject_into_file does not add the same content twice, unless :force is set
98
- * Removed rr in favor to rspec mock framework
99
- * Improved output for thor -T
100
- * [#7] Do not force white color on status
101
- * [#8] Yield a block with the filename on directory
102
-
103
- ## 0.11, released 2009-07-01
104
- * Added a rake compatibility layer. It allows you to use spec and rdoc tasks on
105
- Thor classes.
106
- * BACKWARDS INCOMPATIBLE: aliases are not generated automatically anymore
107
- since it may cause wrong behavior in the invocation system.
108
- * thor help now show information about any class/task. All those calls are
109
- possible:
110
-
111
- thor help describe
112
- thor help describe:amazing
113
- Or even with default namespaces:
114
-
115
- thor help :spec
116
- * Thor::Runner now invokes the default task if none is supplied:
117
-
118
- thor describe # invokes the default task, usually help
119
- * Thor::Runner now works with mappings:
120
-
121
- thor describe -h
122
- * Added some documentation and code refactoring.
123
-
124
- ## 0.9.8, released 2008-10-20
125
- * Fixed some tiny issues that were introduced lately.
126
-
127
- ## 0.9.7, released 2008-10-13
128
- * Setting global method options on the initialize method works as expected:
129
- All other tasks will accept these global options in addition to their own.
130
- * Added 'group' notion to Thor task sets (class Thor); by default all tasks
131
- are in the 'standard' group. Running 'thor -T' will only show the standard
132
- tasks - adding --all will show all tasks. You can also filter on a specific
133
- group using the --group option: thor -T --group advanced
134
-
135
- ## 0.9.6, released 2008-09-13
136
- * Generic improvements
137
-
138
- ## 0.9.5, released 2008-08-27
139
- * Improve Windows compatibility
140
- * Update (incorrect) README and task.thor sample file
141
- * Options hash is now frozen (once returned)
142
- * Allow magic predicates on options object. For instance: `options.force?`
143
- * Add support for :numeric type
144
- * BACKWARDS INCOMPATIBLE: Refactor Thor::Options. You cannot access shorthand forms in options hash anymore (for instance, options[:f])
145
- * Allow specifying optional args with default values: method_options(:user => "mislav")
146
- * Don't write options for nil or false values. This allows, for example, turning color off when running specs.
147
- * Exit with the status of the spec command to help CI stuff out some.
148
-
149
- ## 0.9.4, released 2008-08-13
150
- * Try to add Windows compatibility.
151
- * BACKWARDS INCOMPATIBLE: options hash is now accessed as a property in your class and is not passed as last argument anymore
152
- * Allow options at the beginning of the argument list as well as the end.
153
- * Make options available with symbol keys in addition to string keys.
154
- * Allow true to be passed to Thor#method_options to denote a boolean option.
155
- * If loading a thor file fails, don't give up, just print a warning and keep going.
156
- * Make sure that we re-raise errors if they happened further down the pipe than we care about.
157
- * Only delete the old file on updating when the installation of the new one is a success
158
- * Make it Ruby 1.8.5 compatible.
159
- * Don't raise an error if a boolean switch is defined multiple times.
160
- * Thor::Options now doesn't parse through things that look like options but aren't.
161
- * Add URI detection to install task, and make sure we don't append ".thor" to URIs
162
- * Add rake2thor to the gem binfiles.
163
- * Make sure local Thorfiles override system-wide ones.
@@ -1,12 +0,0 @@
1
- class IO #:nodoc:
2
- class << self
3
- unless method_defined? :binread
4
- def binread(file, *args)
5
- raise ArgumentError, "wrong number of arguments (#{1 + args.size} for 1..3)" unless args.size < 3
6
- File.open(file, "rb") do |f|
7
- f.read(*args)
8
- end
9
- end
10
- end
11
- end
12
- end
@@ -1,129 +0,0 @@
1
- class Thor
2
- module CoreExt
3
- class OrderedHash < ::Hash
4
- if RUBY_VERSION < "1.9"
5
- def initialize(*args, &block)
6
- super
7
- @keys = []
8
- end
9
-
10
- def initialize_copy(other)
11
- super
12
- # make a deep copy of keys
13
- @keys = other.keys
14
- end
15
-
16
- def []=(key, value)
17
- @keys << key unless key?(key)
18
- super
19
- end
20
-
21
- def delete(key)
22
- if key? key
23
- index = @keys.index(key)
24
- @keys.delete_at index
25
- end
26
- super
27
- end
28
-
29
- def delete_if
30
- super
31
- sync_keys!
32
- self
33
- end
34
-
35
- alias_method :reject!, :delete_if
36
-
37
- def reject(&block)
38
- dup.reject!(&block)
39
- end
40
-
41
- def keys
42
- @keys.dup
43
- end
44
-
45
- def values
46
- @keys.map { |key| self[key] }
47
- end
48
-
49
- def to_hash
50
- self
51
- end
52
-
53
- def to_a
54
- @keys.map { |key| [key, self[key]] }
55
- end
56
-
57
- def each_key
58
- return to_enum(:each_key) unless block_given?
59
- @keys.each { |key| yield(key) }
60
- self
61
- end
62
-
63
- def each_value
64
- return to_enum(:each_value) unless block_given?
65
- @keys.each { |key| yield(self[key]) }
66
- self
67
- end
68
-
69
- def each
70
- return to_enum(:each) unless block_given?
71
- @keys.each { |key| yield([key, self[key]]) }
72
- self
73
- end
74
-
75
- def each_pair
76
- return to_enum(:each_pair) unless block_given?
77
- @keys.each { |key| yield(key, self[key]) }
78
- self
79
- end
80
-
81
- alias_method :select, :find_all
82
-
83
- def clear
84
- super
85
- @keys.clear
86
- self
87
- end
88
-
89
- def shift
90
- k = @keys.first
91
- v = delete(k)
92
- [k, v]
93
- end
94
-
95
- def merge!(other_hash)
96
- if block_given?
97
- other_hash.each { |k, v| self[k] = key?(k) ? yield(k, self[k], v) : v }
98
- else
99
- other_hash.each { |k, v| self[k] = v }
100
- end
101
- self
102
- end
103
-
104
- alias_method :update, :merge!
105
-
106
- def merge(other_hash, &block)
107
- dup.merge!(other_hash, &block)
108
- end
109
-
110
- # When replacing with another hash, the initial order of our keys must come from the other hash -ordered or not.
111
- def replace(other)
112
- super
113
- @keys = other.keys
114
- self
115
- end
116
-
117
- def inspect
118
- "#<#{self.class} #{super}>"
119
- end
120
-
121
- private
122
-
123
- def sync_keys!
124
- @keys.delete_if { |k| !key?(k) }
125
- end
126
- end
127
- end
128
- end
129
- end