fylla 0.1.0 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 99136984f7eb5a2b198e68ee41681aff9bfa3c97
4
- data.tar.gz: 2396f92bc99adcba4049207a0c6f19977c76fa4a
3
+ metadata.gz: e9146ead4c4c7a8a7d72096188734b6f439ffff2
4
+ data.tar.gz: 5533724b62e9c629c99d62f68eb7cf2c55b4dadd
5
5
  SHA512:
6
- metadata.gz: 3cc21ab97adc324024605fbab5ffb62c3cae1b4e4d90eb2308cbed9d4a025e1c3b31fc943e88b07e133cea46697477acc13936ab67da26110295a3faf490d4b1
7
- data.tar.gz: 654490096828d6a4416533dd07088e783a4e1c9703104b48db939f84598d35d9ecd88d4c86047e8d7ca074125260c914244cbb23472c5e439562e5e7ced3f9da
6
+ metadata.gz: ca9a24cb0a6829f9b0c814892c80684eed43a31c9d5d6c64b9d15b031aaa27850a8a53a0143b6da439f4d49b4a18cb6a9e7512272c088fa352a49659fb55a912
7
+ data.tar.gz: 737af6d0958eb919b9a8e9d2ec6dfb6e57fea009d337bd66853dee3f7aadbd18365222a4c56a0e93111f8bb5fd99845d22e54a1c95c6d88d0b34ef54892e2a60
data/fylla.gemspec CHANGED
@@ -10,14 +10,11 @@ Gem::Specification.new do |spec|
10
10
  spec.email = ['tyler.b.thrailkill@gmail.com']
11
11
 
12
12
  spec.summary = 'Adds functions for generating autocomplete scripts for Thor applications'
13
- spec.description = '
14
- Fylla generates zsh and bash autocomplete scripts for Thor CLI applications.
15
- '
13
+ spec.description = 'Fylla generates zsh and bash autocomplete scripts for Thor CLI applications.'
16
14
  spec.homepage = 'https://github.com/snowe2010/fylla'
17
15
  spec.license = 'MIT'
18
16
 
19
17
  spec.metadata['yard.run'] = 'yri' # use "yard" to build full HTML docs.
20
- # spec.metadata['changelog_uri'] = "TODO: Put your gem's CHANGELOG.md URL here."
21
18
 
22
19
  # Specify which files should be added to the gem when it is released.
23
20
  # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
@@ -32,10 +29,10 @@ Gem::Specification.new do |spec|
32
29
  spec.require_paths = ['lib']
33
30
 
34
31
  spec.add_development_dependency 'bundler', '~> 2.0'
32
+ spec.add_development_dependency 'codecov', '~> 0.1.14'
35
33
  spec.add_development_dependency 'minitest', '~> 5.0'
36
34
  spec.add_development_dependency 'minitest-hooks', '~> 1.5.0'
37
35
  spec.add_development_dependency 'rake', '~> 10.0'
38
- # spec.add_development_dependency 'thor', '~> 0.20.3'
39
36
  spec.add_dependency 'thor', '>= 0.19.0'
40
37
  end
41
38
  # rubocop:enable BlockLength
@@ -22,16 +22,36 @@ module Fylla
22
22
  # @param executable_name [String]
23
23
  # the name of the executable to generate the script for
24
24
  def zsh_completion(executable_name)
25
+ @executable_name = executable_name
25
26
  command = create_command_map commands, subcommand_classes
26
27
 
27
28
  help = create_completion_string(read_template(:zsh, :help), binding)
28
- builder = map_to_completion_string [command], executable_name
29
+ builder = map_to_completion_string [command]
29
30
  completion = "#compdef _#{executable_name} #{executable_name}\n"
30
31
  completion += builder
31
32
  completion += help
32
33
  completion
33
34
  end
34
35
 
36
+ #
37
+ # Generates a bash _[executable_name] completion
38
+ # script for the entire Thor application
39
+ #
40
+ # @param executable_name [String]
41
+ # the name of the executable to generate the script for
42
+ def bash_completion(executable_name)
43
+ @executable_name = executable_name
44
+ command = create_command_map commands, subcommand_classes
45
+
46
+ help = create_completion_string(read_template(:bash, :help), binding)
47
+ builder = map_to_completion_string [command], style: :bash
48
+ completion = ''
49
+ completion += builder
50
+ completion += help
51
+ completion += "complete -F _#{executable_name} #{executable_name}\n"
52
+ completion
53
+ end
54
+
35
55
  private
36
56
 
37
57
  # Takes a list of [ParsedCommand]s and [ParsedSubcommand]s
@@ -49,17 +69,14 @@ module Fylla
49
69
  # "_sub1_sub2_sub3"
50
70
  # @param class_options [List<Thor::Option>]
51
71
  # a list of global or class level options for the current context
52
- # @param executable_name [String] the executable name, for use in
53
- # method calls and to name the completion script.
54
72
  def map_to_completion_string(commands,
55
- context = '',
56
- class_options = [],
57
- executable_name = '',
58
- style = :zsh)
73
+ context: '',
74
+ class_options: [],
75
+ style: :zsh)
59
76
  builder = ''
60
77
  commands.each do |command|
61
78
  context_name = generate_context_name(context, command)
62
- result = generate_completion_string(command, class_options, context_name, executable_name, style)
79
+ result = generate_completion_string(command, class_options, context_name, style)
63
80
  builder += result
64
81
  end
65
82
  builder
@@ -80,11 +97,15 @@ module Fylla
80
97
  "#{context}#{command_name}"
81
98
  end
82
99
 
