atli 0.1.7 → 0.1.8
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.
- checksums.yaml +4 -4
- data/atli.gemspec +1 -1
- data/lib/thor.rb +57 -14
- data/lib/thor/base/class_methods.rb +17 -6
- data/lib/thor/command.rb +19 -7
- data/lib/thor/example.rb +23 -0
- data/lib/thor/group.rb +1 -1
- data/lib/thor/parser/option.rb +4 -1
- data/lib/thor/parser/shared_option.rb +95 -1
- data/lib/thor/version.rb +2 -2
- metadata +5 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 13e61f293aa7bde2e5ac7b0db815fbe5c7a40751
|
4
|
+
data.tar.gz: f01468bc2b2ec632e392086fe36c068c0eb412f4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f1c315d604b47905681f2a811fc2540730c5a0607159409e6c8c84c05a838dd8385267e011ba30ba1f1369fba15a8917f4cc798738f699d7de3733abab32f9d5
|
7
|
+
data.tar.gz: 12ccd0e704f4a91e51be8b126b8d1f2657924835a9c5a2baef20d308b9168e1b1ca69acb6f7236adf87ad4e703111dd719872a46c1c38d66094fb9a048c2f20f
|
data/atli.gemspec
CHANGED
data/lib/thor.rb
CHANGED
@@ -2,6 +2,7 @@ require "set"
|
|
2
2
|
require 'nrser'
|
3
3
|
require 'semantic_logger'
|
4
4
|
require "thor/base"
|
5
|
+
require 'thor/example'
|
5
6
|
|
6
7
|
|
7
8
|
class Thor
|
@@ -198,7 +199,11 @@ class Thor
|
|
198
199
|
shell.say "Usage:"
|
199
200
|
shell.say " #{banner(command, nil, subcommand)}"
|
200
201
|
shell.say
|
201
|
-
|
202
|
+
|
203
|
+
class_options_help \
|
204
|
+
shell,
|
205
|
+
command.options.values.group_by { |option| option.group }
|
206
|
+
|
202
207
|
if command.long_description
|
203
208
|
shell.say "Description:"
|
204
209
|
shell.print_wrapped(command.long_description, :indent => 2)
|
@@ -206,6 +211,24 @@ class Thor
|
|
206
211
|
shell.say command.description
|
207
212
|
end
|
208
213
|
|
214
|
+
unless command.examples.empty?
|
215
|
+
shell.say "\n"
|
216
|
+
shell.say "Examples:"
|
217
|
+
shell.say "\n"
|
218
|
+
|
219
|
+
command.examples.each_with_index do |example, index|
|
220
|
+
lines = example.lines
|
221
|
+
|
222
|
+
shell.say "1. #{ lines[0] }"
|
223
|
+
|
224
|
+
lines[1..-1].each do |line|
|
225
|
+
shell.say " #{ line }"
|
226
|
+
end
|
227
|
+
end
|
228
|
+
|
229
|
+
shell.say "\n"
|
230
|
+
end
|
231
|
+
|
209
232
|
nil
|
210
233
|
end
|
211
234
|
alias_method :task_help, :command_help
|
@@ -435,10 +458,26 @@ class Thor
|
|
435
458
|
def find_shared_method_options *names, groups: nil
|
436
459
|
groups_set = Set[*groups]
|
437
460
|
|
438
|
-
shared_method_options.
|
439
|
-
|
440
|
-
|
441
|
-
|
461
|
+
shared_method_options.each_with_object( {} ) do |(name, option), results|
|
462
|
+
match = {}
|
463
|
+
|
464
|
+
if names.include? name
|
465
|
+
match[:name] = true
|
466
|
+
end
|
467
|
+
|
468
|
+
match_groups = option.groups & groups_set
|
469
|
+
|
470
|
+
unless match_groups.empty?
|
471
|
+
match[:groups] = match_groups
|
472
|
+
end
|
473
|
+
|
474
|
+
unless match.empty?
|
475
|
+
results[name] = {
|
476
|
+
option: option,
|
477
|
+
match: match,
|
478
|
+
}
|
479
|
+
end
|
480
|
+
end
|
442
481
|
end
|
443
482
|
alias_method :find_shared_options, :find_shared_method_options
|
444
483
|
|
@@ -553,8 +592,8 @@ class Thor
|
|
553
592
|
#
|
554
593
|
def include_method_options *names, groups: nil
|
555
594
|
find_shared_method_options( *names, groups: groups ).
|
556
|
-
each do |name,
|
557
|
-
method_options[name] =
|
595
|
+
each do |name, result|
|
596
|
+
method_options[name] = Thor::IncludedOption.new **result
|
558
597
|
end
|
559
598
|
end
|
560
599
|
|
@@ -650,16 +689,20 @@ class Thor
|
|
650
689
|
@desc ||= nil
|
651
690
|
@long_desc ||= nil
|
652
691
|
@hide ||= nil
|
692
|
+
|
693
|
+
examples = @examples || []
|
694
|
+
@examples = []
|
653
695
|
|
654
696
|
if @usage && @desc
|
655
697
|
base_class = @hide ? Thor::HiddenCommand : Thor::Command
|
656
|
-
commands[meth] = base_class.new
|
657
|
-
meth,
|
658
|
-
@desc,
|
659
|
-
@long_desc,
|
660
|
-
@usage,
|
661
|
-
|
662
|
-
|
698
|
+
commands[meth] = base_class.new \
|
699
|
+
name: meth,
|
700
|
+
description: @desc,
|
701
|
+
long_description: @long_desc,
|
702
|
+
usage: @usage,
|
703
|
+
examples: examples,
|
704
|
+
options: method_options
|
705
|
+
|
663
706
|
@usage, @desc, @long_desc, @method_options, @hide = nil
|
664
707
|
true
|
665
708
|
elsif all_commands[meth] || meth == "method_missing"
|
@@ -17,10 +17,11 @@ require 'nrser/refinements/types'
|
|
17
17
|
using NRSER::Types
|
18
18
|
|
19
19
|
|
20
|
-
#
|
20
|
+
# Namespace
|
21
21
|
# =======================================================================
|
22
22
|
|
23
|
-
|
23
|
+
class Thor
|
24
|
+
module Base
|
24
25
|
|
25
26
|
|
26
27
|
# Definitions
|
@@ -29,7 +30,7 @@ module Thor::Base; end
|
|
29
30
|
# Methods that are mixed in as module/class/singleton methods to modules
|
30
31
|
# that include {Thor::Base}.
|
31
32
|
#
|
32
|
-
module
|
33
|
+
module ClassMethods
|
33
34
|
|
34
35
|
# Mixins
|
35
36
|
# ==========================================================================
|
@@ -536,7 +537,7 @@ module Thor::Base::ClassMethods
|
|
536
537
|
#
|
537
538
|
# @return [nil]
|
538
539
|
#
|
539
|
-
def class_options_help
|
540
|
+
def class_options_help shell, groups = {}
|
540
541
|
# Group options by group
|
541
542
|
class_options.each do |_, value|
|
542
543
|
groups[value.group] ||= []
|
@@ -545,7 +546,10 @@ module Thor::Base::ClassMethods
|
|
545
546
|
|
546
547
|
# Deal with default group
|
547
548
|
global_options = groups.delete(nil) || []
|
548
|
-
print_options
|
549
|
+
print_options \
|
550
|
+
shell,
|
551
|
+
global_options,
|
552
|
+
(groups.empty? ? nil : 'General')
|
549
553
|
|
550
554
|
# Print all others
|
551
555
|
groups.each do |group_name, options|
|
@@ -731,4 +735,11 @@ module Thor::Base::ClassMethods
|
|
731
735
|
|
732
736
|
public # end Protected Mixin Methods ***************************************
|
733
737
|
|
734
|
-
end # module
|
738
|
+
end # module ClassMethods
|
739
|
+
|
740
|
+
|
741
|
+
# /Namespace
|
742
|
+
# ========================================================================
|
743
|
+
|
744
|
+
end # module Base
|
745
|
+
end # class Thor
|
data/lib/thor/command.rb
CHANGED
@@ -5,14 +5,26 @@ class Thor
|
|
5
5
|
:description,
|
6
6
|
:long_description,
|
7
7
|
:usage,
|
8
|
+
:examples,
|
8
9
|
:options,
|
9
10
|
:ancestor_name )
|
10
11
|
include SemanticLogger::Loggable
|
11
12
|
|
12
13
|
FILE_REGEXP = /^#{Regexp.escape(File.dirname(__FILE__))}/
|
13
14
|
|
14
|
-
def initialize
|
15
|
-
|
15
|
+
def initialize name:,
|
16
|
+
description: nil,
|
17
|
+
long_description: nil,
|
18
|
+
usage: nil,
|
19
|
+
examples: [],
|
20
|
+
options: nil
|
21
|
+
super \
|
22
|
+
name.to_s,
|
23
|
+
description,
|
24
|
+
long_description,
|
25
|
+
usage,
|
26
|
+
examples,
|
27
|
+
options || {}
|
16
28
|
end
|
17
29
|
|
18
30
|
def initialize_copy(other) #:nodoc:
|
@@ -301,11 +313,11 @@ class Thor
|
|
301
313
|
# A dynamic command that handles method missing scenarios.
|
302
314
|
class DynamicCommand < Command
|
303
315
|
def initialize(name, options = nil)
|
304
|
-
super( name.to_s,
|
305
|
-
"A dynamically-generated command",
|
306
|
-
name.to_s,
|
307
|
-
name.to_s,
|
308
|
-
options )
|
316
|
+
super( name: name.to_s,
|
317
|
+
description: "A dynamically-generated command",
|
318
|
+
long_description: name.to_s, # why?!
|
319
|
+
usage: name.to_s,
|
320
|
+
options: options )
|
309
321
|
end
|
310
322
|
|
311
323
|
def run(instance, args = [])
|
data/lib/thor/example.rb
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
|
5
|
+
# Definitions
|
6
|
+
# =======================================================================
|
7
|
+
|
8
|
+
class Thor
|
9
|
+
|
10
|
+
# Add an example to the next defined command.
|
11
|
+
#
|
12
|
+
# @param [String] example
|
13
|
+
# The example text.
|
14
|
+
#
|
15
|
+
# @return [nil]
|
16
|
+
#
|
17
|
+
def self.example example
|
18
|
+
@examples ||= []
|
19
|
+
@examples << example
|
20
|
+
nil
|
21
|
+
end # #example
|
22
|
+
|
23
|
+
end # class Thor
|
data/lib/thor/group.rb
CHANGED
@@ -251,7 +251,7 @@ class Thor::Group
|
|
251
251
|
end
|
252
252
|
|
253
253
|
def create_command(meth) #:nodoc:
|
254
|
-
commands[meth.to_s] = Thor::Command.new
|
254
|
+
commands[meth.to_s] = Thor::Command.new name: meth
|
255
255
|
true
|
256
256
|
end
|
257
257
|
alias_method :create_task, :create_command
|
data/lib/thor/parser/option.rb
CHANGED
@@ -1,3 +1,6 @@
|
|
1
|
+
# Need {String#titleize}
|
2
|
+
require 'active_support/core_ext/string/inflections'
|
3
|
+
|
1
4
|
class Thor
|
2
5
|
class Option < Argument #:nodoc:
|
3
6
|
attr_reader :aliases, :group, :lazy_default, :hide
|
@@ -9,7 +12,7 @@ class Thor
|
|
9
12
|
options[:required] = false unless options.key?(:required)
|
10
13
|
super
|
11
14
|
@lazy_default = options[:lazy_default]
|
12
|
-
@group = options[:group].to_s.
|
15
|
+
@group = options[:group].to_s.titleize if options[:group]
|
13
16
|
@aliases = Array(options[:aliases])
|
14
17
|
@hide = options[:hide]
|
15
18
|
end
|
@@ -1,5 +1,28 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
# Requirements
|
5
|
+
# ========================================================================
|
6
|
+
|
7
|
+
# Stdlib
|
8
|
+
# ------------------------------------------------------------------------
|
1
9
|
require 'set'
|
2
10
|
|
11
|
+
# Deps
|
12
|
+
# ------------------------------------------------------------------------
|
13
|
+
|
14
|
+
# Need {String#titleize}
|
15
|
+
require 'active_support/core_ext/string/inflections'
|
16
|
+
|
17
|
+
# Need {NRSER::LazyAttr}
|
18
|
+
require 'nrser/meta/lazy_attr'
|
19
|
+
|
20
|
+
# Project / Package
|
21
|
+
# ------------------------------------------------------------------------
|
22
|
+
|
23
|
+
require_relative './option'
|
24
|
+
|
25
|
+
|
3
26
|
class Thor
|
4
27
|
# A {Thor::Option} that has an additional {#groups} attribute storing a
|
5
28
|
# set of group symbols that the option is a part of.
|
@@ -15,9 +38,80 @@ class Thor
|
|
15
38
|
#
|
16
39
|
#
|
17
40
|
def initialize name, **options
|
41
|
+
@groups = Set.new [*options[:groups]].map( &:to_sym )
|
42
|
+
|
43
|
+
# # If
|
44
|
+
# if options[:group].nil? && groups.count == 1
|
45
|
+
# options[:group] = groups.first.to_s.titleize
|
46
|
+
# end
|
47
|
+
|
18
48
|
super name, options
|
49
|
+
end
|
50
|
+
|
51
|
+
|
52
|
+
def initialize_options
|
53
|
+
{
|
54
|
+
# {Thor::Argument} options
|
55
|
+
desc: :@description,
|
56
|
+
required: :@required,
|
57
|
+
type: :@type,
|
58
|
+
default: :@default,
|
59
|
+
banner: :@banner,
|
60
|
+
eunm: :@enum,
|
61
|
+
|
62
|
+
# {Thor::Option} options
|
63
|
+
check_default_type: :@check_default_type,
|
64
|
+
lazy_default: :@lazy_default,
|
65
|
+
group: :@group,
|
66
|
+
aliases: :@aliases,
|
67
|
+
hide: :@hide,
|
68
|
+
|
69
|
+
# {Thor::SharedOption} options
|
70
|
+
groups: :@groups,
|
71
|
+
}.transform_values &method( :instance_variable_get )
|
72
|
+
end
|
73
|
+
|
74
|
+
end
|
75
|
+
|
76
|
+
|
77
|
+
class IncludedOption < SharedOption
|
78
|
+
|
79
|
+
# The match that resulted in this option getting included.
|
80
|
+
#
|
81
|
+
# @return [Hash]
|
82
|
+
#
|
83
|
+
attr_reader :match
|
84
|
+
|
85
|
+
|
86
|
+
def initialize option:, match:
|
87
|
+
super option.name, **option.initialize_options
|
88
|
+
@match = match
|
89
|
+
end
|
90
|
+
|
91
|
+
|
92
|
+
+NRSER::LazyAttr
|
93
|
+
def group
|
94
|
+
case @group
|
95
|
+
when false
|
96
|
+
nil
|
97
|
+
when String
|
98
|
+
@group
|
99
|
+
when nil
|
100
|
+
default_group
|
101
|
+
else
|
102
|
+
logger.warn "Bad {Option#group}: #{ @group.inspect }",
|
103
|
+
option: self
|
104
|
+
nil
|
105
|
+
end
|
106
|
+
end
|
107
|
+
|
108
|
+
|
109
|
+
+NRSER::LazyAttr
|
110
|
+
def default_group
|
111
|
+
return nil unless match[:groups]
|
19
112
|
|
20
|
-
|
113
|
+
match[:groups].map { |group| group.to_s.titleize }.join ' / '
|
21
114
|
end
|
115
|
+
|
22
116
|
end
|
23
117
|
end
|
data/lib/thor/version.rb
CHANGED
@@ -14,7 +14,7 @@ class Thor
|
|
14
14
|
#
|
15
15
|
# @return [String]
|
16
16
|
#
|
17
|
-
VERSION = '0.1.
|
17
|
+
VERSION = '0.1.8'
|
18
18
|
|
19
19
|
|
20
20
|
# The version of Thor that Atli is up to date with.
|
@@ -27,5 +27,5 @@ class Thor
|
|
27
27
|
#
|
28
28
|
# @return [String]
|
29
29
|
#
|
30
|
-
THOR_VERSION = '0.1.
|
30
|
+
THOR_VERSION = '0.1.8'
|
31
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.8
|
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-05-
|
13
|
+
date: 2018-05-25 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: bundler
|
@@ -32,14 +32,14 @@ dependencies:
|
|
32
32
|
requirements:
|
33
33
|
- - "~>"
|
34
34
|
- !ruby/object:Gem::Version
|
35
|
-
version: 0.3.
|
35
|
+
version: 0.3.5
|
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.3.
|
42
|
+
version: 0.3.5
|
43
43
|
- !ruby/object:Gem::Dependency
|
44
44
|
name: yard
|
45
45
|
requirement: !ruby/object:Gem::Requirement
|
@@ -98,6 +98,7 @@ files:
|
|
98
98
|
- lib/thor/core_ext/io_binary_read.rb
|
99
99
|
- lib/thor/core_ext/ordered_hash.rb
|
100
100
|
- lib/thor/error.rb
|
101
|
+
- lib/thor/example.rb
|
101
102
|
- lib/thor/execution.rb
|
102
103
|
- lib/thor/group.rb
|
103
104
|
- lib/thor/invocation.rb
|