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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 0c0b0a7f5f6649588679a69a1173b3fbb8908cc7
4
- data.tar.gz: b71f5389f97fd747ed80973fbf14993ffc88cc4d
3
+ metadata.gz: a46d790507da9bae22ff058b3b331394779c4184
4
+ data.tar.gz: 53f2fbfe3332fe588fbbb1a51d98ac51ba742114
5
5
  SHA512:
6
- metadata.gz: 23f12ce391adccd268f03d11fbcf48496956b9f4428f95cf31591e3456c111edd9c72f3330c724f48e1c253e0c5a4a09b29a45295453797524ae4d821ae119b4
7
- data.tar.gz: c22ce281321e342ae0345a051eadd38cb2d0563f3e1bcc240321ec3de3262bbf95bd411bef116f6931586cbb619ab9997bda8f7c8e219c42b0b7092313987e63
6
+ metadata.gz: ea7efdbb08074d45e324af4ab2476b9a43eee619d59458730eae86c49d14f6384d8a66fecf4602494c7a2e71b1cd67600c177c13da325dc987b97b00ba0f2f92
7
+ data.tar.gz: 0e4ea217d63327d68e94d63ea4107553200b7e4d2997b7ca382d16a8765df88b78f2803df5cd68265fcf35782904dc0cc9a2c4290100b9e9c4f892bbca51c3e4
@@ -7,9 +7,9 @@ module Shelldon
7
7
  end
8
8
 
9
9
  def set_proc
10
- @comp = proc { |s| auto_comp.grep(/^#{Regexp.escape(s)}/) }
11
- Readline.completion_append_character = ' '
12
- Readline.completion_proc = @comp
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 = @shell.command_list.commands.map(&:to_s)
22
- length = buf.split(' ').length
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(buf)
26
+ cmd, = @shell.command_list.find(last_command)
25
27
  return [] unless cmd
26
- remainder = buf.gsub("#{cmd.christian_name} ", '')
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
@@ -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 = [tokens] unless tokens.is_a?(Array)
46
+ tokens = [tokens] unless tokens.is_a?(Array)
45
47
  Timeout.timeout(timeout_length, Shelldon::TimeoutError) do
46
- instance_exec(tokens.join(' '), &@action)
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 += instance_exec(buf, &@autocomplete) if @autocomplete
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
@@ -21,14 +21,13 @@ module Shelldon
21
21
  @default_command = cmd
22
22
  end
23
23
 
24
- def run(str)
25
- cmd, tokens = find(str)
24
+ def run(tokens)
25
+ cmd, tokens = find(tokens)
26
26
  cmd.run(tokens)
27
27
  end
28
28
 
29
- def find(str)
30
- tokens = str.split(' ')
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 = { command: cmd.christian_name }
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 = [compile_help(cmd).values]
59
+ res = [compile_help(cmd).values]
61
60
  res << subcommands unless subcommands.empty?
62
61
  res
63
62
  else
@@ -0,0 +1,5 @@
1
+ class String
2
+ def start_and_end_with?(str)
3
+ self.start_with?(str) && self.end_with?(str)
4
+ end
5
+ end
@@ -149,11 +149,12 @@ module Shelldon
149
149
  end
150
150
 
151
151
  def run_commands(commands)
152
- commands.split(';').each { |cmd| run_command(cmd) }
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 = Logger.new(filepath, freq)
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 = Shelldon::ErrorFactory.new(&block)
229
+ error_factory = Shelldon::ErrorFactory.new(&block)
229
230
  @accept_errors, @reject_errors = error_factory.get
230
- @on_accept_error = error_factory.on_accept_error
231
- @on_reject_error = error_factory.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)
@@ -5,6 +5,7 @@ require 'getopt/long'
5
5
  require 'yaml'
6
6
  require 'fuzzy_match'
7
7
  require 'index'
8
+ require 'patches/string_patches'
8
9
  require 'shell/shell_index'
9
10
  require 'shell/shell_factory_index'
10
11
  require 'dsl'
@@ -1,3 +1,3 @@
1
1
  module Shelldon
2
- VERSION = '0.0.8'
2
+ VERSION = '0.0.9'
3
3
  end
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.8
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-09-24 00:00:00.000000000 Z
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