shelldon 0.0.8 → 0.0.9
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/auto_complete.rb +9 -11
- data/lib/command/command.rb +20 -4
- data/lib/command/command_list.rb +6 -7
- data/lib/patches/string_patches.rb +5 -0
- data/lib/shell/shell.rb +7 -6
- data/lib/shelldon.rb +1 -0
- data/lib/shelldon/version.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a46d790507da9bae22ff058b3b331394779c4184
|
4
|
+
data.tar.gz: 53f2fbfe3332fe588fbbb1a51d98ac51ba742114
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ea7efdbb08074d45e324af4ab2476b9a43eee619d59458730eae86c49d14f6384d8a66fecf4602494c7a2e71b1cd67600c177c13da325dc987b97b00ba0f2f92
|
7
|
+
data.tar.gz: 0e4ea217d63327d68e94d63ea4107553200b7e4d2997b7ca382d16a8765df88b78f2803df5cd68265fcf35782904dc0cc9a2c4290100b9e9c4f892bbca51c3e4
|
data/lib/auto_complete.rb
CHANGED
@@ -7,9 +7,9 @@ module Shelldon
|
|
7
7
|
end
|
8
8
|
|
9
9
|
def set_proc
|
10
|
-
@comp
|
11
|
-
Readline.completion_append_character
|
12
|
-
Readline.completion_proc
|
10
|
+
@comp = proc { |s| auto_comp.grep(/^#{Regexp.escape(s)}/) }
|
11
|
+
Readline.completion_append_character = ' '
|
12
|
+
Readline.completion_proc = @comp
|
13
13
|
end
|
14
14
|
|
15
15
|
def buf
|
@@ -18,17 +18,15 @@ module Shelldon
|
|
18
18
|
|
19
19
|
def auto_comp
|
20
20
|
Readline.completion_append_character = ' '
|
21
|
-
@commands
|
22
|
-
|
21
|
+
@commands = @shell.command_list.commands.map(&:to_s)
|
22
|
+
last_command = Command.tokenize(buf)
|
23
|
+
last_command = last_command.last if last_command.last.is_a?(Array)
|
24
|
+
length = last_command.length
|
23
25
|
return @commands if length <= 1 && !buf.end_with?(' ')
|
24
|
-
cmd, = @shell.command_list.find(
|
26
|
+
cmd, = @shell.command_list.find(last_command)
|
25
27
|
return [] unless cmd
|
26
|
-
remainder =
|
28
|
+
remainder = last_command.join(' ').gsub("#{cmd.christian_name} ", '')
|
27
29
|
cmd.complete(remainder)
|
28
30
|
end
|
29
|
-
|
30
|
-
def tokenize(str)
|
31
|
-
str.split(' ')
|
32
|
-
end
|
33
31
|
end
|
34
32
|
end
|
data/lib/command/command.rb
CHANGED
@@ -3,6 +3,8 @@ require 'timeout'
|
|
3
3
|
module Shelldon
|
4
4
|
class Command
|
5
5
|
attr_reader :name, :aliases, :subcommands, :parent, :autocomplete, :times_out
|
6
|
+
SINGLE_QUOTE = "'"
|
7
|
+
DOUBLE_QUOTE = '"'
|
6
8
|
|
7
9
|
def initialize(name, parent, &block)
|
8
10
|
@name = name
|
@@ -41,9 +43,9 @@ module Shelldon
|
|
41
43
|
end
|
42
44
|
|
43
45
|
def run(tokens = [])
|
44
|
-
tokens
|
46
|
+
tokens = [tokens] unless tokens.is_a?(Array)
|
45
47
|
Timeout.timeout(timeout_length, Shelldon::TimeoutError) do
|
46
|
-
instance_exec(tokens
|
48
|
+
instance_exec(tokens, &@action)
|
47
49
|
end
|
48
50
|
end
|
49
51
|
|
@@ -122,7 +124,7 @@ module Shelldon
|
|
122
124
|
def complete(buf)
|
123
125
|
length = buf.split(' ').length
|
124
126
|
res = (length <= 1 && !buf.end_with?(' ')) ? subcommand_list : []
|
125
|
-
res
|
127
|
+
res += instance_exec(buf, &@autocomplete) if @autocomplete
|
126
128
|
res
|
127
129
|
end
|
128
130
|
|
@@ -180,9 +182,23 @@ module Shelldon
|
|
180
182
|
if block_given?
|
181
183
|
@autocomplete = block.to_proc
|
182
184
|
else
|
183
|
-
arr
|
185
|
+
arr ||= []
|
184
186
|
@autocomplete = proc { arr }
|
185
187
|
end
|
186
188
|
end
|
189
|
+
|
190
|
+
def self.tokenize(str)
|
191
|
+
statements = str.split(/;(?=(?:[^\"]*\"[^\"]*\")*[^\"]*$)/).map(&:strip)
|
192
|
+
statements.map do |statement|
|
193
|
+
statement.split(/\s(?=(?:[^"]|"[^"]*")*$)/).map do |token|
|
194
|
+
if token.start_and_end_with?(DOUBLE_QUOTE) ||
|
195
|
+
token.start_and_end_with?(SINGLE_QUOTE)
|
196
|
+
|
197
|
+
token = token[1..-2]
|
198
|
+
end
|
199
|
+
token
|
200
|
+
end
|
201
|
+
end
|
202
|
+
end
|
187
203
|
end
|
188
204
|
end
|
data/lib/command/command_list.rb
CHANGED
@@ -21,14 +21,13 @@ module Shelldon
|
|
21
21
|
@default_command = cmd
|
22
22
|
end
|
23
23
|
|
24
|
-
def run(
|
25
|
-
cmd, tokens = find(
|
24
|
+
def run(tokens)
|
25
|
+
cmd, tokens = find(tokens)
|
26
26
|
cmd.run(tokens)
|
27
27
|
end
|
28
28
|
|
29
|
-
def find(
|
30
|
-
|
31
|
-
key = tokens.first.to_sym
|
29
|
+
def find(tokens)
|
30
|
+
key = tokens.first.to_sym
|
32
31
|
if @commands.key?(key)
|
33
32
|
@commands[key].find(tokens[1..-1])
|
34
33
|
else
|
@@ -42,7 +41,7 @@ module Shelldon
|
|
42
41
|
end
|
43
42
|
|
44
43
|
def compile_help(cmd)
|
45
|
-
res = {
|
44
|
+
res = {command: cmd.christian_name}
|
46
45
|
res[:help] = cmd.help if cmd.help
|
47
46
|
res[:usage] = "\"#{cmd.usage}\"" if cmd.usage
|
48
47
|
res[:examples] = cmd.examples if cmd.examples
|
@@ -57,7 +56,7 @@ module Shelldon
|
|
57
56
|
cmd = find(str).first
|
58
57
|
if cmd.show && !is_default?(cmd)
|
59
58
|
subcommands = cmd.sub_to_a
|
60
|
-
res
|
59
|
+
res = [compile_help(cmd).values]
|
61
60
|
res << subcommands unless subcommands.empty?
|
62
61
|
res
|
63
62
|
else
|
data/lib/shell/shell.rb
CHANGED
@@ -149,11 +149,12 @@ module Shelldon
|
|
149
149
|
end
|
150
150
|
|
151
151
|
def run_commands(commands)
|
152
|
-
|
152
|
+
@history_helper << commands if @history_helper
|
153
|
+
commands = Command.tokenize(commands)
|
154
|
+
commands.each { |cmd| run_command(cmd) }
|
153
155
|
end
|
154
156
|
|
155
157
|
def run_command(cmd)
|
156
|
-
@history_helper << cmd if @history_helper
|
157
158
|
run_precommand(cmd)
|
158
159
|
@command_list.run(cmd)
|
159
160
|
run_postcommand(cmd)
|
@@ -193,7 +194,7 @@ module Shelldon
|
|
193
194
|
|
194
195
|
def log_file(filepath, freq = 'daily')
|
195
196
|
filepath = Pathname.new(filepath).expand_path.to_s
|
196
|
-
@logger
|
197
|
+
@logger = Logger.new(filepath, freq)
|
197
198
|
end
|
198
199
|
|
199
200
|
def prompt(str = '> ', &block)
|
@@ -225,10 +226,10 @@ module Shelldon
|
|
225
226
|
end
|
226
227
|
|
227
228
|
def errors(&block)
|
228
|
-
error_factory
|
229
|
+
error_factory = Shelldon::ErrorFactory.new(&block)
|
229
230
|
@accept_errors, @reject_errors = error_factory.get
|
230
|
-
@on_accept_error
|
231
|
-
@on_reject_error
|
231
|
+
@on_accept_error = error_factory.on_accept_error
|
232
|
+
@on_reject_error = error_factory.on_reject_error
|
232
233
|
end
|
233
234
|
|
234
235
|
def autocomplete(&block)
|
data/lib/shelldon.rb
CHANGED
data/lib/shelldon/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: shelldon
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.9
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Wesley Boynton
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-
|
11
|
+
date: 2016-11-12 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: getopt
|
@@ -127,6 +127,7 @@ files:
|
|
127
127
|
- lib/module/module_index.rb
|
128
128
|
- lib/opts/opt_factory.rb
|
129
129
|
- lib/opts/opts.rb
|
130
|
+
- lib/patches/string_patches.rb
|
130
131
|
- lib/shell/shell.rb
|
131
132
|
- lib/shell/shell_factory.rb
|
132
133
|
- lib/shell/shell_factory_index.rb
|