fylla 0.3.0 → 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/Gemfile +4 -4
- data/exe/fylla +0 -0
- data/fylla.gemspec +39 -39
- data/lib/fylla.rb +3 -1
- data/lib/fylla/completion_extension.rb +15 -21
- data/lib/fylla/completion_generator.rb +184 -184
- data/lib/fylla/erb_templates/bash/command.erb +14 -14
- data/lib/fylla/erb_templates/bash/subcommand.erb +36 -36
- data/lib/fylla/erb_templates/zsh/subcommand.erb +2 -2
- data/lib/fylla/thor/extensions/ShellDescriptionExtension.rb +1 -0
- data/lib/fylla/version.rb +1 -1
- metadata +4 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: dfe6f78127702957706d81b2d20f1433edb3d0539c2fe06cb7a5faa8a199dee1
|
4
|
+
data.tar.gz: c2aa3c67515e64eb9ea13c3177cc5f911bd65123438cda196df7a04781ee0a7e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 39368c375eb8ccbc486609c06590e324e1aaa0980a071fa550c7898f6f1843a66a23320ec48a93d6b3d0dc7ecb29096a04d45be4b6eb2657108f0e505c5e2088
|
7
|
+
data.tar.gz: b6343092982862c13bcc149515a0d68a61623ca5a7790f41d4c0f3fa7406173549ecf2887d61a91e57bb6f57b080102fe09737074d04ab6da8a70873f7e38d31
|
data/Gemfile
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
source 'https://rubygems.org'
|
2
|
-
|
3
|
-
# Specify your gem's dependencies in Fylla.gemspec
|
4
|
-
gemspec
|
1
|
+
source 'https://rubygems.org'
|
2
|
+
|
3
|
+
# Specify your gem's dependencies in Fylla.gemspec
|
4
|
+
gemspec
|
data/exe/fylla
CHANGED
File without changes
|
data/fylla.gemspec
CHANGED
@@ -1,39 +1,39 @@
|
|
1
|
-
lib = File.expand_path('lib', __dir__)
|
2
|
-
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
3
|
-
require 'fylla/version'
|
4
|
-
|
5
|
-
# rubocop:disable BlockLength
|
6
|
-
Gem::Specification.new do |spec|
|
7
|
-
spec.name = 'fylla'
|
8
|
-
spec.version = Fylla::VERSION
|
9
|
-
spec.authors = ['Tyler Thrailkill']
|
10
|
-
spec.email = ['tyler.b.thrailkill@gmail.com']
|
11
|
-
|
12
|
-
spec.summary = 'Adds functions for generating autocomplete scripts for Thor applications'
|
13
|
-
spec.description = 'Fylla generates zsh and bash autocomplete scripts for Thor CLI applications.'
|
14
|
-
spec.homepage = 'https://github.com/snowe2010/fylla'
|
15
|
-
spec.license = 'MIT'
|
16
|
-
|
17
|
-
spec.metadata['yard.run'] = 'yri' # use "yard" to build full HTML docs.
|
18
|
-
spec.metadata['changelog_uri'] = 'https://github.com/snowe2010/fylla/blob/master/CHANGELOG.md'
|
19
|
-
|
20
|
-
# Specify which files should be added to the gem when it is released.
|
21
|
-
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
22
|
-
spec.files = Dir.chdir(File.expand_path(__dir__)) do
|
23
|
-
`git ls-files -z`.split("\x0").reject do |f|
|
24
|
-
f.match(%r{^(.idea|test|spec|features)/|^[.][a-zA-Z0-9]|^.*[.]md|Gemfile.lock})
|
25
|
-
end
|
26
|
-
end
|
27
|
-
|
28
|
-
spec.bindir = 'exe'
|
29
|
-
spec.executables = spec.files.grep(%r{^exe/}) {|f| File.basename(f)}
|
30
|
-
spec.require_paths = ['lib']
|
31
|
-
|
32
|
-
spec.add_development_dependency 'bundler', '~> 2.0'
|
33
|
-
spec.add_development_dependency 'codecov', '~> 0.1.14'
|
34
|
-
spec.add_development_dependency 'minitest', '~> 5.0'
|
35
|
-
spec.add_development_dependency 'minitest-hooks', '~> 1.5.0'
|
36
|
-
spec.add_development_dependency 'rake', '~> 10.0'
|
37
|
-
spec.add_dependency 'thor', '>= 0.19.0'
|
38
|
-
end
|
39
|
-
# rubocop:enable BlockLength
|
1
|
+
lib = File.expand_path('lib', __dir__)
|
2
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
3
|
+
require 'fylla/version'
|
4
|
+
|
5
|
+
# rubocop:disable BlockLength
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = 'fylla'
|
8
|
+
spec.version = Fylla::VERSION
|
9
|
+
spec.authors = ['Tyler Thrailkill']
|
10
|
+
spec.email = ['tyler.b.thrailkill@gmail.com']
|
11
|
+
|
12
|
+
spec.summary = 'Adds functions for generating autocomplete scripts for Thor applications'
|
13
|
+
spec.description = 'Fylla generates zsh and bash autocomplete scripts for Thor CLI applications.'
|
14
|
+
spec.homepage = 'https://github.com/snowe2010/fylla'
|
15
|
+
spec.license = 'MIT'
|
16
|
+
|
17
|
+
spec.metadata['yard.run'] = 'yri' # use "yard" to build full HTML docs.
|
18
|
+
spec.metadata['changelog_uri'] = 'https://github.com/snowe2010/fylla/blob/master/CHANGELOG.md'
|
19
|
+
|
20
|
+
# Specify which files should be added to the gem when it is released.
|
21
|
+
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
22
|
+
spec.files = Dir.chdir(File.expand_path(__dir__)) do
|
23
|
+
`git ls-files -z`.split("\x0").reject do |f|
|
24
|
+
f.match(%r{^(.idea|test|spec|features)/|^[.][a-zA-Z0-9]|^.*[.]md|Gemfile.lock})
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
spec.bindir = 'exe'
|
29
|
+
spec.executables = spec.files.grep(%r{^exe/}) {|f| File.basename(f)}
|
30
|
+
spec.require_paths = ['lib']
|
31
|
+
|
32
|
+
spec.add_development_dependency 'bundler', '~> 2.0'
|
33
|
+
spec.add_development_dependency 'codecov', '~> 0.1.14'
|
34
|
+
spec.add_development_dependency 'minitest', '~> 5.0'
|
35
|
+
spec.add_development_dependency 'minitest-hooks', '~> 1.5.0'
|
36
|
+
spec.add_development_dependency 'rake', '~> 10.0'
|
37
|
+
spec.add_dependency 'thor', '>= 0.19.0'
|
38
|
+
end
|
39
|
+
# rubocop:enable BlockLength
|
data/lib/fylla.rb
CHANGED
@@ -5,6 +5,9 @@ require 'fylla/parsed_subcommand'
|
|
5
5
|
require 'fylla/completion_extension'
|
6
6
|
require 'thor'
|
7
7
|
|
8
|
+
# We _must prepend before thor loads_ Ideally this is at require time...
|
9
|
+
::Thor::Option.prepend Fylla::Thor::Option
|
10
|
+
|
8
11
|
#
|
9
12
|
# Top level module for the Fylla project.
|
10
13
|
# Contains one method for initializing Fylla
|
@@ -18,7 +21,6 @@ module Fylla
|
|
18
21
|
def self.load(executable_name = nil)
|
19
22
|
@executable_name = executable_name || nil
|
20
23
|
::Thor.prepend Fylla::Thor::CompletionGenerator
|
21
|
-
# ::Thor::Option.prepend Fylla::Thor::Option
|
22
24
|
end
|
23
25
|
|
24
26
|
#
|
@@ -1,21 +1,15 @@
|
|
1
|
-
require 'thor'
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
def completion(completion)
|
17
|
-
@completion = completion
|
18
|
-
end
|
19
|
-
end
|
20
|
-
end
|
21
|
-
end
|
1
|
+
require 'thor'
|
2
|
+
|
3
|
+
# add the 'completion:' option to Thor::Option, which
|
4
|
+
# allows passing a shorter description for the shell
|
5
|
+
module Fylla
|
6
|
+
module Thor
|
7
|
+
module Option
|
8
|
+
attr_accessor :completion
|
9
|
+
def initialize(name, options = {})
|
10
|
+
@completion = options[:completion]
|
11
|
+
super
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
@@ -1,184 +1,184 @@
|
|
1
|
-
require_relative 'parsed_option'
|
2
|
-
require_relative 'parsed_command'
|
3
|
-
require_relative 'parsed_subcommand'
|
4
|
-
require 'erb'
|
5
|
-
|
6
|
-
module Fylla
|
7
|
-
module Thor
|
8
|
-
#
|
9
|
-
# module for prepending into +Thor+
|
10
|
-
# inserts methods into Thor that allow generating completion scripts
|
11
|
-
module CompletionGenerator
|
12
|
-
def self.prepended(base)
|
13
|
-
base.singleton_class.prepend(ClassMethods)
|
14
|
-
end
|
15
|
-
|
16
|
-
#
|
17
|
-
# Contains the methods +zsh_completion+
|
18
|
-
module ClassMethods
|
19
|
-
#
|
20
|
-
# Generates a zsh _[executable_name] completion
|
21
|
-
# script for the entire Thor application
|
22
|
-
#
|
23
|
-
# @param executable_name [String]
|
24
|
-
# the name of the executable to generate the script for
|
25
|
-
def zsh_completion(executable_name)
|
26
|
-
@executable_name = executable_name
|
27
|
-
command = create_command_map all_commands, subcommand_classes
|
28
|
-
|
29
|
-
builder = map_to_completion_string [command]
|
30
|
-
completion = "#compdef _#{executable_name} #{executable_name}\n"
|
31
|
-
completion += builder
|
32
|
-
completion
|
33
|
-
end
|
34
|
-
|
35
|
-
#
|
36
|
-
# Generates a bash _[executable_name] completion
|
37
|
-
# script for the entire Thor application
|
38
|
-
#
|
39
|
-
# @param executable_name [String]
|
40
|
-
# the name of the executable to generate the script for
|
41
|
-
def bash_completion(executable_name)
|
42
|
-
@executable_name = executable_name
|
43
|
-
command = create_command_map all_commands, subcommand_classes
|
44
|
-
|
45
|
-
builder = map_to_completion_string [command], style: :bash
|
46
|
-
completion = ''
|
47
|
-
completion += builder
|
48
|
-
completion += "complete -F _#{executable_name} #{executable_name}\n"
|
49
|
-
completion
|
50
|
-
end
|
51
|
-
|
52
|
-
private
|
53
|
-
|
54
|
-
# Takes a list of [ParsedCommand]s and [ParsedSubcommand]s
|
55
|
-
# and converts them into completion strings, to be combined
|
56
|
-
# together into one completion script
|
57
|
-
#
|
58
|
-
# @param style [Symbol] style of completions to generate
|
59
|
-
# defaults to :zsh
|
60
|
-
# @param commands [List<Thor::Command>]
|
61
|
-
# list of [Thor::Command]s
|
62
|
-
# @param context [String] the current command context
|
63
|
-
# this is essentially a breadcrumb of our current
|
64
|
-
# command path:
|
65
|
-
# e.g. "exe sub1 sub2 sub3 --help" maps to a context of
|
66
|
-
# "_sub1_sub2_sub3"
|
67
|
-
# @param class_options [List<Thor::Option>]
|
68
|
-
# a list of global or class level options for the current context
|
69
|
-
def map_to_completion_string(commands,
|
70
|
-
context: '',
|
71
|
-
class_options: [],
|
72
|
-
style: :zsh)
|
73
|
-
builder = ''
|
74
|
-
commands.each do |command|
|
75
|
-
context_name = generate_context_name(context, command)
|
76
|
-
result = generate_completion_string(command, class_options, context_name, style)
|
77
|
-
builder += result
|
78
|
-
end
|
79
|
-
builder
|
80
|
-
end
|
81
|
-
|
82
|
-
# Generate a context name based off of
|
83
|
-
# the current context and the current command
|
84
|
-
#
|
85
|
-
# @param context [String] the current context
|
86
|
-
# @param command [Thor::Command]
|
87
|
-
# current command we are generating documentation for
|
88
|
-
def generate_context_name(context, command)
|
89
|
-
command_name = if command.name.nil? || command.name.empty?
|
90
|
-
''
|
91
|
-
else
|
92
|
-
"_#{command.name}"
|
93
|
-
end
|
94
|
-
"#{context}#{command_name}"
|
95
|
-
end
|
96
|
-
|
97
|
-
def generate_completion_string(command, class_options, context_name, style)
|
98
|
-
builder = ''
|
99
|
-
if command.is_a? ParsedSubcommand
|
100
|
-
class_options = (class_options + command.class_options).uniq
|
101
|
-
builder += map_to_completion_string(command.commands,
|
102
|
-
context: context_name,
|
103
|
-
class_options: class_options,
|
104
|
-
style: style)
|
105
|
-
|
106
|
-
builder += create_completion_string(read_template(style, :subcommand), binding)
|
107
|
-
else
|
108
|
-
builder += create_completion_string(read_template(style, :command), binding)
|
109
|
-
end
|
110
|
-
builder
|
111
|
-
end
|
112
|
-
|
113
|
-
# Recursively generate a command map based off
|
114
|
-
# of the commands and subcommands passed in.
|
115
|
-
#
|
116
|
-
# The [command_map] is a map of [String]s to [Thor::Command] objects,
|
117
|
-
# while the [subcommand_map] is a map of [String]s to [Thor] classes,
|
118
|
-
# usually your own CLI classes that subclass [Thor]
|
119
|
-
#
|
120
|
-
# @param command_map [Hash<String, Thor::Command>]
|
121
|
-
# a map to recursively generate a completion layout
|
122
|
-
# @param subcommand_map [Hash<String, Class < Thor>]
|
123
|
-
# a map indicating the subcommands and their respective classes
|
124
|
-
def recursively_find_commands(command_map, subcommand_map)
|
125
|
-
map = Hash[command_map.map {|k, v| [v, subcommand_map[k]]}]
|
126
|
-
map.map do |command, subcommand_class|
|
127
|
-
if subcommand_class.nil?
|
128
|
-
ancestor_name = command.ancestor_name if command.respond_to? :ancestor_name
|
129
|
-
options = parse_options(command.options.values)
|
130
|
-
ParsedCommand.new(ancestor_name, command.description, command.name, options)
|
131
|
-
else
|
132
|
-
commands = recursively_find_commands subcommand_class.commands, subcommand_class.subcommand_classes
|
133
|
-
ParsedSubcommand.new(command.name, command.description, commands, subcommand_class.class_options.values)
|
134
|
-
end
|
135
|
-
end
|
136
|
-
end
|
137
|
-
|
138
|
-
# Top level method to begin the recursive map generation
|
139
|
-
# This is needed because we don't have a 'top' level
|
140
|
-
# command to wrap everything under.
|
141
|
-
#
|
142
|
-
# This simplifies the rest of the code.
|
143
|
-
#
|
144
|
-
# (see #recursively_find_commands) for more documentation
|
145
|
-
def create_command_map(command_map, subcommand_map)
|
146
|
-
command_map = recursively_find_commands command_map, subcommand_map
|
147
|
-
ParsedSubcommand.new(nil, '', command_map, class_options.values)
|
148
|
-
end
|
149
|
-
|
150
|
-
# Helper method to load an [ERB] template
|
151
|
-
# and generate the corresponding [String]
|
152
|
-
#
|
153
|
-
# @param template [String] an ERB template
|
154
|
-
# @param bind [Binding] a binding to a context
|
155
|
-
def create_completion_string(template, bind)
|
156
|
-
template = ERB.new(template, nil, '-<>')
|
157
|
-
template.result(bind)
|
158
|
-
end
|
159
|
-
|
160
|
-
# Helper method to read an [ERB] template
|
161
|
-
# from a file and return it as a [String]
|
162
|
-
#
|
163
|
-
# @param name [Symbol] type of template to retrieve
|
164
|
-
# can be either :subcommand or :command
|
165
|
-
# @param style [Symbol] style of template to retrieve
|
166
|
-
# can be either :zsh or :bash
|
167
|
-
# @return [String] template string retrieved from erb file
|
168
|
-
def read_template(style, name)
|
169
|
-
style = style.is_a?(Symbol) ? style.to_s : style
|
170
|
-
name = name.is_a?(Symbol) ? name.to_s : name
|
171
|
-
erb_path = "erb_templates/#{style}/#{name}.erb"
|
172
|
-
File.read(File.join(__dir__, erb_path))
|
173
|
-
end
|
174
|
-
|
175
|
-
def parse_options(options)
|
176
|
-
options.map do |opt|
|
177
|
-
description = opt.completion || opt.description || opt.banner
|
178
|
-
ParsedOption.new(opt.name, description, opt.aliases)
|
179
|
-
end
|
180
|
-
end
|
181
|
-
end
|
182
|
-
end
|
183
|
-
end
|
184
|
-
end
|
1
|
+
require_relative 'parsed_option'
|
2
|
+
require_relative 'parsed_command'
|
3
|
+
require_relative 'parsed_subcommand'
|
4
|
+
require 'erb'
|
5
|
+
|
6
|
+
module Fylla
|
7
|
+
module Thor
|
8
|
+
#
|
9
|
+
# module for prepending into +Thor+
|
10
|
+
# inserts methods into Thor that allow generating completion scripts
|
11
|
+
module CompletionGenerator
|
12
|
+
def self.prepended(base)
|
13
|
+
base.singleton_class.prepend(ClassMethods)
|
14
|
+
end
|
15
|
+
|
16
|
+
#
|
17
|
+
# Contains the methods +zsh_completion+
|
18
|
+
module ClassMethods
|
19
|
+
#
|
20
|
+
# Generates a zsh _[executable_name] completion
|
21
|
+
# script for the entire Thor application
|
22
|
+
#
|
23
|
+
# @param executable_name [String]
|
24
|
+
# the name of the executable to generate the script for
|
25
|
+
def zsh_completion(executable_name)
|
26
|
+
@executable_name = executable_name
|
27
|
+
command = create_command_map all_commands, subcommand_classes
|
28
|
+
|
29
|
+
builder = map_to_completion_string [command]
|
30
|
+
completion = "#compdef _#{executable_name} #{executable_name}\n"
|
31
|
+
completion += builder
|
32
|
+
completion
|
33
|
+
end
|
34
|
+
|
35
|
+
#
|
36
|
+
# Generates a bash _[executable_name] completion
|
37
|
+
# script for the entire Thor application
|
38
|
+
#
|
39
|
+
# @param executable_name [String]
|
40
|
+
# the name of the executable to generate the script for
|
41
|
+
def bash_completion(executable_name)
|
42
|
+
@executable_name = executable_name
|
43
|
+
command = create_command_map all_commands, subcommand_classes
|
44
|
+
|
45
|
+
builder = map_to_completion_string [command], style: :bash
|
46
|
+
completion = ''
|
47
|
+
completion += builder
|
48
|
+
completion += "complete -F _#{executable_name} #{executable_name}\n"
|
49
|
+
completion
|
50
|
+
end
|
51
|
+
|
52
|
+
private
|
53
|
+
|
54
|
+
# Takes a list of [ParsedCommand]s and [ParsedSubcommand]s
|
55
|
+
# and converts them into completion strings, to be combined
|
56
|
+
# together into one completion script
|
57
|
+
#
|
58
|
+
# @param style [Symbol] style of completions to generate
|
59
|
+
# defaults to :zsh
|
60
|
+
# @param commands [List<Thor::Command>]
|
61
|
+
# list of [Thor::Command]s
|
62
|
+
# @param context [String] the current command context
|
63
|
+
# this is essentially a breadcrumb of our current
|
64
|
+
# command path:
|
65
|
+
# e.g. "exe sub1 sub2 sub3 --help" maps to a context of
|
66
|
+
# "_sub1_sub2_sub3"
|
67
|
+
# @param class_options [List<Thor::Option>]
|
68
|
+
# a list of global or class level options for the current context
|
69
|
+
def map_to_completion_string(commands,
|
70
|
+
context: '',
|
71
|
+
class_options: [],
|
72
|
+
style: :zsh)
|
73
|
+
builder = ''
|
74
|
+
commands.each do |command|
|
75
|
+
context_name = generate_context_name(context, command)
|
76
|
+
result = generate_completion_string(command, class_options, context_name, style)
|
77
|
+
builder += result
|
78
|
+
end
|
79
|
+
builder
|
80
|
+
end
|
81
|
+
|
82
|
+
# Generate a context name based off of
|
83
|
+
# the current context and the current command
|
84
|
+
#
|
85
|
+
# @param context [String] the current context
|
86
|
+
# @param command [Thor::Command]
|
87
|
+
# current command we are generating documentation for
|
88
|
+
def generate_context_name(context, command)
|
89
|
+
command_name = if command.name.nil? || command.name.empty?
|
90
|
+
''
|
91
|
+
else
|
92
|
+
"_#{command.name}"
|
93
|
+
end
|
94
|
+
"#{context}#{command_name}"
|
95
|
+
end
|
96
|
+
|
97
|
+
def generate_completion_string(command, class_options, context_name, style)
|
98
|
+
builder = ''
|
99
|
+
if command.is_a? ParsedSubcommand
|
100
|
+
class_options = (class_options + command.class_options).uniq
|
101
|
+
builder += map_to_completion_string(command.commands,
|
102
|
+
context: context_name,
|
103
|
+
class_options: class_options,
|
104
|
+
style: style)
|
105
|
+
|
106
|
+
builder += create_completion_string(read_template(style, :subcommand), binding)
|
107
|
+
else
|
108
|
+
builder += create_completion_string(read_template(style, :command), binding)
|
109
|
+
end
|
110
|
+
builder
|
111
|
+
end
|
112
|
+
|
113
|
+
# Recursively generate a command map based off
|
114
|
+
# of the commands and subcommands passed in.
|
115
|
+
#
|
116
|
+
# The [command_map] is a map of [String]s to [Thor::Command] objects,
|
117
|
+
# while the [subcommand_map] is a map of [String]s to [Thor] classes,
|
118
|
+
# usually your own CLI classes that subclass [Thor]
|
119
|
+
#
|
120
|
+
# @param command_map [Hash<String, Thor::Command>]
|
121
|
+
# a map to recursively generate a completion layout
|
122
|
+
# @param subcommand_map [Hash<String, Class < Thor>]
|
123
|
+
# a map indicating the subcommands and their respective classes
|
124
|
+
def recursively_find_commands(command_map, subcommand_map)
|
125
|
+
map = Hash[command_map.map {|k, v| [v, subcommand_map[k]]}]
|
126
|
+
map.map do |command, subcommand_class|
|
127
|
+
if subcommand_class.nil?
|
128
|
+
ancestor_name = command.ancestor_name if command.respond_to? :ancestor_name
|
129
|
+
options = parse_options(command.options.values)
|
130
|
+
ParsedCommand.new(ancestor_name, command.description, command.name, options)
|
131
|
+
else
|
132
|
+
commands = recursively_find_commands subcommand_class.commands, subcommand_class.subcommand_classes
|
133
|
+
ParsedSubcommand.new(command.name, command.description, commands, subcommand_class.class_options.values)
|
134
|
+
end
|
135
|
+
end
|
136
|
+
end
|
137
|
+
|
138
|
+
# Top level method to begin the recursive map generation
|
139
|
+
# This is needed because we don't have a 'top' level
|
140
|
+
# command to wrap everything under.
|
141
|
+
#
|
142
|
+
# This simplifies the rest of the code.
|
143
|
+
#
|
144
|
+
# (see #recursively_find_commands) for more documentation
|
145
|
+
def create_command_map(command_map, subcommand_map)
|
146
|
+
command_map = recursively_find_commands command_map, subcommand_map
|
147
|
+
ParsedSubcommand.new(nil, '', command_map, class_options.values)
|
148
|
+
end
|
149
|
+
|
150
|
+
# Helper method to load an [ERB] template
|
151
|
+
# and generate the corresponding [String]
|
152
|
+
#
|
153
|
+
# @param template [String] an ERB template
|
154
|
+
# @param bind [Binding] a binding to a context
|
155
|
+
def create_completion_string(template, bind)
|
156
|
+
template = ERB.new(template, nil, '-<>')
|
157
|
+
template.result(bind)
|
158
|
+
end
|
159
|
+
|
160
|
+
# Helper method to read an [ERB] template
|
161
|
+
# from a file and return it as a [String]
|
162
|
+
#
|
163
|
+
# @param name [Symbol] type of template to retrieve
|
164
|
+
# can be either :subcommand or :command
|
165
|
+
# @param style [Symbol] style of template to retrieve
|
166
|
+
# can be either :zsh or :bash
|
167
|
+
# @return [String] template string retrieved from erb file
|
168
|
+
def read_template(style, name)
|
169
|
+
style = style.is_a?(Symbol) ? style.to_s : style
|
170
|
+
name = name.is_a?(Symbol) ? name.to_s : name
|
171
|
+
erb_path = "erb_templates/#{style}/#{name}.erb"
|
172
|
+
File.read(File.join(__dir__, erb_path))
|
173
|
+
end
|
174
|
+
|
175
|
+
def parse_options(options)
|
176
|
+
options.map do |opt|
|
177
|
+
description = opt.completion || opt.description || opt.banner
|
178
|
+
ParsedOption.new(opt.name, description, opt.aliases)
|
179
|
+
end
|
180
|
+
end
|
181
|
+
end
|
182
|
+
end
|
183
|
+
end
|
184
|
+
end
|
@@ -1,14 +1,14 @@
|
|
1
|
-
_<%= @executable_name %><%= context_name %> ()
|
2
|
-
{
|
3
|
-
local cur="${COMP_WORDS[COMP_CWORD]}"
|
4
|
-
local options=()
|
5
|
-
<%- command.options.each do |opt| -%>
|
6
|
-
options+=("--<%= opt.name %>")
|
7
|
-
<%- opt.aliases.each do |a| -%>
|
8
|
-
options+=("-<%= a %>")
|
9
|
-
<%- end -%>
|
10
|
-
<%- end -%>
|
11
|
-
options+=("--help")
|
12
|
-
options+=("-h")
|
13
|
-
COMPREPLY=($(compgen -W "${options[*]}" -- "$cur"))
|
14
|
-
}
|
1
|
+
_<%= @executable_name %><%= context_name %> ()
|
2
|
+
{
|
3
|
+
local cur="${COMP_WORDS[COMP_CWORD]}"
|
4
|
+
local options=()
|
5
|
+
<%- command.options.each do |opt| -%>
|
6
|
+
options+=("--<%= opt.name %>")
|
7
|
+
<%- opt.aliases.each do |a| -%>
|
8
|
+
options+=("-<%= a %>")
|
9
|
+
<%- end -%>
|
10
|
+
<%- end -%>
|
11
|
+
options+=("--help")
|
12
|
+
options+=("-h")
|
13
|
+
COMPREPLY=($(compgen -W "${options[*]}" -- "$cur"))
|
14
|
+
}
|
@@ -1,36 +1,36 @@
|
|
1
|
-
_<%= @executable_name %><%= context_name %>() {
|
2
|
-
local i=1 subcommand_index
|
3
|
-
|
4
|
-
# find the subcommand
|
5
|
-
while [[ $i -lt $COMP_CWORD ]]; do
|
6
|
-
local s="${COMP_WORDS[i]}"
|
7
|
-
case "$s" in
|
8
|
-
<%= command.name || @executable_name %>)<%# if command.name is empty, then we're at the top level command. therefore we need to use the @executable_name %>
|
9
|
-
subcommand_index=$i
|
10
|
-
break
|
11
|
-
;;
|
12
|
-
esac
|
13
|
-
(( i++ ))
|
14
|
-
done
|
15
|
-
|
16
|
-
while [[ $subcommand_index -lt $COMP_CWORD ]]; do
|
17
|
-
local s="${COMP_WORDS[subcommand_index]}"
|
18
|
-
case "$s" in
|
19
|
-
<%- unless command.commands.empty? -%>
|
20
|
-
<%- command.commands.each do |command| -%>
|
21
|
-
<%= command.name %>)
|
22
|
-
_<%= @executable_name %><%= context_name %>_<%= command.name %>
|
23
|
-
return ;;
|
24
|
-
<%- end -%>
|
25
|
-
<%- end -%>
|
26
|
-
help)
|
27
|
-
COMPREPLY=""
|
28
|
-
return
|
29
|
-
;;
|
30
|
-
esac
|
31
|
-
(( subcommand_index++ ))
|
32
|
-
done
|
33
|
-
|
34
|
-
local cur="${COMP_WORDS[COMP_CWORD]}"
|
35
|
-
COMPREPLY=($(compgen -W "<%= command.commands.map(&:name).join(" ") %> <%= command.class_options.map(&:switch_name).join(" ") %>" -- "$cur"))
|
36
|
-
}
|
1
|
+
_<%= @executable_name %><%= context_name %>() {
|
2
|
+
local i=1 subcommand_index
|
3
|
+
|
4
|
+
# find the subcommand
|
5
|
+
while [[ $i -lt $COMP_CWORD ]]; do
|
6
|
+
local s="${COMP_WORDS[i]}"
|
7
|
+
case "$s" in
|
8
|
+
<%= command.name || @executable_name %>)<%# if command.name is empty, then we're at the top level command. therefore we need to use the @executable_name %>
|
9
|
+
subcommand_index=$i
|
10
|
+
break
|
11
|
+
;;
|
12
|
+
esac
|
13
|
+
(( i++ ))
|
14
|
+
done
|
15
|
+
|
16
|
+
while [[ $subcommand_index -lt $COMP_CWORD ]]; do
|
17
|
+
local s="${COMP_WORDS[subcommand_index]}"
|
18
|
+
case "$s" in
|
19
|
+
<%- unless command.commands.empty? -%>
|
20
|
+
<%- command.commands.each do |command| -%>
|
21
|
+
<%= command.name %>)
|
22
|
+
_<%= @executable_name %><%= context_name %>_<%= command.name %>
|
23
|
+
return ;;
|
24
|
+
<%- end -%>
|
25
|
+
<%- end -%>
|
26
|
+
help)
|
27
|
+
COMPREPLY=""
|
28
|
+
return
|
29
|
+
;;
|
30
|
+
esac
|
31
|
+
(( subcommand_index++ ))
|
32
|
+
done
|
33
|
+
|
34
|
+
local cur="${COMP_WORDS[COMP_CWORD]}"
|
35
|
+
COMPREPLY=($(compgen -W "<%= command.commands.map(&:name).join(" ") %> <%= command.class_options.map(&:switch_name).join(" ") %>" -- "$cur"))
|
36
|
+
}
|
@@ -16,9 +16,9 @@ function _<%= @executable_name %><%= context_name %> {
|
|
16
16
|
<%- unless class_options.nil? -%>
|
17
17
|
<%- class_options.each do |option| -%>
|
18
18
|
<%- option.aliases.each do |al| -%>
|
19
|
-
|
19
|
+
"-<%= al %>=[<%= option.description %>]" \
|
20
20
|
<%- end -%>
|
21
|
-
|
21
|
+
"--<%= option.name%>=[<%= option.description %>]" \
|
22
22
|
<%- end -%>
|
23
23
|
<%- end -%>
|
24
24
|
"-h[Show help information]" \
|
@@ -0,0 +1 @@
|
|
1
|
+
|
data/lib/fylla/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: fylla
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Tyler Thrailkill
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-
|
11
|
+
date: 2019-05-30 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -119,6 +119,7 @@ files:
|
|
119
119
|
- lib/fylla/parsed_command.rb
|
120
120
|
- lib/fylla/parsed_option.rb
|
121
121
|
- lib/fylla/parsed_subcommand.rb
|
122
|
+
- lib/fylla/thor/extensions/ShellDescriptionExtension.rb
|
122
123
|
- lib/fylla/version.rb
|
123
124
|
homepage: https://github.com/snowe2010/fylla
|
124
125
|
licenses:
|
@@ -142,7 +143,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
142
143
|
version: '0'
|
143
144
|
requirements: []
|
144
145
|
rubyforge_project:
|
145
|
-
rubygems_version: 2.6
|
146
|
+
rubygems_version: 2.7.6
|
146
147
|
signing_key:
|
147
148
|
specification_version: 4
|
148
149
|
summary: Adds functions for generating autocomplete scripts for Thor applications
|