fylla 0.4.3 → 0.5.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/fylla.rb +2 -0
- data/lib/fylla/completion_extension.rb +8 -4
- data/lib/fylla/completion_generator.rb +2 -1
- data/lib/fylla/erb_templates/zsh/command.erb +17 -7
- data/lib/fylla/erb_templates/zsh/subcommand.erb +21 -19
- data/lib/fylla/parsed_option.rb +4 -2
- data/lib/fylla/thor/extensions/comma_array_extension.rb +21 -0
- data/lib/fylla/version.rb +1 -1
- metadata +3 -3
- data/lib/fylla/thor/extensions/ShellDescriptionExtension.rb +0 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 14e4ab52af2d12b3d0078c3c0451da1a28c0e795c06b9e9867f6188e849c304a
|
4
|
+
data.tar.gz: 8267d2624d22df38cdce36e8b9f245458ec43b6659634e02a5970eaa099fef21
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0ff83b9fcc93795be5fc9feadc6dc4cc04cf3fbc178a6430a7f2602e2363d7d0ab5961430f78da4bad91957846690b648638e317ac019f272e5d184272a79971
|
7
|
+
data.tar.gz: f92146028038df7a651eb82579bc5dc437032fb554e1518290cc2f9c40319fd43fa8204bb914b0e4c8bbf0c9c46db09dc9e7da28c8a444e465b4d4b998b0061b
|
data/lib/fylla.rb
CHANGED
@@ -3,10 +3,12 @@ require 'fylla/completion_generator'
|
|
3
3
|
require 'fylla/parsed_command'
|
4
4
|
require 'fylla/parsed_subcommand'
|
5
5
|
require 'fylla/completion_extension'
|
6
|
+
require 'fylla/thor/extensions/comma_array_extension'
|
6
7
|
require 'thor'
|
7
8
|
|
8
9
|
# We _must prepend before thor loads_ Ideally this is at require time...
|
9
10
|
::Thor::Option.prepend Fylla::Thor::Option
|
11
|
+
::Thor::Arguments.prepend Fylla::Thor::Arguments
|
10
12
|
|
11
13
|
#
|
12
14
|
# Top level module for the Fylla project.
|
@@ -1,13 +1,17 @@
|
|
1
1
|
require 'thor'
|
2
2
|
|
3
|
-
# add
|
4
|
-
#
|
3
|
+
# add more options to Thor::Option
|
4
|
+
#
|
5
|
+
# :completion => allows providing a custom completion description for zsh
|
6
|
+
# :filter => allows filtering completions for arrays based on past completions
|
5
7
|
module Fylla
|
6
8
|
module Thor
|
7
9
|
module Option
|
8
|
-
attr_accessor :completion
|
10
|
+
attr_accessor :completion, :filter
|
9
11
|
def initialize(name, options = {})
|
10
|
-
@completion = options[:completion
|
12
|
+
@completion = options[:fylla]&.[](:completion)
|
13
|
+
@filter = options[:fylla]&.[](:filter)
|
14
|
+
@filter = true if @filter.nil?
|
11
15
|
super
|
12
16
|
end
|
13
17
|
end
|
@@ -29,6 +29,7 @@ module Fylla
|
|
29
29
|
builder = map_to_completion_string [command]
|
30
30
|
completion = "#compdef _#{executable_name} #{executable_name}\n"
|
31
31
|
completion += builder
|
32
|
+
completion += %Q(_#{executable_name} "$@")
|
32
33
|
completion
|
33
34
|
end
|
34
35
|
|
@@ -175,7 +176,7 @@ module Fylla
|
|
175
176
|
def parse_options(options)
|
176
177
|
options.map do |opt|
|
177
178
|
description = opt.completion || opt.description || opt.banner || opt.name.to_s.upcase
|
178
|
-
ParsedOption.new(opt.name, description, opt.aliases)
|
179
|
+
ParsedOption.new(opt.name, description, opt.aliases, opt.enum, opt.filter)
|
179
180
|
end
|
180
181
|
end
|
181
182
|
end
|
@@ -2,14 +2,24 @@ function _<%= @executable_name %><%= context_name %> {
|
|
2
2
|
_arguments \
|
3
3
|
<%- unless command.options.nil? -%>
|
4
4
|
<%- command.options.each do |option| -%>
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
5
|
+
<%- enums_exist = option.enum -%>
|
6
|
+
<%- filtered = option.filter -%>
|
7
|
+
<%- desc = option.description.gsub('"', %q|\\"|) -%>
|
8
|
+
<%- if enums_exist -%>
|
9
|
+
<%- if filtered -%>
|
10
|
+
<%- actions = ": :_values -s , 'options' #{option.enum.join(' ')}" -%>
|
11
|
+
<%- else -%>
|
12
|
+
<%- actions = ": :_sequence -d compadd - #{option.enum.join(' ')}" -%>
|
13
|
+
<%- end -%>
|
14
|
+
"--<%= option.name %>=[<%= desc %>]<%= actions %>" \
|
15
|
+
<%- else -%>
|
16
|
+
"--<%= option.name %>[<%= desc %>]" \
|
17
|
+
<%- end -%>
|
18
|
+
<%- option.aliases.each do |al| -%>
|
19
|
+
"-<%= al %><%= option.enum ? '=' : '' %>[<%= desc %>]<%= option.enum ? actions : '' %>" \
|
20
|
+
<%- end -%>
|
9
21
|
<%- end -%>
|
10
22
|
<%- end -%>
|
11
23
|
"-h[Show help information]" \
|
12
|
-
"--help[Show help information]"
|
13
|
-
"1: :_commands" \
|
14
|
-
"*::arg:->args"/.
|
24
|
+
"--help[Show help information]"
|
15
25
|
}
|
@@ -1,35 +1,37 @@
|
|
1
1
|
function _<%= @executable_name %><%= context_name %> {
|
2
2
|
local line
|
3
3
|
<%- unless command.commands.empty? %>
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
)
|
12
|
-
_describe 'command' commands
|
13
|
-
}
|
4
|
+
local -a commands
|
5
|
+
commands=(
|
6
|
+
<%-# remove newlines and leading space on this loop -%>
|
7
|
+
<%- command.commands.sort_by(&:name).each do |command| -%>
|
8
|
+
'<%= command.name %>:<%= command.description.gsub("'", %q|'"'"'|) %>'
|
9
|
+
<%- end -%>
|
10
|
+
)
|
14
11
|
<%- end %>
|
15
12
|
_arguments \
|
16
13
|
<%- unless class_options.nil? -%>
|
17
14
|
<%- class_options.each do |option| -%>
|
18
15
|
<%- option.aliases.each do |al| -%>
|
19
|
-
"-<%= al
|
16
|
+
"-<%= al %>[<%= option.description.gsub('"', %q|\\"|) %>]" \
|
20
17
|
<%- end -%>
|
21
|
-
"--<%= option.name
|
18
|
+
"--<%= option.name %>[<%= option.description.gsub('"', %q|\\"|) %>]" \
|
22
19
|
<%- end -%>
|
23
20
|
<%- end -%>
|
24
21
|
"-h[Show help information]" \
|
25
22
|
"--help[Show help information]" \
|
26
|
-
"1: :
|
27
|
-
"*::arg:->args"
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
23
|
+
"1: : _describe 'command' commands" \
|
24
|
+
"*::arg:->args"
|
25
|
+
|
26
|
+
case $state in
|
27
|
+
args)
|
28
|
+
case $line[1] in
|
29
|
+
<%- command.commands.sort_by(&:name).each do |command| -%>
|
30
|
+
<%= command.name %>)
|
31
|
+
_<%= @executable_name %><%= context_name %>_<%= command.name %>
|
32
|
+
;;
|
33
|
+
<%- end -%>
|
34
|
+
esac
|
32
35
|
;;
|
33
|
-
<%- end -%>
|
34
36
|
esac
|
35
37
|
}
|
data/lib/fylla/parsed_option.rb
CHANGED
@@ -1,12 +1,14 @@
|
|
1
1
|
module Fylla
|
2
2
|
class ParsedOption
|
3
|
-
attr_accessor :aliases, :description, :name
|
3
|
+
attr_accessor :aliases, :description, :name, :enum, :filter
|
4
4
|
attr_reader :completion, :banner # used just for parsing class_options recursively. Don't ever set these.
|
5
5
|
|
6
|
-
def initialize(name, description, aliases)
|
6
|
+
def initialize(name, description, aliases, enum, filter)
|
7
7
|
@name = name
|
8
8
|
@description = description
|
9
9
|
@aliases = aliases
|
10
|
+
@enum = enum || nil
|
11
|
+
@filter = filter
|
10
12
|
end
|
11
13
|
end
|
12
14
|
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
require 'thor'
|
2
|
+
|
3
|
+
# Modify how Thor parses array arguments to be POSIX standard per
|
4
|
+
# getopt_long(3)
|
5
|
+
# @see https://linux.die.net/man/3/getopt_long
|
6
|
+
module Fylla
|
7
|
+
module Thor
|
8
|
+
module Arguments
|
9
|
+
def parse_array(name)
|
10
|
+
return shift if peek.is_a?(Array)
|
11
|
+
array = []
|
12
|
+
if peek.include? ","
|
13
|
+
array.push(*shift.split(","))
|
14
|
+
else
|
15
|
+
array << shift while current_is_value?
|
16
|
+
end
|
17
|
+
array
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
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.5.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-06-
|
11
|
+
date: 2019-06-13 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -119,7 +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/
|
122
|
+
- lib/fylla/thor/extensions/comma_array_extension.rb
|
123
123
|
- lib/fylla/version.rb
|
124
124
|
homepage: https://github.com/snowe2010/fylla
|
125
125
|
licenses:
|
@@ -1 +0,0 @@
|
|
1
|
-
|