fylla 0.2.0 → 0.3.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: e9146ead4c4c7a8a7d72096188734b6f439ffff2
4
- data.tar.gz: 5533724b62e9c629c99d62f68eb7cf2c55b4dadd
3
+ metadata.gz: 90d49bc51792ace89262f2175d3590427cdb9d92
4
+ data.tar.gz: 9cd74325c692ddce6371ddaea10d4e972ec721e2
5
5
  SHA512:
6
- metadata.gz: ca9a24cb0a6829f9b0c814892c80684eed43a31c9d5d6c64b9d15b031aaa27850a8a53a0143b6da439f4d49b4a18cb6a9e7512272c088fa352a49659fb55a912
7
- data.tar.gz: 737af6d0958eb919b9a8e9d2ec6dfb6e57fea009d337bd66853dee3f7aadbd18365222a4c56a0e93111f8bb5fd99845d22e54a1c95c6d88d0b34ef54892e2a60
6
+ metadata.gz: a53727a1901bbe8cde4260fd3acaa75db30755b8fb8900cdaea12f6980028d9ef66b250ea6bc948b92e43460f3c5eeb27b4bad163d16a0480dbe5dce20876c32
7
+ data.tar.gz: d4adaac549e8dc82aad501442ad406ca8cb3d14594b0a1abb059f0c6b05893808e1d5b9b53bbf1941082936133567632344c6cd5ba682c90b5a42f16fdc1138d
data/fylla.gemspec CHANGED
@@ -15,6 +15,7 @@ Gem::Specification.new do |spec|
15
15
  spec.license = 'MIT'
16
16
 
17
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'
18
19
 
19
20
  # Specify which files should be added to the gem when it is released.
20
21
  # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
@@ -25,7 +26,7 @@ Gem::Specification.new do |spec|
25
26
  end
26
27
 
27
28
  spec.bindir = 'exe'
28
- spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
29
+ spec.executables = spec.files.grep(%r{^exe/}) {|f| File.basename(f)}
29
30
  spec.require_paths = ['lib']
30
31
 
31
32
  spec.add_development_dependency 'bundler', '~> 2.0'
@@ -0,0 +1,21 @@
1
+ require 'thor'
2
+
3
+ class Thor
4
+ class Option
5
+ attr_accessor :completion
6
+ old_initialize = instance_method(:initialize)
7
+ define_method(:initialize) do |name, options = {}|
8
+ old_initialize.bind(self).call(name, options)
9
+ @completion = options[:completion]
10
+ end
11
+ # def initialize(name, options = {})
12
+ # old_initialize
13
+ # end
14
+
15
+ class << self
16
+ def completion(completion)
17
+ @completion = completion
18
+ end
19
+ end
20
+ end
21
+ end
@@ -1,3 +1,4 @@
1
+ require_relative 'parsed_option'
1
2
  require_relative 'parsed_command'
2
3
  require_relative 'parsed_subcommand'
3
4
  require 'erb'
@@ -23,13 +24,11 @@ module Fylla
23
24
  # the name of the executable to generate the script for
24
25
  def zsh_completion(executable_name)
25
26
  @executable_name = executable_name
26
- command = create_command_map commands, subcommand_classes
27
+ command = create_command_map all_commands, subcommand_classes
27
28
 
28
- help = create_completion_string(read_template(:zsh, :help), binding)
29
29
  builder = map_to_completion_string [command]
30
30
  completion = "#compdef _#{executable_name} #{executable_name}\n"
31
31
  completion += builder
32
- completion += help
33
32
  completion
34
33
  end
35
34
 
@@ -41,13 +40,11 @@ module Fylla
41
40
  # the name of the executable to generate the script for
42
41
  def bash_completion(executable_name)
43
42
  @executable_name = executable_name
44
- command = create_command_map commands, subcommand_classes
43
+ command = create_command_map all_commands, subcommand_classes
45
44
 
46
- help = create_completion_string(read_template(:bash, :help), binding)
47
45
  builder = map_to_completion_string [command], style: :bash
48
46
  completion = ''
49
47
  completion += builder
50
- completion += help
51
48
  completion += "complete -F _#{executable_name} #{executable_name}\n"