83
- def generate_completion_string(command, class_options, context_name, executable_name, style)
100
+ def generate_completion_string(command, class_options, context_name, style)
84
101
  builder = ''
85
102
  if command.is_a? ParsedSubcommand
86
103
  class_options = (class_options + command.class_options).uniq
87
- builder += map_to_completion_string(command.commands, context_name, class_options, executable_name)
104
+ builder += map_to_completion_string(command.commands,
105
+ context: context_name,
106
+ class_options: class_options,
107
+ style: style)
108
+
88
109
  builder += create_completion_string(read_template(style, :subcommand), binding)
89
110
  else
90
111
  builder += create_completion_string(read_template(style, :command), binding)
@@ -125,7 +146,7 @@ module Fylla
125
146
  # (see #recursively_find_commands) for more documentation
126
147
  def create_command_map(command_map, subcommand_map)
127
148
  command_map = recursively_find_commands command_map, subcommand_map
128
- ParsedSubcommand.new(nil, '', command_map, [])
149
+ ParsedSubcommand.new(nil, '', command_map, class_options.values)
129
150
  end
130
151
 
131
152
  # Helper method to load an [ERB] template
@@ -0,0 +1,5 @@
1
+ _<%= @executable_name %><%= context_name %> ()
2
+ {
3
+ local cur="${COMP_WORDS[COMP_CWORD]}"
4
+ COMPREPLY=($(compgen -W "<%= command.options.map(&:switch_name).join(" ") %> --help -h" -- "$cur"))
5
+ }
File without changes
@@ -0,0 +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,4 +1,4 @@
1
- function _<%= executable_name %><%= context_name %> {
1
+ function _<%= @executable_name %><%= context_name %> {
2
2
  _arguments \
3
3
  <%- unless command.options.nil? -%>
4
4
  <%- command.options.each do |option| -%>
@@ -1,4 +1,4 @@
1
- function _<%= executable_name %>_help {
1
+ function _<%= @executable_name %>_help {
2
2
  <%- unless command.commands.empty? %>
3
3
  function _commands {
4
4
  local -a commands
@@ -1,4 +1,4 @@
1
- function _<%= executable_name %><%= context_name %> {
1
+ function _<%= @executable_name %><%= context_name %> {
2
2
  local line
3
3
  <%- unless command.commands.empty? %>
4
4
  function _commands {
@@ -28,7 +28,7 @@ function _<%= executable_name %><%= context_name %> {
28
28
  case $line[1] in
29
29
  <%- command.commands.each do |command| -%>
30
30
  <%= command.name %>)
31
- _<%= executable_name %><%= context_name %>_<%= command.name %>
31
+ _<%= @executable_name %><%= context_name %>_<%= command.name %>
32
32
  ;;
33
33
  <%- end -%>
34
34
  esac
data/lib/fylla/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Fylla
2
- VERSION = '0.1.0'.freeze
2
+ VERSION = '0.2.0'.freeze
3
3
  end
data/lib/fylla.rb CHANGED
@@ -9,12 +9,29 @@ require 'thor'
9
9
  # Contains one method for initializing Fylla
10
10
  #
11
11
  module Fylla
12
+ #
13
+ # this method initializes [Fylla]
14
+ # Call this _before_ #Thor.start is called.
12
15
  def self.load(executable_name = nil)
13
16
  @executable_name = executable_name || nil
14
17
  ::Thor.prepend Fylla::Thor::CompletionGenerator
15
18
  end
16
19
 
20
+ #
21
+ # @param binding [Binding] _must always be self_
22
+ # @param executable_name [String] name of your thor executable,
23
+ # must either be provided through #self.load or here.
24
+ # @return [String] containing the entire zsh completion script.
17
25
  def self.zsh_completion(binding, executable_name = @executable_name)
18
26
  binding.class.zsh_completion(executable_name)
19
27
  end
28
+
29
+ #
30
+ # @param binding [Binding] _must always be self_
31
+ # @param executable_name [String] name of your thor executable,
32
+ # must either be provided through #self.load or here.
33
+ # @return [String] containing the entire bash completion script.
34
+ def self.bash_completion(binding, executable_name = @executable_name)
35
+ binding.class.bash_completion(executable_name)
36
+ end
20
37
  end
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.1.0
4
+ version: 0.2.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-01-12 00:00:00.000000000 Z
11
+ date: 2019-01-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -24,6 +24,20 @@ dependencies:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
26
  version: '2.0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: codecov
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: 0.1.14
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: 0.1.14
27
41
  - !ruby/object:Gem::Dependency
28
42
  name: minitest
29
43
  requirement: !ruby/object:Gem::Requirement
@@ -80,8 +94,7 @@ dependencies:
80
94
  - - ">="
81
95
  - !ruby/object:Gem::Version
82
96
  version: 0.19.0
83
- description: "\n Fylla generates zsh and bash autocomplete scripts for Thor CLI applications.\n
84
- \ "
97
+ description: Fylla generates zsh and bash autocomplete scripts for Thor CLI applications.
85
98
  email:
86
99
  - tyler.b.thrailkill@gmail.com
87
100
  executables:
@@ -98,6 +111,9 @@ files:
98
111
  - fylla.gemspec
99
112
  - lib/fylla.rb
100
113
  - lib/fylla/completion_generator.rb
114
+ - lib/fylla/erb_templates/bash/command.erb
115
+ - lib/fylla/erb_templates/bash/help.erb
116
+ - lib/fylla/erb_templates/bash/subcommand.erb
101
117
  - lib/fylla/erb_templates/zsh/command.erb
102
118
  - lib/fylla/erb_templates/zsh/help.erb
103
119
  - lib/fylla/erb_templates/zsh/subcommand.erb