simple-cli 0.1.1 → 0.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.rubocop.yml +9 -0
- data/Gemfile.lock +17 -1
- data/Rakefile +2 -2
- data/lib/simple/cli/helpers.rb +5 -5
- data/lib/simple/cli/logger.rb +1 -1
- data/lib/simple/cli/runner/autocompletion.rb +27 -24
- data/lib/simple/cli/runner/command_help.rb +17 -15
- data/lib/simple/cli/runner.rb +17 -11
- data/lib/simple/cli/version.rb +1 -1
- data/lib/simple-cli.rb +1 -0
- data/simple-cli.gemspec +1 -0
- metadata +15 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1d1cca86fa6b4673bc090dfbbe4ceec9f64a9ab3
|
4
|
+
data.tar.gz: deec7baa1fb6c0813f6cd957f162c2df880f2d0b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f905d9b12e0fe61077e78b7ba6e682dc7a4f40ae07b1fff07c17f64fd4e80d2b3c478bdb1a8beb5cde07f7e9d2f5ef57f6dbf8f311b77f5df7575fa26e6dcdb2
|
7
|
+
data.tar.gz: c01ea85117b23c6dfc08c63bbc355abe1b180ae1cfb80ed2acf6f217dc5a4cecc3f1e3689c4505748db8ffc3817c51cafdee3086a92a5add1f7a6432582d9b49
|
data/.rubocop.yml
CHANGED
@@ -15,6 +15,9 @@ Metrics/LineLength:
|
|
15
15
|
Style/SpecialGlobalVars:
|
16
16
|
Enabled: false
|
17
17
|
|
18
|
+
Style/PerlBackrefs:
|
19
|
+
Enabled: false
|
20
|
+
|
18
21
|
Style/StringLiterals:
|
19
22
|
EnforcedStyle: double_quotes
|
20
23
|
ConsistentQuotesInMultiline: false
|
@@ -33,3 +36,9 @@ Style/Documentation:
|
|
33
36
|
|
34
37
|
Style/MutableConstant:
|
35
38
|
Enabled: false
|
39
|
+
|
40
|
+
Lint/MissingCopEnableDirective:
|
41
|
+
Enabled: false
|
42
|
+
|
43
|
+
Style/RegexpLiteral:
|
44
|
+
Enabled: false
|
data/Gemfile.lock
CHANGED
@@ -1,14 +1,20 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
simple-cli (0.1.
|
4
|
+
simple-cli (0.1.2)
|
5
5
|
|
6
6
|
GEM
|
7
7
|
remote: https://rubygems.org/
|
8
8
|
specs:
|
9
|
+
ast (2.3.0)
|
9
10
|
diff-lcs (1.3)
|
10
11
|
docile (1.1.5)
|
11
12
|
json (2.1.0)
|
13
|
+
parallel (1.12.1)
|
14
|
+
parser (2.4.0.2)
|
15
|
+
ast (~> 2.3)
|
16
|
+
powerpack (0.1.1)
|
17
|
+
rainbow (3.0.0)
|
12
18
|
rake (11.3.0)
|
13
19
|
rspec (3.7.0)
|
14
20
|
rspec-core (~> 3.7.0)
|
@@ -23,11 +29,20 @@ GEM
|
|
23
29
|
diff-lcs (>= 1.2.0, < 2.0)
|
24
30
|
rspec-support (~> 3.7.0)
|
25
31
|
rspec-support (3.7.0)
|
32
|
+
rubocop (0.52.1)
|
33
|
+
parallel (~> 1.10)
|
34
|
+
parser (>= 2.4.0.2, < 3.0)
|
35
|
+
powerpack (~> 0.1)
|
36
|
+
rainbow (>= 2.2.2, < 4.0)
|
37
|
+
ruby-progressbar (~> 1.7)
|
38
|
+
unicode-display_width (~> 1.0, >= 1.0.1)
|
39
|
+
ruby-progressbar (1.9.0)
|
26
40
|
simplecov (0.15.1)
|
27
41
|
docile (~> 1.1.0)
|
28
42
|
json (>= 1.8, < 3)
|
29
43
|
simplecov-html (~> 0.10.0)
|
30
44
|
simplecov-html (0.10.2)
|
45
|
+
unicode-display_width (1.3.0)
|
31
46
|
|
32
47
|
PLATFORMS
|
33
48
|
ruby
|
@@ -35,6 +50,7 @@ PLATFORMS
|
|
35
50
|
DEPENDENCIES
|
36
51
|
rake (~> 11)
|
37
52
|
rspec (~> 3.7)
|
53
|
+
rubocop (= 0.52.1)
|
38
54
|
simple-cli!
|
39
55
|
simplecov (~> 0)
|
40
56
|
|
data/Rakefile
CHANGED
data/lib/simple/cli/helpers.rb
CHANGED
@@ -42,7 +42,7 @@ module Simple::CLI::Helpers
|
|
42
42
|
class Command
|
43
43
|
def initialize(cmd, *args)
|
44
44
|
@cmd = cmd
|
45
|
-
@args = [
|
45
|
+
@args = [cmd] + args
|
46
46
|
end
|
47
47
|
|
48
48
|
def sh
|
@@ -54,10 +54,10 @@ module Simple::CLI::Helpers
|
|
54
54
|
def run
|
55
55
|
STDERR.puts "> #{self}"
|
56
56
|
rv = if @args.length > 1
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
57
|
+
system to_s
|
58
|
+
else
|
59
|
+
system @args.first
|
60
|
+
end
|
61
61
|
|
62
62
|
@process_status = $?
|
63
63
|
rv
|
data/lib/simple/cli/logger.rb
CHANGED
@@ -13,7 +13,7 @@ module Simple::CLI::Logger
|
|
13
13
|
|
14
14
|
def build_default_logger
|
15
15
|
logger = Logger.new(STDOUT)
|
16
|
-
logger.formatter = proc do |severity,
|
16
|
+
logger.formatter = proc do |severity, _datetime, _progname, msg|
|
17
17
|
"#{severity}: #{msg}\n"
|
18
18
|
end
|
19
19
|
logger.level = Logger::INFO
|
@@ -1,13 +1,16 @@
|
|
1
1
|
module Simple::CLI::Runner::Autocompletion
|
2
2
|
CommandHelp = Simple::CLI::Runner::CommandHelp
|
3
3
|
|
4
|
-
def autocomplete(subcommand=nil, cur=nil)
|
5
|
-
completions
|
4
|
+
def autocomplete(subcommand = nil, cur = nil)
|
5
|
+
puts completions(subcommand, cur).join("\n")
|
6
|
+
end
|
7
|
+
|
8
|
+
def completions(subcommand = nil, cur = nil)
|
9
|
+
if !cur
|
6
10
|
autocomplete_subcommands(subcommand)
|
7
11
|
else
|
8
12
|
autocomplete_subcommand_options(subcommand, cur)
|
9
13
|
end
|
10
|
-
puts completions.join("\n")
|
11
14
|
end
|
12
15
|
|
13
16
|
def filter_completions(completions, prefix:)
|
@@ -18,7 +21,7 @@ module Simple::CLI::Runner::Autocompletion
|
|
18
21
|
|
19
22
|
def autocomplete_subcommands(cur)
|
20
23
|
completions = filter_completions commands.map(&:to_s), prefix: cur
|
21
|
-
if completions == [
|
24
|
+
if completions == [cur]
|
22
25
|
autocomplete_subcommand_options(cur, nil)
|
23
26
|
else
|
24
27
|
completions
|
@@ -27,19 +30,19 @@ module Simple::CLI::Runner::Autocompletion
|
|
27
30
|
|
28
31
|
def autocomplete_subcommand_options(subcommand, cur)
|
29
32
|
completions = if subcommand == "help"
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
33
|
+
commands.map(&:to_s) + ["autocomplete"]
|
34
|
+
else
|
35
|
+
CommandHelp.option_names(@app, subcommand)
|
36
|
+
end
|
34
37
|
|
35
38
|
filter_completions completions, prefix: cur
|
36
39
|
end
|
37
40
|
|
38
41
|
def autocomplete_help
|
39
42
|
STDERR.puts <<~DOC
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
+
#{binary_name} supports autocompletion. To enable autocompletion please run
|
44
|
+
|
45
|
+
eval "$(#{$0} autocomplete:bash)"
|
43
46
|
DOC
|
44
47
|
|
45
48
|
exit 1
|
@@ -61,20 +64,20 @@ module Simple::CLI::Runner::Autocompletion
|
|
61
64
|
# see https://www.gnu.org/software/bash/manual/html_node/Programmable-Completion-Builtins.html
|
62
65
|
#
|
63
66
|
AUTOCOMPLETE_SHELL_CODE = <<~BASH
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
67
|
+
_{{BINARY}}()
|
68
|
+
{
|
69
|
+
local cmd=$1
|
70
|
+
local cur=$2
|
68
71
|
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
72
|
+
if [[ $COMP_CWORD == 1 ]]; then
|
73
|
+
COMPREPLY=( $("$cmd" autocomplete "$cur" ))
|
74
|
+
else
|
75
|
+
local subcommand=${COMP_WORDS[1]}
|
76
|
+
COMPREPLY=( $("$cmd" autocomplete "$subcommand" "$cur" ))
|
77
|
+
fi
|
75
78
|
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
+
return 0
|
80
|
+
}
|
81
|
+
complete -F _{{BINARY}} {{BINARY}}
|
79
82
|
BASH
|
80
83
|
end
|
@@ -1,3 +1,7 @@
|
|
1
|
+
# rubocop:disable Metrics/AbcSize
|
2
|
+
# rubocop:disable Metrics/CyclomaticComplexity
|
3
|
+
# rubocop:disable Metrics/MethodLength
|
4
|
+
|
1
5
|
class Simple::CLI::Runner::CommandHelp
|
2
6
|
def self.option_names(app, subcommand)
|
3
7
|
new(app, subcommand).option_names
|
@@ -6,7 +10,8 @@ class Simple::CLI::Runner::CommandHelp
|
|
6
10
|
end
|
7
11
|
|
8
12
|
def initialize(mod, method)
|
9
|
-
@mod
|
13
|
+
@mod = mod
|
14
|
+
@method = method
|
10
15
|
end
|
11
16
|
|
12
17
|
# First line of the help as read from the method comments.
|
@@ -22,14 +27,16 @@ class Simple::CLI::Runner::CommandHelp
|
|
22
27
|
def option_names
|
23
28
|
method = @mod.instance_method(@method)
|
24
29
|
|
25
|
-
method.parameters.map do |mode, name|
|
30
|
+
option_names = method.parameters.map do |mode, name|
|
26
31
|
case mode
|
27
32
|
when :key then name
|
28
33
|
when :keyreq then name
|
29
34
|
end
|
30
|
-
end.compact
|
31
|
-
|
32
|
-
|
35
|
+
end.compact
|
36
|
+
|
37
|
+
option_names.map do |name|
|
38
|
+
["--#{name}", "--#{name}="]
|
39
|
+
end.flatten
|
33
40
|
end
|
34
41
|
|
35
42
|
# A help string constructed from the commands method signature.
|
@@ -71,7 +78,6 @@ class Simple::CLI::Runner::CommandHelp
|
|
71
78
|
case line
|
72
79
|
when /^\s*# ?(.*)$/ then $1
|
73
80
|
when /^\s*end/ then :end
|
74
|
-
else nil
|
75
81
|
end
|
76
82
|
end
|
77
83
|
end
|
@@ -82,22 +88,18 @@ class Simple::CLI::Runner::CommandHelp
|
|
82
88
|
# go down from before_line until we see a line which is either a comment
|
83
89
|
# or an :end. Note that the line at before_line-1 should be the first
|
84
90
|
# line of the method definition in question.
|
85
|
-
last_line = before_line-1
|
86
|
-
while last_line >= 0 && !parsed_source[last_line]
|
87
|
-
last_line -= 1
|
88
|
-
end
|
91
|
+
last_line = before_line - 1
|
92
|
+
last_line -= 1 while last_line >= 0 && !parsed_source[last_line]
|
89
93
|
|
90
94
|
first_line = last_line
|
91
|
-
while first_line >= 0 && parsed_source[first_line]
|
92
|
-
first_line -= 1
|
93
|
-
end
|
95
|
+
first_line -= 1 while first_line >= 0 && parsed_source[first_line]
|
94
96
|
first_line += 1
|
95
97
|
|
96
|
-
comments = parsed_source[first_line
|
98
|
+
comments = parsed_source[first_line..last_line]
|
97
99
|
if comments.include?(:end)
|
98
100
|
[]
|
99
101
|
else
|
100
|
-
parsed_source[first_line
|
102
|
+
parsed_source[first_line..last_line]
|
101
103
|
end
|
102
104
|
end
|
103
105
|
end
|
data/lib/simple/cli/runner.rb
CHANGED
@@ -1,3 +1,9 @@
|
|
1
|
+
# rubocop:disable Metrics/AbcSize
|
2
|
+
# rubocop:disable Metrics/ClassLength
|
3
|
+
# rubocop:disable Metrics/CyclomaticComplexity
|
4
|
+
# rubocop:disable Metrics/MethodLength
|
5
|
+
# rubocop:disable Metrics/PerceivedComplexity
|
6
|
+
|
1
7
|
class Simple::CLI::Runner
|
2
8
|
end
|
3
9
|
|
@@ -38,9 +44,9 @@ class Simple::CLI::Runner
|
|
38
44
|
if command == :help
|
39
45
|
do_help!(*args)
|
40
46
|
elsif command == :autocomplete
|
41
|
-
autocomplete
|
47
|
+
autocomplete(*args)
|
42
48
|
elsif command == :autocomplete_bash
|
43
|
-
autocomplete_bash
|
49
|
+
autocomplete_bash(*args)
|
44
50
|
elsif commands.include?(command)
|
45
51
|
@instance.run! command, *args_with_options(args)
|
46
52
|
else
|
@@ -90,7 +96,7 @@ class Simple::CLI::Runner
|
|
90
96
|
def args_with_options(args)
|
91
97
|
r = []
|
92
98
|
options = {}
|
93
|
-
while arg = args.shift
|
99
|
+
while (arg = args.shift)
|
94
100
|
case arg
|
95
101
|
when /^--(.*)=(.*)/ then options[$1.to_sym] = $2
|
96
102
|
when /^--no-(.*)/ then options[$1.to_sym] = false
|
@@ -104,11 +110,11 @@ class Simple::CLI::Runner
|
|
104
110
|
end
|
105
111
|
|
106
112
|
def command_to_string(sym)
|
107
|
-
sym.to_s.
|
113
|
+
sym.to_s.tr("_", ":")
|
108
114
|
end
|
109
115
|
|
110
116
|
def string_to_command(s)
|
111
|
-
s.
|
117
|
+
s.tr(":", "_").to_sym
|
112
118
|
end
|
113
119
|
|
114
120
|
def commands
|
@@ -138,20 +144,20 @@ class Simple::CLI::Runner
|
|
138
144
|
|
139
145
|
commands.sort.each do |sym|
|
140
146
|
command_help = command_helps.fetch(sym)
|
141
|
-
command_help = "%-#{max_command_helps_length}s"
|
147
|
+
command_help = format("%-#{max_command_helps_length}s", command_help)
|
142
148
|
edoc = CommandHelp.new(@app, sym)
|
143
149
|
head = "# #{edoc.head}" if edoc.head
|
144
|
-
STDERR.puts " #{command_help} #{
|
150
|
+
STDERR.puts " #{command_help} #{head}"
|
145
151
|
end
|
146
152
|
|
147
153
|
STDERR.puts "\n"
|
148
154
|
|
149
155
|
STDERR.puts <<~DOC
|
150
|
-
|
156
|
+
Default options include:
|
151
157
|
|
152
|
-
|
153
|
-
|
154
|
-
|
158
|
+
#{binary_name} [ --verbose | -v ] # run on DEBUG log level
|
159
|
+
#{binary_name} [ --quiet | -q ] # run on WARN log level
|
160
|
+
#{binary_name} help autocomplete # print information on autocompletion.
|
155
161
|
|
156
162
|
DOC
|
157
163
|
|
data/lib/simple/cli/version.rb
CHANGED
data/lib/simple-cli.rb
CHANGED
data/simple-cli.gemspec
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: simple-cli
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- radiospiel
|
@@ -53,6 +53,20 @@ dependencies:
|
|
53
53
|
- - "~>"
|
54
54
|
- !ruby/object:Gem::Version
|
55
55
|
version: '0'
|
56
|
+
- !ruby/object:Gem::Dependency
|
57
|
+
name: rubocop
|
58
|
+
requirement: !ruby/object:Gem::Requirement
|
59
|
+
requirements:
|
60
|
+
- - '='
|
61
|
+
- !ruby/object:Gem::Version
|
62
|
+
version: 0.52.1
|
63
|
+
type: :development
|
64
|
+
prerelease: false
|
65
|
+
version_requirements: !ruby/object:Gem::Requirement
|
66
|
+
requirements:
|
67
|
+
- - '='
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: 0.52.1
|
56
70
|
description: Simple CLI builder
|
57
71
|
email: eno@radiospiel.org
|
58
72
|
executables: []
|