52
49
  completion
53
50
  end
@@ -125,11 +122,12 @@ module Fylla
125
122
  # @param subcommand_map [Hash<String, Class < Thor>]
126
123
  # a map indicating the subcommands and their respective classes
127
124
  def recursively_find_commands(command_map, subcommand_map)
128
- map = Hash[command_map.map { |k, v| [v, subcommand_map[k]] }]
125
+ map = Hash[command_map.map {|k, v| [v, subcommand_map[k]]}]
129
126
  map.map do |command, subcommand_class|
130
127
  if subcommand_class.nil?
131
128
  ancestor_name = command.ancestor_name if command.respond_to? :ancestor_name
132
- ParsedCommand.new(ancestor_name, command.description, command.name, command.options.values)
129
+ options = parse_options(command.options.values)
130
+ ParsedCommand.new(ancestor_name, command.description, command.name, options)
133
131
  else
134
132
  commands = recursively_find_commands subcommand_class.commands, subcommand_class.subcommand_classes
135
133
  ParsedSubcommand.new(command.name, command.description, commands, subcommand_class.class_options.values)
@@ -163,7 +161,7 @@ module Fylla
163
161
  # from a file and return it as a [String]
164
162
  #
165
163
  # @param name [Symbol] type of template to retrieve
166
- # can be either :help, :subcommand, or :command
164
+ # can be either :subcommand or :command
167
165
  # @param style [Symbol] style of template to retrieve
168
166
  # can be either :zsh or :bash
169
167
  # @return [String] template string retrieved from erb file
@@ -173,6 +171,13 @@ module Fylla
173
171
  erb_path = "erb_templates/#{style}/#{name}.erb"
174
172
  File.read(File.join(__dir__, erb_path))
175
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
176
181
  end
177
182
  end
178
183
  end
@@ -1,5 +1,14 @@
1
1
  _<%= @executable_name %><%= context_name %> ()
2
2
  {
3
3
  local cur="${COMP_WORDS[COMP_CWORD]}"
4
- COMPREPLY=($(compgen -W "<%= command.options.map(&:switch_name).join(" ") %> --help -h" -- "$cur"))
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"))
5
14
  }
