thor_enhance 0.5.0 → 0.5.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +3 -0
- data/Gemfile.lock +1 -1
- data/docs/autogenerate/Readme.md +21 -7
- data/generated_readme/commands/Readme.md +34 -0
- data/generated_readme/commands/autobots.md +69 -0
- data/generated_readme/commands/sample.md +84 -0
- data/generated_readme/commands/sub/Readme.md +37 -0
- data/generated_readme/commands/sub/innard.md +46 -0
- data/lib/thor_enhance/autogenerate/command.rb +107 -13
- data/lib/thor_enhance/autogenerate/configuration.rb +2 -2
- data/lib/thor_enhance/autogenerate/templates/aggregate_options.rb.erb +1 -2
- data/lib/thor_enhance/autogenerate/templates/class_options.rb.erb +7 -0
- data/lib/thor_enhance/autogenerate/templates/command.rb.erb +7 -2
- data/lib/thor_enhance/autogenerate/templates/footer.rb.erb +1 -2
- data/lib/thor_enhance/autogenerate.rb +19 -10
- data/lib/thor_enhance/command_method.rb +8 -2
- data/lib/thor_enhance/sample.rb +19 -1
- data/lib/thor_enhance/version.rb +1 -1
- metadata +8 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c35515a53e679dc8e52c1c615dc19c4c24214280fb75e1af513e257d831cf457
|
4
|
+
data.tar.gz: 68a91514f8b7dde6df20913f4ec8fdfce263c1a36e8700da80569d79fd3480d3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7cd3bda1a32242ad57a0f55f956d5e9780a1f5c22f9866718e1fc12944c40792f9aa89b2ae6ba885f7ffdb269890fa66056f2b8fac40c15bba64ef1a85288a9f
|
7
|
+
data.tar.gz: b30889ca39f92ef0e9851dd3c0b37930b472dd1db7a001bb1778a034c64904f216f5c3cc16ed71d590f96fd515052441eb649aa2856638ad29f6e2f4656f6679
|
data/CHANGELOG.md
CHANGED
@@ -6,6 +6,9 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
|
|
6
6
|
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
7
7
|
|
8
8
|
|
9
|
+
## [0.5.0]
|
10
|
+
- Autogenerate Readme based on command options and method options
|
11
|
+
|
9
12
|
## [0.4.0]
|
10
13
|
- Enable Enhancements on a klass basis
|
11
14
|
- Add Enable/disable blocks for enhancements to allow for onboarding new tasks
|
data/Gemfile.lock
CHANGED
data/docs/autogenerate/Readme.md
CHANGED
@@ -14,10 +14,20 @@ ThorEnhance.configure do |c|
|
|
14
14
|
end
|
15
15
|
```
|
16
16
|
|
17
|
+
### Pro Tip
|
18
|
+
The Readme's are generated based on the code. We suggest to enable the following in your `.gitattributes`
|
19
|
+
```
|
20
|
+
# .gitattributes
|
21
|
+
...
|
22
|
+
generated_readme/** linguist-generated=true
|
23
|
+
...
|
24
|
+
```
|
25
|
+
`generated_readme/**` is the default location for ThorEnhance Readmes. The code above will tell github to ignore these files for code review. This will help in the process to ensure that only the code gets changes rather than the generated readme.
|
26
|
+
|
17
27
|
## Default capabilities
|
18
28
|
|
19
29
|
### Example Command Option
|
20
|
-
When `readme_enhance` is enabled, by default the `example`
|
30
|
+
When `readme_enhance` is enabled, by default the `example` command option is available on for every command.
|
21
31
|
|
22
32
|
```ruby
|
23
33
|
desc "sample", "This Sample command"
|
@@ -27,13 +37,13 @@ method_option :boolean, type: :boolean, desc: "Just a normal boolean"
|
|
27
37
|
def sample;end;
|
28
38
|
```
|
29
39
|
|
30
|
-
The example command
|
40
|
+
The example command signature expects:
|
31
41
|
```ruby
|
32
42
|
# remove basename and any submodules from command execution
|
33
43
|
example "command execution", desc: "Description of what the command does"
|
34
44
|
```
|
35
45
|
|
36
|
-
By default, `example` is not required for every command. To make example required for every command, modify the configuration to
|
46
|
+
By default, `example` is not required for every command. To make `example` required for every command, modify the configuration to:
|
37
47
|
```ruby
|
38
48
|
ThorEnhance.configure do |c|
|
39
49
|
c.readme_enhance! do |r|
|
@@ -43,7 +53,7 @@ end
|
|
43
53
|
```
|
44
54
|
|
45
55
|
### Header Command Option
|
46
|
-
When `readme_enhance` is enabled, by default
|
56
|
+
When `readme_enhance` is enabled, by default the `header` option is available on every command.
|
47
57
|
|
48
58
|
```ruby
|
49
59
|
desc "sample", "This Sample command"
|
@@ -61,11 +71,11 @@ This optional command option gets used for the Readme title. Otherwise, the meth
|
|
61
71
|
|
62
72
|
```ruby
|
63
73
|
desc "sample", "This Sample command"
|
64
|
-
title ""
|
74
|
+
title "Useless Sample command"
|
65
75
|
def sample;end;
|
66
76
|
```
|
67
77
|
|
68
|
-
By default, `title` is not required for every command. To make
|
78
|
+
By default, `title` is not required for every command. To make `title` required for every command, modify the configuration to
|
69
79
|
```ruby
|
70
80
|
ThorEnhance.configure do |c|
|
71
81
|
c.readme_enhance! do |r|
|
@@ -149,4 +159,8 @@ is_this_important "Yes this is imporant. It even has a custom tag", tag: 1
|
|
149
159
|
def sample;end;
|
150
160
|
```
|
151
161
|
|
152
|
-
Take special
|
162
|
+
Take special note of the `tag` option on the custom header. By default, header will output as an `<h2>` header tag. You can optionally change the header tag value to a numeric: `1|2|3|4` or you can use a header string: `h1|h2|h3|h4`
|
163
|
+
|
164
|
+
# Example:
|
165
|
+
|
166
|
+
ThorEnanhace has sample thor tasks defined in [ThorEnhance::Sample](/lib/thor_enhance/sample.rb). View the [AutoGenerated Commands here](/generated_readme/commands)
|
@@ -0,0 +1,34 @@
|
|
1
|
+
## [Subcommand for sample class](sub/Readme.md)
|
2
|
+
Thor sub command validation for thor enhance
|
3
|
+
|
4
|
+
```bash
|
5
|
+
# Help Command
|
6
|
+
thor_enhance sub <options>
|
7
|
+
|
8
|
+
|
9
|
+
```
|
10
|
+
|
11
|
+
## [sample](sample.md)
|
12
|
+
This Sample command does a lot of nothing
|
13
|
+
|
14
|
+
```bash
|
15
|
+
# Help Command
|
16
|
+
thor_enhance sample <options>
|
17
|
+
|
18
|
+
thor_enhance sample
|
19
|
+
thor_enhance sample --boolean
|
20
|
+
```
|
21
|
+
|
22
|
+
## [autobots](autobots.md)
|
23
|
+
Command outputs what Optimus prime is thniking
|
24
|
+
|
25
|
+
```bash
|
26
|
+
# Help Command
|
27
|
+
thor_enhance autobots <options>
|
28
|
+
|
29
|
+
thor_enhance sample
|
30
|
+
thor_enhance sample --boolean
|
31
|
+
```
|
32
|
+
|
33
|
+
> AutoGenerateted by [ThorEnhance](https://github.com/matt-taylor/thor_enhance) <br>
|
34
|
+
> Regenerate readme files with: thor_enhance thor_enhance_autogenerate --apply
|
@@ -0,0 +1,69 @@
|
|
1
|
+
# Autobots
|
2
|
+
|
3
|
+
Source code for this command can be found at: [ThorEnhance::Sample#autobots](/lib/thor_enhance/sample.rb#L51)
|
4
|
+
|
5
|
+
## Description
|
6
|
+
Command outputs what Optimus prime is thniking
|
7
|
+
|
8
|
+
```bash
|
9
|
+
# Base command for `autobots`
|
10
|
+
thor_enhance autobots <options>
|
11
|
+
```
|
12
|
+
|
13
|
+
## When Should I Use This?
|
14
|
+
|
15
|
+
Do you ever feel angry about how powerful the Decepticons are compared to the Autobots? It seems unfair.
|
16
|
+
Trust...The autobots agree.
|
17
|
+
|
18
|
+
|
19
|
+
|
20
|
+
|
21
|
+
---
|
22
|
+
|
23
|
+
## Examples
|
24
|
+
|
25
|
+
```bash
|
26
|
+
# yo yo ma
|
27
|
+
thor_enhance sample
|
28
|
+
```
|
29
|
+
|
30
|
+
```bash
|
31
|
+
# yo yo ma
|
32
|
+
thor_enhance sample --boolean
|
33
|
+
```
|
34
|
+
|
35
|
+
|
36
|
+
|
37
|
+
---
|
38
|
+
|
39
|
+
|
40
|
+
## Method Options
|
41
|
+
|
42
|
+
|
43
|
+
|
44
|
+
<details open>
|
45
|
+
<summary> <h3> Important options </h3> </summary>
|
46
|
+
|
47
|
+
```bash
|
48
|
+
# What: Enable bumblee bee flag
|
49
|
+
# Type: boolean
|
50
|
+
# Required: false
|
51
|
+
--bumble | -b | --no-bumble
|
52
|
+
|
53
|
+
```
|
54
|
+
|
55
|
+
</details>
|
56
|
+
|
57
|
+
|
58
|
+
|
59
|
+
|
60
|
+
|
61
|
+
|
62
|
+
|
63
|
+
|
64
|
+
|
65
|
+
---
|
66
|
+
|
67
|
+
> AutoGenerateted by [ThorEnhance](https://github.com/matt-taylor/thor_enhance) <br>
|
68
|
+
> Regenerate readme files with: thor_enhance thor_enhance_autogenerate --apply
|
69
|
+
|
@@ -0,0 +1,84 @@
|
|
1
|
+
# Sample
|
2
|
+
|
3
|
+
Source code for this command can be found at: [ThorEnhance::Sample#sample](/lib/thor_enhance/sample.rb#L39)
|
4
|
+
|
5
|
+
## Description
|
6
|
+
This Sample command does a lot of nothing
|
7
|
+
|
8
|
+
```bash
|
9
|
+
# Base command for `sample`
|
10
|
+
thor_enhance sample <options>
|
11
|
+
```
|
12
|
+
|
13
|
+
#### How Does This Help
|
14
|
+
|
15
|
+
Honestly, this does not help at all
|
16
|
+
|
17
|
+
# How Does This Help
|
18
|
+
|
19
|
+
But its cool because it is a repatable command
|
20
|
+
|
21
|
+
## When Should I Use This?
|
22
|
+
|
23
|
+
Have you ever wanted your code to be useless?
|
24
|
+
Well, this command does absolutely nothing.
|
25
|
+
This output is to say that this command does absolutely nothing
|
26
|
+
|
27
|
+
|
28
|
+
|
29
|
+
|
30
|
+
---
|
31
|
+
|
32
|
+
## Examples
|
33
|
+
|
34
|
+
```bash
|
35
|
+
# yo yo ma
|
36
|
+
thor_enhance sample
|
37
|
+
```
|
38
|
+
|
39
|
+
```bash
|
40
|
+
# yo yo ma
|
41
|
+
thor_enhance sample --boolean
|
42
|
+
```
|
43
|
+
|
44
|
+
|
45
|
+
|
46
|
+
---
|
47
|
+
|
48
|
+
|
49
|
+
## Method Options
|
50
|
+
|
51
|
+
|
52
|
+
|
53
|
+
<details open>
|
54
|
+
<summary> <h3> Important options </h3> </summary>
|
55
|
+
|
56
|
+
```bash
|
57
|
+
# What: Just a normal boolean
|
58
|
+
# Type: boolean
|
59
|
+
# Required: false
|
60
|
+
--boolean | -b | --no-boolean
|
61
|
+
|
62
|
+
# What: How many times to output text
|
63
|
+
# Type: numeric
|
64
|
+
# Required: false
|
65
|
+
# Allowed Inputs: [1, 2, 3, 4, 5]
|
66
|
+
--count
|
67
|
+
|
68
|
+
```
|
69
|
+
|
70
|
+
</details>
|
71
|
+
|
72
|
+
|
73
|
+
|
74
|
+
|
75
|
+
|
76
|
+
|
77
|
+
|
78
|
+
|
79
|
+
|
80
|
+
---
|
81
|
+
|
82
|
+
> AutoGenerateted by [ThorEnhance](https://github.com/matt-taylor/thor_enhance) <br>
|
83
|
+
> Regenerate readme files with: thor_enhance thor_enhance_autogenerate --apply
|
84
|
+
|
@@ -0,0 +1,37 @@
|
|
1
|
+
# Subcommand For Sample Class
|
2
|
+
|
3
|
+
|
4
|
+
|
5
|
+
## Description
|
6
|
+
Thor sub command validation for thor enhance
|
7
|
+
|
8
|
+
```bash
|
9
|
+
# Base command for `sub`
|
10
|
+
thor_enhance sub <options>
|
11
|
+
```
|
12
|
+
|
13
|
+
|
14
|
+
|
15
|
+
|
16
|
+
|
17
|
+
|
18
|
+
|
19
|
+
### [Innard command for Subtask Subcommand](innard.md)
|
20
|
+
|
21
|
+
|
22
|
+
Wow, This longer description will take precedence over the desc above. This is what will be shown in the readme autogenerated page. Try me out!
|
23
|
+
|
24
|
+
```bash
|
25
|
+
thor_enhance sub innard <options>
|
26
|
+
thor_enhance sub innard --count 5
|
27
|
+
thor_enhance sub innard --count 35
|
28
|
+
```
|
29
|
+
|
30
|
+
|
31
|
+
|
32
|
+
|
33
|
+
---
|
34
|
+
|
35
|
+
> AutoGenerateted by [ThorEnhance](https://github.com/matt-taylor/thor_enhance) <br>
|
36
|
+
> Regenerate readme files with: thor_enhance thor_enhance_autogenerate --apply
|
37
|
+
|
@@ -0,0 +1,46 @@
|
|
1
|
+
# Innard Command For Subtask Subcommand
|
2
|
+
|
3
|
+
Source code for this command can be found at: [ThorEnhance::Sample::SubCommand#innard](/lib/thor_enhance/sample.rb#L20)
|
4
|
+
|
5
|
+
## Description
|
6
|
+
Wow, This longer description will take precedence over the desc above. This is what will be shown in the readme autogenerated page. Try me out!
|
7
|
+
|
8
|
+
```bash
|
9
|
+
# Base command for `innard`
|
10
|
+
thor_enhance sub innard <options>
|
11
|
+
```
|
12
|
+
|
13
|
+
## When Should I Use This?
|
14
|
+
|
15
|
+
Use sub command task to validate that subocommands work as expected
|
16
|
+
|
17
|
+
|
18
|
+
## Deprecation warning
|
19
|
+
This command will get deprecated in the next major version
|
20
|
+
|
21
|
+
|
22
|
+
---
|
23
|
+
|
24
|
+
## Examples
|
25
|
+
|
26
|
+
```bash
|
27
|
+
# Innard sub command with a count of 5
|
28
|
+
thor_enhance sub innard --count 5
|
29
|
+
```
|
30
|
+
|
31
|
+
```bash
|
32
|
+
# Innard sub command with a count of 35
|
33
|
+
thor_enhance sub innard --count 35
|
34
|
+
```
|
35
|
+
|
36
|
+
|
37
|
+
|
38
|
+
|
39
|
+
|
40
|
+
|
41
|
+
|
42
|
+
---
|
43
|
+
|
44
|
+
> AutoGenerateted by [ThorEnhance](https://github.com/matt-taylor/thor_enhance) <br>
|
45
|
+
> Regenerate readme files with: thor_enhance thor_enhance_autogenerate --apply
|
46
|
+
|
@@ -13,17 +13,21 @@ module ThorEnhance
|
|
13
13
|
AGGREGATE_OPTIONS_ERB = "#{File.dirname(__FILE__)}/templates/aggregate_options.rb.erb"
|
14
14
|
AGGREGATE_OPTIONS_TEMPLATE = ERB.new(File.read(AGGREGATE_OPTIONS_ERB))
|
15
15
|
|
16
|
+
CLASS_OPTIONS_ERB = "#{File.dirname(__FILE__)}/templates/class_options.rb.erb"
|
17
|
+
CLASS_OPTIONS_TEMPLATE = ERB.new(File.read(CLASS_OPTIONS_ERB))
|
18
|
+
|
16
19
|
FOOTER_ERB = "#{File.dirname(__FILE__)}/templates/footer.rb.erb"
|
17
20
|
FOOTER_TEMPLATE = ERB.new(File.read(FOOTER_ERB))
|
18
21
|
|
19
|
-
attr_reader :leaf, :name, :basename, :child_commands, :parent
|
22
|
+
attr_reader :root, :leaf, :name, :basename, :child_commands, :parent
|
20
23
|
|
21
|
-
def initialize(leaf:, name:, basename:, parent: nil)
|
24
|
+
def initialize(leaf:, name:, basename:, root: , parent: nil)
|
22
25
|
@leaf = leaf
|
23
26
|
@name = name
|
24
27
|
@basename = basename
|
25
28
|
@child_commands = []
|
26
29
|
@parent = parent
|
30
|
+
@root = root
|
27
31
|
initialize_children!
|
28
32
|
end
|
29
33
|
|
@@ -31,42 +35,68 @@ module ThorEnhance
|
|
31
35
|
return unless children?
|
32
36
|
|
33
37
|
@child_commands = leaf.children.map do |name, child_leaf|
|
34
|
-
self.class.new(leaf: child_leaf, name: name, basename: basename, parent: self)
|
38
|
+
self.class.new(root: root, leaf: child_leaf, name: name, basename: basename, parent: self)
|
35
39
|
end
|
36
40
|
end
|
37
41
|
|
38
42
|
def method_options
|
39
43
|
@method_options ||= begin
|
40
44
|
_options = options.map { |name, option| Option.new(name: name, option: option) }
|
45
|
+
_options = _options.group_by { _1.readme_type }
|
46
|
+
unless _options.empty?
|
47
|
+
_options.delete(ThorEnhance.configuration.autogenerated_config.readme_skip_key)
|
48
|
+
end
|
41
49
|
|
42
|
-
_options
|
50
|
+
_options
|
43
51
|
end
|
44
52
|
end
|
45
53
|
|
46
54
|
def command_erb
|
47
55
|
@command_erb ||= begin
|
48
56
|
params = {
|
57
|
+
all_bases: all_bases,
|
49
58
|
basename_string: basename_string,
|
50
59
|
children_descriptors: children_descriptors,
|
60
|
+
class_options_erb: class_options_erb,
|
51
61
|
command: command,
|
62
|
+
command_source: command_source,
|
52
63
|
custom_headers: custom_headers,
|
64
|
+
default_command: default_command,
|
65
|
+
default_command_string: default_command_string,
|
53
66
|
description: description,
|
54
67
|
drawn_out_examples: drawn_out_examples,
|
55
68
|
footer_erb: footer_erb,
|
56
69
|
headers: headers,
|
57
70
|
method_options_erb: method_options_erb,
|
58
71
|
parent_basename_string: parent_basename_string,
|
72
|
+
preferred_basename_string: preferred_basename_string,
|
59
73
|
title: title,
|
60
74
|
}
|
61
75
|
COMMAND_TEMPLATE.result_with_hash(params)
|
62
76
|
end
|
63
77
|
end
|
64
78
|
|
79
|
+
def command_source
|
80
|
+
# if children exists, it is a subcommand
|
81
|
+
# source location for a command does not accurately find the correct source
|
82
|
+
# Return nil and skip output
|
83
|
+
return nil if children?
|
84
|
+
|
85
|
+
file, line = leaf.base.instance_method(name).source_location
|
86
|
+
# This value returns the length of the root up to generated_readme
|
87
|
+
# This allows us to understand how many directories to remove from the local `source_location`
|
88
|
+
remove_length = root.split("/")[0..-2].length
|
89
|
+
|
90
|
+
# this will return the relative location of the command source line
|
91
|
+
relative_source = file.split("/")[remove_length..-1]
|
92
|
+
relative_link = "/#{relative_source.join("/")}#L#{line}"
|
93
|
+
"Source code for this command can be found at: [#{leaf.base.name}##{name}](#{relative_link})"
|
94
|
+
end
|
95
|
+
|
65
96
|
def footer_erb
|
66
97
|
@footer_erb ||= begin
|
67
|
-
regenerate_single_command = "#{parent_basename_string} thor_enhance_autogenerate --command #{command.usage} --apply"
|
68
98
|
regenerate_thor_command = "#{basename} thor_enhance_autogenerate --apply"
|
69
|
-
FOOTER_TEMPLATE.result_with_hash({
|
99
|
+
FOOTER_TEMPLATE.result_with_hash({ regenerate_thor_command: regenerate_thor_command })
|
70
100
|
end
|
71
101
|
end
|
72
102
|
|
@@ -92,8 +122,36 @@ module ThorEnhance
|
|
92
122
|
@method_options_erb ||= AGGREGATE_OPTIONS_TEMPLATE.result_with_hash({ method_options: method_options })
|
93
123
|
end
|
94
124
|
|
125
|
+
def class_options_erb
|
126
|
+
@class_options_erb ||= begin
|
127
|
+
if class_options.empty?
|
128
|
+
nil
|
129
|
+
else
|
130
|
+
CLASS_OPTIONS_TEMPLATE.result_with_hash({ method_options_text_array: class_options.map(&:template_text) })
|
131
|
+
end
|
132
|
+
end
|
133
|
+
end
|
134
|
+
|
135
|
+
def class_options
|
136
|
+
leaf.base.class_options.map do |name, class_option|
|
137
|
+
class_option.hide ? nil : Option.new(name: name, option: class_option)
|
138
|
+
end.compact
|
139
|
+
end
|
140
|
+
|
95
141
|
def basename_string
|
96
|
-
|
142
|
+
"#{parent_basename_string} #{command.usage}"
|
143
|
+
end
|
144
|
+
|
145
|
+
def default_command_string
|
146
|
+
parent_basename_string if name == default_command
|
147
|
+
end
|
148
|
+
|
149
|
+
def all_bases
|
150
|
+
[default_command_string, basename_string].compact
|
151
|
+
end
|
152
|
+
|
153
|
+
def preferred_basename_string
|
154
|
+
default_command_string || basename_string
|
97
155
|
end
|
98
156
|
|
99
157
|
def parent_basename_string
|
@@ -158,13 +216,23 @@ module ThorEnhance
|
|
158
216
|
end
|
159
217
|
|
160
218
|
def title
|
161
|
-
command.title || command.usage
|
219
|
+
command.title&.dig(:input) || command.usage
|
162
220
|
end
|
163
221
|
|
164
222
|
def self_for_root
|
165
223
|
params_for_child(self)
|
166
224
|
end
|
167
225
|
|
226
|
+
def default_command
|
227
|
+
if children?
|
228
|
+
leaf.base.subcommand_classes[name].default_task
|
229
|
+
else
|
230
|
+
leaf.base.default_task
|
231
|
+
end
|
232
|
+
rescue
|
233
|
+
nil
|
234
|
+
end
|
235
|
+
|
168
236
|
private
|
169
237
|
|
170
238
|
def custom_headers
|
@@ -207,19 +275,45 @@ module ThorEnhance
|
|
207
275
|
end
|
208
276
|
|
209
277
|
def children_descriptors
|
210
|
-
child_commands.map { params_for_child(_1) }
|
278
|
+
default = child_commands.map { params_for_child(_1) }.select { _1[:default_command] }
|
279
|
+
not_default = child_commands.map { params_for_child(_1) }.select { !_1[:default_command] }
|
280
|
+
default + not_default
|
211
281
|
end
|
212
282
|
|
213
283
|
def params_for_child(child)
|
284
|
+
relative_link = find_iterations_back(child)
|
285
|
+
link = child.relative_readme_path[relative_link..-1].join("/")
|
214
286
|
{
|
215
|
-
|
216
|
-
link: child.relative_readme_path[-1],
|
217
|
-
description: child.description,
|
287
|
+
all_bases: child.all_bases,
|
218
288
|
basename_string: child.basename_string,
|
289
|
+
default_command: child.name == default_command,
|
290
|
+
default_command_string: default_command_string,
|
291
|
+
description: child.description,
|
219
292
|
examples: child.drawn_out_examples(with_desc: false) || [],
|
293
|
+
link: link,
|
294
|
+
preferred_basename_string: child.preferred_basename_string,
|
295
|
+
title: child.title,
|
220
296
|
}
|
221
297
|
end
|
222
298
|
|
299
|
+
def find_iterations_back(child)
|
300
|
+
# if parent is not present, then start from 0th position
|
301
|
+
return 0 if child.parent.nil?
|
302
|
+
# When there is no children, just take the last
|
303
|
+
return -1 unless child.leaf.children?
|
304
|
+
|
305
|
+
# when parent exists, find out how many parents there are
|
306
|
+
# Return how many parents there are
|
307
|
+
iterations = -1
|
308
|
+
temp_child = child
|
309
|
+
while temp = temp_child.parent
|
310
|
+
iterations -= 1
|
311
|
+
temp_child = temp_child.parent
|
312
|
+
end
|
313
|
+
|
314
|
+
iterations
|
315
|
+
end
|
316
|
+
|
223
317
|
def headers
|
224
318
|
(command.header || []).map { _1[:arguments][:kwargs] }
|
225
319
|
end
|
@@ -233,7 +327,7 @@ module ThorEnhance
|
|
233
327
|
end
|
234
328
|
|
235
329
|
def options
|
236
|
-
command.options
|
330
|
+
command.options.reject { |name, option| option.hide}
|
237
331
|
end
|
238
332
|
end
|
239
333
|
end
|
@@ -61,9 +61,9 @@ module ThorEnhance
|
|
61
61
|
def readme(required: nil, empty_group: :unassigned, skip_key: DEFAULT_SKIP_KEY, enums: [:important, :advanced, skip_key.to_sym].compact)
|
62
62
|
ThorEnhance::Configuration.allow_changes?
|
63
63
|
|
64
|
-
@readme_empty_group = empty_group
|
64
|
+
@readme_empty_group = empty_group.to_sym
|
65
65
|
@readme_skip_key = skip_key
|
66
|
-
@readme_enums = enums.map(&:to_sym)
|
66
|
+
@readme_enums = enums.map(&:to_sym) << empty_group.to_sym
|
67
67
|
required = required.nil? ? @required : required
|
68
68
|
configuration[:add_option_enhance][:readme] = { enums: enums, required: required }
|
69
69
|
end
|
@@ -4,9 +4,8 @@
|
|
4
4
|
<summary> <h3> <%= group_name.to_s.titlecase %> options </h3> </summary>
|
5
5
|
|
6
6
|
```bash
|
7
|
-
<%= method_options[group_name].map { _1.template_text }.join("\n") %>
|
7
|
+
<%= method_options[group_name].map { "#{_1.template_text}\n" }.join("\n") %>
|
8
8
|
```
|
9
9
|
|
10
10
|
</details>
|
11
|
-
|
12
11
|
<% end %>
|
@@ -1,11 +1,13 @@
|
|
1
1
|
# <%= title.to_s.titlecase %>
|
2
2
|
|
3
|
+
<%= command_source %>
|
4
|
+
|
3
5
|
## Description
|
4
6
|
<%= command.long_description || command.description %>
|
5
7
|
|
6
8
|
```bash
|
7
9
|
# Base command for `<%= command.usage %>`
|
8
|
-
<%=
|
10
|
+
<%= all_bases.join(" <options> \n") %> <options>
|
9
11
|
```
|
10
12
|
|
11
13
|
<%= custom_headers %>
|
@@ -36,14 +38,17 @@
|
|
36
38
|
<% children_descriptors.each do |child| %>
|
37
39
|
### [<%= child[:title]%>](<%= child[:link] %>)
|
38
40
|
|
41
|
+
<%= "**Default Command** <br>" if child[:default_command] %>
|
39
42
|
<%= child[:description] %>
|
40
43
|
|
41
44
|
```bash
|
42
|
-
<%= child[:
|
45
|
+
<%= child[:all_bases].join(" <options> \n") %> <options>
|
43
46
|
<%= child[:examples].map { _1 }.join("\n") %>
|
44
47
|
```
|
45
48
|
<% end %>
|
46
49
|
<% end %>
|
50
|
+
|
51
|
+
<%= class_options_erb %>
|
47
52
|
---
|
48
53
|
|
49
54
|
<%= footer_erb %>
|
@@ -1,3 +1,2 @@
|
|
1
1
|
> AutoGenerateted by [ThorEnhance](https://github.com/matt-taylor/thor_enhance) <br>
|
2
|
-
> Regenerate
|
3
|
-
> Regenerate all files with: <%= regenerate_thor_command %>
|
2
|
+
> Regenerate readme files with: <%= regenerate_thor_command %>
|
@@ -30,16 +30,24 @@ module ThorEnhance
|
|
30
30
|
end
|
31
31
|
|
32
32
|
command_structure = leaves.map do |name, leaf|
|
33
|
-
|
33
|
+
Command.new(name: name, leaf: leaf, basename: basename, root: options.generated_root)
|
34
34
|
end
|
35
35
|
|
36
36
|
# flatten_children returns all kids, grandkids, great grandkids etc of the commands returned from the above mapping
|
37
37
|
youthful_kids = command_structure.map(&:flatten_children).flatten
|
38
|
+
children_result = save_generated_readmes!(commands: youthful_kids, generated_root: options.generated_root, apply: options.apply)
|
39
|
+
return children_result if children_result[:status] != :pass
|
38
40
|
|
39
|
-
|
40
|
-
|
41
|
+
root_result = save_generated_readmes!(commands: command_structure, generated_root: options.generated_root, apply: options.apply)
|
42
|
+
return root_result if root_result[:status] != :pass
|
41
43
|
|
42
|
-
|
44
|
+
self_for_roots = root_result[:saved_status].collect { _1[:self_for_root] }
|
45
|
+
# Add saved results from the children
|
46
|
+
root_result[:saved_status] += children_result[:saved_status]
|
47
|
+
# Add root savior saved results
|
48
|
+
root_result[:saved_status] << root_savior!(basename: basename, apply: options.apply, full_root: root_result[:full_root], self_for_roots: self_for_roots)
|
49
|
+
|
50
|
+
root_result
|
43
51
|
end
|
44
52
|
|
45
53
|
def save_generated_readmes!(commands:, generated_root:, apply:)
|
@@ -48,17 +56,18 @@ module ThorEnhance
|
|
48
56
|
saved_status = commands.map do |command|
|
49
57
|
command.save_self!(root: full_root, apply: apply)
|
50
58
|
end
|
51
|
-
self_for_roots = saved_status.collect { _1[:self_for_root] }
|
52
|
-
saved_status << root_savior!(apply: apply, full_root: full_root, self_for_roots: self_for_roots)
|
53
59
|
|
54
|
-
{ status: :pass, saved_status: saved_status }
|
60
|
+
{ status: :pass, full_root: full_root, saved_status: saved_status }
|
55
61
|
end
|
56
62
|
|
57
|
-
def root_savior!(full_root:, self_for_roots:, apply:)
|
63
|
+
def root_savior!(basename:, full_root:, self_for_roots:, apply:)
|
58
64
|
full_path = "#{full_root}/Readme.md"
|
59
|
-
|
65
|
+
regenerate_thor_command = "#{basename} thor_enhance_autogenerate --apply"
|
66
|
+
footer = ThorEnhance::Autogenerate::Command::FOOTER_TEMPLATE.result_with_hash({ regenerate_thor_command: regenerate_thor_command })
|
67
|
+
|
68
|
+
root_erb_result = (self_for_roots.map do |root_child|
|
60
69
|
ROOT_TEMPLATE.result_with_hash({ root_child: root_child })
|
61
|
-
end.join("\n")
|
70
|
+
end + [footer]).join("\n")
|
62
71
|
|
63
72
|
FileUtils.mkdir_p(full_root)
|
64
73
|
if File.exist?(full_path)
|
@@ -100,7 +100,10 @@ module ThorEnhance
|
|
100
100
|
# The value is nil/unset
|
101
101
|
|
102
102
|
# If we have disabled required operations, go ahead and skip this
|
103
|
-
|
103
|
+
if ::Thor.__thor_enhance_definition == ThorEnhance::CommandMethod::ClassMethods::THOR_ENHANCE_DISABLE
|
104
|
+
::Thor.__thor_enhance_definition_ignored << meth.to_sym
|
105
|
+
next
|
106
|
+
end
|
104
107
|
|
105
108
|
# Skip if the expected command method was not required
|
106
109
|
next unless object[:required]
|
@@ -135,8 +138,11 @@ module ThorEnhance
|
|
135
138
|
@__thor_enhance_definition_stack ||= []
|
136
139
|
end
|
137
140
|
|
138
|
-
|
141
|
+
def __thor_enhance_definition_ignored
|
142
|
+
@__thor_enhance_definition_ignored ||= []
|
143
|
+
end
|
139
144
|
|
145
|
+
private
|
140
146
|
|
141
147
|
def __thor_enhance_validate_arguments!(object, input, args, kwargs)
|
142
148
|
expected_arity = object.dig(:arity)
|
data/lib/thor_enhance/sample.rb
CHANGED
@@ -10,6 +10,7 @@ module ThorEnhance
|
|
10
10
|
thor_enhance_allow!
|
11
11
|
|
12
12
|
desc "innard", "Validate that a subcommand works. This description can be as long as you want it to be."
|
13
|
+
title "Innard command for Subtask Subcommand"
|
13
14
|
long_desc "Wow, This longer description will take precedence over the desc above. This is what will be shown in the readme autogenerated page. Try me out!"
|
14
15
|
example "innard --count 5", desc: "Innard sub command with a count of 5"
|
15
16
|
example "innard --count 35", desc: "Innard sub command with a count of 35"
|
@@ -20,6 +21,7 @@ module ThorEnhance
|
|
20
21
|
end
|
21
22
|
|
22
23
|
desc "sub", "Thor sub command validation for thor enhance"
|
24
|
+
title "Subcommand for sample class"
|
23
25
|
subcommand "sub", SubCommand
|
24
26
|
|
25
27
|
desc "sample", "This Sample command does a lot of nothing"
|
@@ -33,8 +35,24 @@ module ThorEnhance
|
|
33
35
|
example "sample", desc: "yo yo ma"
|
34
36
|
example "sample --boolean", desc: "yo yo ma"
|
35
37
|
method_option :boolean, aliases: "-b", type: :boolean, desc: "Just a normal boolean", readme: :important
|
38
|
+
method_option :count, type: :numeric, enum: [1,2,3,4,5], default: 1, desc: "How many times to output text", readme: :important
|
36
39
|
def sample
|
37
|
-
Kernel.puts "Executed Sample method"
|
40
|
+
options[:count].times { Kernel.puts "Executed Sample method" }
|
41
|
+
end
|
42
|
+
|
43
|
+
desc "autobots", "Command outputs what Optimus prime is thniking"
|
44
|
+
when_should_i_use_this <<~README
|
45
|
+
Do you ever feel angry about how powerful the Decepticons are compared to the Autobots? It seems unfair.
|
46
|
+
Trust...The autobots agree.
|
47
|
+
README
|
48
|
+
example "sample", desc: "yo yo ma"
|
49
|
+
example "sample --boolean", desc: "yo yo ma"
|
50
|
+
method_option :bumble, aliases: "-b", type: :boolean, desc: "Enable bumblee bee flag", readme: :important
|
51
|
+
def autobots
|
52
|
+
Kernel.puts "Optimus prime requires megatron must be eliminated"
|
53
|
+
if options.bumble
|
54
|
+
Kernel.puts "Bumble bee agrees"
|
55
|
+
end
|
38
56
|
end
|
39
57
|
end
|
40
58
|
end
|
data/lib/thor_enhance/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: thor_enhance
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.5.
|
4
|
+
version: 0.5.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Matt Taylor
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-12-
|
11
|
+
date: 2023-12-26 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: thor
|
@@ -70,12 +70,18 @@ files:
|
|
70
70
|
- examples/basic_example.md
|
71
71
|
- examples/example_with_subcommand.md
|
72
72
|
- examples/hooks.md
|
73
|
+
- generated_readme/commands/Readme.md
|
74
|
+
- generated_readme/commands/autobots.md
|
75
|
+
- generated_readme/commands/sample.md
|
76
|
+
- generated_readme/commands/sub/Readme.md
|
77
|
+
- generated_readme/commands/sub/innard.md
|
73
78
|
- lib/thor_enhance.rb
|
74
79
|
- lib/thor_enhance/autogenerate.rb
|
75
80
|
- lib/thor_enhance/autogenerate/command.rb
|
76
81
|
- lib/thor_enhance/autogenerate/configuration.rb
|
77
82
|
- lib/thor_enhance/autogenerate/option.rb
|
78
83
|
- lib/thor_enhance/autogenerate/templates/aggregate_options.rb.erb
|
84
|
+
- lib/thor_enhance/autogenerate/templates/class_options.rb.erb
|
79
85
|
- lib/thor_enhance/autogenerate/templates/command.rb.erb
|
80
86
|
- lib/thor_enhance/autogenerate/templates/footer.rb.erb
|
81
87
|
- lib/thor_enhance/autogenerate/templates/option.rb.erb
|