@@ -2,8 +2,10 @@ function _<%= @executable_name %><%= context_name %> {
2
2
  _arguments \
3
3
  <%- unless command.options.nil? -%>
4
4
  <%- command.options.each do |option| -%>
5
- "-<%= option.name%>=[<%= option.banner %>]"
6
- "-<%= option.aliases[0]%>=[<%= option.banner %>]"
5
+ "--<%= option.name%>=[<%= option.description %>]" \
6
+ <%- option.aliases.each do |al| -%>
7
+ "-<%= al %>=[<%= option.description %>]" \
8
+ <%- end -%>
7
9
  <%- end -%>
8
10
  <%- end -%>
9
11
  "-h[Show help information]" \
@@ -5,7 +5,7 @@ function _<%= @executable_name %><%= context_name %> {
5
5
  local -a commands
6
6
  commands=(
7
7
  <%-# remove newlines and leading space on this loop -%>
8
- <%- command.commands.each do |command| -%>
8
+ <%- command.commands.sort_by(&:name).each do |command| -%>
9
9
  '<%= command.name %>:<%= command.description %>'
10
10
  <%- end -%>
11
11
  )
@@ -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
- "-<%= al %>=[<%= option.banner %>]"
19
+ "-<%= al %>=[<%= option.description %>]" \
20
20
  <%- end -%>
21
- "--<%= option.name%>=[<%= option.banner %>]"
21
+ "--<%= option.name%>=[<%= option.description %>]" \
22
22
  <%- end -%>
23
23
  <%- end -%>
24
24
  "-h[Show help information]" \
@@ -26,7 +26,7 @@ function _<%= @executable_name %><%= context_name %> {
26
26
  "1: :_commands" \
27
27
  "*::arg:->args"/.
28
28
  case $line[1] in
29
- <%- command.commands.each do |command| -%>
29
+ <%- command.commands.sort_by(&:name).each do |command| -%>
30
30
  <%= command.name %>)
31
31
  _<%= @executable_name %><%= context_name %>_<%= command.name %>
32
32
  ;;
@@ -0,0 +1,11 @@
1
+ module Fylla
2
+ class ParsedOption
3
+ attr_accessor :aliases, :description, :name
4
+
5
+ def initialize(name, description, aliases)
6
+ @name = name
7
+ @description = description
8
+ @aliases = aliases
9
+ end
10
+ end
11
+ end
data/lib/fylla/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Fylla
2
- VERSION = '0.2.0'.freeze
2
+ VERSION = '0.3.0'.freeze
3
3
  end
data/lib/fylla.rb CHANGED
@@ -2,6 +2,7 @@ require 'fylla/version'
2
2
  require 'fylla/completion_generator'
3
3
  require 'fylla/parsed_command'
4
4
  require 'fylla/parsed_subcommand'
5
+ require 'fylla/completion_extension'
5
6
  require 'thor'
6
7
 
7
8
  #
@@ -12,12 +13,16 @@ module Fylla
12
13
  #
13
14
  # this method initializes [Fylla]
14
15
  # Call this _before_ #Thor.start is called.
16
+ # @param executable_name [String] name of your thor executable, must be provided
17
+ # here or through #self.zsh_completion or #self.bash_completion
15
18
  def self.load(executable_name = nil)
16
19
  @executable_name = executable_name || nil
17
20
  ::Thor.prepend Fylla::Thor::CompletionGenerator
21
+ # ::Thor::Option.prepend Fylla::Thor::Option
18
22
  end
19
23
 
20
24
  #
25
+ # Method to generate bash completions for the current [Thor] application
21
26
  # @param binding [Binding] _must always be self_
22
27
  # @param executable_name [String] name of your thor executable,
23
28
  # must either be provided through #self.load or here.
@@ -27,6 +32,7 @@ module Fylla
27
32
  end
28
33
 
29
34
  #
35
+ # Method to generate bash completions for the current [Thor] application
30
36
  # @param binding [Binding] _must always be self_
31
37
  # @param executable_name [String] name of your thor executable,
32
38
  # must either be provided through #self.load or here.
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.2.0
4
+ version: 0.3.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-28 00:00:00.000000000 Z
11
+ date: 2019-02-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -110,14 +110,14 @@ files:
110
110
  - exe/fylla
111
111
  - fylla.gemspec
112
112
  - lib/fylla.rb
113
+ - lib/fylla/completion_extension.rb
113
114
  - lib/fylla/completion_generator.rb
114
115
  - lib/fylla/erb_templates/bash/command.erb
115
- - lib/fylla/erb_templates/bash/help.erb
116
116
  - lib/fylla/erb_templates/bash/subcommand.erb
117
117
  - lib/fylla/erb_templates/zsh/command.erb
118
- - lib/fylla/erb_templates/zsh/help.erb
119
118
  - lib/fylla/erb_templates/zsh/subcommand.erb
120
119
  - lib/fylla/parsed_command.rb
120
+ - lib/fylla/parsed_option.rb
121
121
  - lib/fylla/parsed_subcommand.rb
122
122
  - lib/fylla/version.rb
123
123
  homepage: https://github.com/snowe2010/fylla
@@ -125,6 +125,7 @@ licenses:
125
125
  - MIT
126
126
  metadata:
127
127
  yard.run: yri
128
+ changelog_uri: https://github.com/snowe2010/fylla/blob/master/CHANGELOG.md
128
129
  post_install_message:
129
130
  rdoc_options: []
130
131
  require_paths:
File without changes
@@ -1,19 +0,0 @@
1
- function _<%= @executable_name %>_help {
2
- <%- unless command.commands.empty? %>
3
- function _commands {
4
- local -a commands
5
- commands=(
6
- <%-# remove newlines and leading space on this loop -%>
7
- <%- command.commands.each do |command| -%>
8
- '<%= command.name %>:<%= command.description %>'
9
- <%- end -%>
10
- )
11
- _describe 'command' commands
12
- }
13
- <%- end %>
14
- _arguments \
15
- "-h[Show help information]" \
16
- "--help[Show help information]" \
17
- "1: :_commands" \
18
- "*::arg:->args"/.
19
- }