mysh 0.4.0 → 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/README.md +162 -51
- data/lib/mysh.rb +4 -2
- data/lib/mysh/{external_ruby.rb → external.rb} +6 -7
- data/lib/mysh/handlebars.rb +1 -1
- data/lib/mysh/init.rb +14 -9
- data/lib/mysh/input_wrapper.rb +67 -0
- data/lib/mysh/internal/action.rb +5 -16
- data/lib/mysh/internal/action_pool.rb +1 -1
- data/lib/mysh/internal/actions/cd.rb +8 -15
- data/lib/mysh/internal/actions/command_line.rb +3 -3
- data/lib/mysh/internal/actions/comment.rb +3 -11
- data/lib/mysh/internal/actions/elapsed.rb +9 -16
- data/lib/mysh/internal/actions/exit.rb +4 -11
- data/lib/mysh/internal/actions/gls.rb +2 -2
- data/lib/mysh/internal/actions/help.rb +6 -3
- data/lib/mysh/internal/actions/help/sub_help.rb +2 -2
- data/lib/mysh/internal/actions/history.rb +2 -2
- data/lib/mysh/internal/actions/load.rb +24 -30
- data/lib/mysh/internal/actions/pwd.rb +3 -11
- data/lib/mysh/internal/actions/quit.rb +3 -11
- data/lib/mysh/internal/actions/say.rb +3 -12
- data/lib/mysh/internal/actions/show.rb +16 -19
- data/lib/mysh/internal/actions/show/env.rb +5 -5
- data/lib/mysh/internal/actions/show/ruby.rb +1 -1
- data/lib/mysh/internal/actions/type.rb +11 -17
- data/lib/mysh/internal/actions/vars.rb +2 -2
- data/lib/mysh/internal/actions/vls.rb +11 -16
- data/lib/mysh/internal/manage.rb +5 -19
- data/lib/mysh/process.rb +8 -12
- data/lib/mysh/quick.rb +11 -11
- data/lib/mysh/system.rb +11 -0
- data/lib/mysh/version.rb +1 -1
- data/tests/my_shell_tests.rb +25 -7
- metadata +5 -3
@@ -3,26 +3,20 @@
|
|
3
3
|
#* mysh/internal/actions/type.rb -- The mysh type command.
|
4
4
|
module Mysh
|
5
5
|
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
#Execute the type command.
|
10
|
-
def call(args)
|
11
|
-
file_name = args.shift
|
6
|
+
#Add the type command to the library.
|
7
|
+
desc = 'Display a text file with support for optional embedded ' +
|
8
|
+
'handlebars and mysh variables.'
|
12
9
|
|
13
|
-
|
10
|
+
action = lambda do |input|
|
11
|
+
args = input.args
|
12
|
+
file_name = args.shift
|
14
13
|
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
end
|
14
|
+
if file_name
|
15
|
+
show_handlebar_file(file_name, BindingWrapper.new(binding))
|
16
|
+
else
|
17
|
+
fail "A text file must be specified."
|
20
18
|
end
|
21
|
-
|
22
19
|
end
|
23
20
|
|
24
|
-
|
25
|
-
desc = 'Display a text file with support for optional embedded ' +
|
26
|
-
'handlebars and mysh variables.'
|
27
|
-
COMMANDS.add_action(TypeCommand.new('type file', desc))
|
21
|
+
COMMANDS.add_action(Action.new('type file', desc, &action))
|
28
22
|
end
|
@@ -19,8 +19,8 @@ module Mysh
|
|
19
19
|
end
|
20
20
|
|
21
21
|
#Execute a command against the internal mysh variables.
|
22
|
-
def
|
23
|
-
match = VAR_EXP.match(
|
22
|
+
def process_command(input)
|
23
|
+
match = VAR_EXP.match(input.raw)
|
24
24
|
@name, @equals, @value = match[:name], match[:equals], match[:value]
|
25
25
|
do_command
|
26
26
|
:internal
|
@@ -5,25 +5,20 @@ require 'vls'
|
|
5
5
|
#* mysh/internal/actions/vls.rb -- The mysh module vls (Version LS) command.
|
6
6
|
module Mysh
|
7
7
|
|
8
|
-
|
9
|
-
|
8
|
+
#Add the vls command to the library.
|
9
|
+
desc = 'Display the loaded modules, matching the optional mask, that ' +
|
10
|
+
'have version info.'
|
10
11
|
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
results = VersionLS.vls(filter)
|
12
|
+
action = lambda do |input|
|
13
|
+
filter = input.args[0] || /./
|
14
|
+
results = VersionLS.vls(filter)
|
15
15
|
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
end
|
16
|
+
if results.empty?
|
17
|
+
puts "No modules found for filter #{filter.inspect}.", ""
|
18
|
+
else
|
19
|
+
puts results.format_mysh_bullets, ""
|
21
20
|
end
|
22
|
-
|
23
21
|
end
|
24
22
|
|
25
|
-
|
26
|
-
desc = 'Display the loaded modules, matching the optional mask, that ' +
|
27
|
-
'have version info.'
|
28
|
-
COMMANDS.add_action(VlsCommand.new('vls <mask>', desc))
|
23
|
+
COMMANDS.add_action(Action.new('vls <mask>', desc, &action))
|
29
24
|
end
|
data/lib/mysh/internal/manage.rb
CHANGED
@@ -6,29 +6,15 @@ module Mysh
|
|
6
6
|
#Set up the command action pool.
|
7
7
|
COMMANDS = ActionPool.new("COMMANDS")
|
8
8
|
|
9
|
-
#
|
10
|
-
def self.
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
end
|
15
|
-
|
16
|
-
#Execute the action of an internal command.
|
17
|
-
def self.execute(str)
|
18
|
-
unless str[0] == ' '
|
19
|
-
action, args = parse_command(str.chomp)
|
20
|
-
|
21
|
-
if action
|
22
|
-
action.call(args)
|
9
|
+
#Try to execute the string as an internal action.
|
10
|
+
def self.try_execute_internal(input)
|
11
|
+
unless input.quick_command == ' '
|
12
|
+
if (action = COMMANDS[input.raw_command])
|
13
|
+
action.process_command(input)
|
23
14
|
:internal
|
24
15
|
end
|
25
16
|
end
|
26
17
|
end
|
27
18
|
|
28
|
-
#Try to execute the string as an internal action.
|
29
|
-
def self.try_execute_internal_command(str)
|
30
|
-
execute(str)
|
31
|
-
end
|
32
|
-
|
33
19
|
end
|
34
20
|
|
data/lib/mysh/process.rb
CHANGED
@@ -23,7 +23,7 @@ module Mysh
|
|
23
23
|
until source.eoi? do
|
24
24
|
execute_a_command(get_command(source))
|
25
25
|
end
|
26
|
-
rescue MyshExit
|
26
|
+
rescue Interrupt, MyshExit
|
27
27
|
end
|
28
28
|
|
29
29
|
#Execute a single line of input and handle exceptions.
|
@@ -32,21 +32,17 @@ module Mysh
|
|
32
32
|
|
33
33
|
rescue Interrupt, StandardError, ScriptError => err
|
34
34
|
puts "Error #{err.class}: #{err}"
|
35
|
-
puts err.backtrace if MNV[:debug]
|
35
|
+
puts err.backtrace if MNV[:debug] || defined?(MiniTest)
|
36
36
|
end
|
37
37
|
|
38
38
|
#Try to execute a single line of input. Does not handle exceptions.
|
39
|
-
def self.try_execute_command(
|
40
|
-
|
41
|
-
input = input.preprocess
|
42
|
-
end
|
43
|
-
|
44
|
-
puts "=> #{input}" if MNV[:debug]
|
39
|
+
def self.try_execute_command(str)
|
40
|
+
input = InputWrapper.new(str)
|
45
41
|
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
(
|
42
|
+
try_execute_quick(input) ||
|
43
|
+
try_execute_internal(input) ||
|
44
|
+
try_execute_external(input) ||
|
45
|
+
try_execute_system(input)
|
50
46
|
end
|
51
47
|
|
52
48
|
end
|
data/lib/mysh/quick.rb
CHANGED
@@ -4,19 +4,19 @@
|
|
4
4
|
module Mysh
|
5
5
|
|
6
6
|
#A hash of quick command short cuts and their actions.
|
7
|
-
QUICK = Hash.new(lambda {|
|
7
|
+
QUICK = Hash.new(lambda {|_input| false })
|
8
8
|
|
9
|
-
QUICK['!'] = lambda {|
|
10
|
-
QUICK['#'] = lambda {|
|
11
|
-
QUICK['$'] = lambda {|
|
12
|
-
QUICK['%'] = lambda {|
|
13
|
-
QUICK['='] = lambda {|
|
14
|
-
QUICK['?'] = lambda {|
|
15
|
-
QUICK['@'] = lambda {|
|
9
|
+
QUICK['!'] = lambda {|input| HISTORY_COMMAND.process_quick_command(input)}
|
10
|
+
QUICK['#'] = lambda {|input| MYSH_COMMENT.process_command(input)}
|
11
|
+
QUICK['$'] = lambda {|input| VARS_COMMAND.process_command(input)}
|
12
|
+
QUICK['%'] = lambda {|input| TIMED_COMMAND.process_command(input)}
|
13
|
+
QUICK['='] = lambda {|input| $mysh_exec_host.execute(input.raw.preprocess)}
|
14
|
+
QUICK['?'] = lambda {|input| HELP_COMMAND.process_quick_command(input)}
|
15
|
+
QUICK['@'] = lambda {|input| SHOW_COMMAND.process_quick_command(input)}
|
16
16
|
|
17
|
-
#Try to execute the
|
18
|
-
def self.
|
19
|
-
QUICK[
|
17
|
+
#Try to execute the inputing as a quick command.
|
18
|
+
def self.try_execute_quick(input)
|
19
|
+
QUICK[input.quick_command].call(input)
|
20
20
|
end
|
21
21
|
|
22
22
|
end
|
data/lib/mysh/system.rb
ADDED
data/lib/mysh/version.rb
CHANGED
data/tests/my_shell_tests.rb
CHANGED
@@ -11,13 +11,6 @@ class MyShellTester < Minitest::Test
|
|
11
11
|
#Track mini-test progress.
|
12
12
|
include MinitestVisible
|
13
13
|
|
14
|
-
#Evaluate the string in a mysh context.
|
15
|
-
def mysh_eval(str)
|
16
|
-
@mysh_binding ||= binding
|
17
|
-
|
18
|
-
@mysh_binding.eval(str)
|
19
|
-
end
|
20
|
-
|
21
14
|
def test_that_module_entities_exists
|
22
15
|
assert_equal(String, Mysh::VERSION.class)
|
23
16
|
|
@@ -26,6 +19,8 @@ class MyShellTester < Minitest::Test
|
|
26
19
|
assert_equal(Class, Mysh::ActionPool.class)
|
27
20
|
assert_equal(Module, Mysh::MNV.class)
|
28
21
|
assert_equal(Class, Mysh::Keeper.class)
|
22
|
+
assert_equal(Class, Mysh::BindingWrapper.class)
|
23
|
+
assert_equal(Class, Mysh::InputWrapper.class)
|
29
24
|
|
30
25
|
assert_equal(Mysh::ActionPool, Mysh::COMMANDS.class)
|
31
26
|
assert_equal(Mysh::ActionPool, Mysh::HELP.class)
|
@@ -197,4 +192,27 @@ class MyShellTester < Minitest::Test
|
|
197
192
|
assert_equal("99", MNV[:d])
|
198
193
|
end
|
199
194
|
|
195
|
+
def test_the_input_wrapper
|
196
|
+
wrapper = Mysh::InputWrapper.new '@last 45 "is finished" {{ 2+2 }} ever'
|
197
|
+
|
198
|
+
assert_equal('@last 45 "is finished" {{ 2+2 }} ever', wrapper.raw)
|
199
|
+
assert_equal('@last 45 "is finished" 4 ever', wrapper.cooked)
|
200
|
+
|
201
|
+
assert_equal('@last', wrapper.raw_command)
|
202
|
+
assert_equal(' 45 "is finished" {{ 2+2 }} ever', wrapper.raw_body)
|
203
|
+
|
204
|
+
assert_equal('@', wrapper.quick_command)
|
205
|
+
assert_equal('last 45 "is finished" {{ 2+2 }} ever', wrapper.quick_body)
|
206
|
+
|
207
|
+
assert_equal(["@last", "45", "is finished", "4", "ever"], wrapper.parsed)
|
208
|
+
assert_equal(["45", "is finished", "4", "ever"], wrapper.args)
|
209
|
+
|
210
|
+
assert_equal(wrapper, wrapper.quick)
|
211
|
+
|
212
|
+
assert_equal('@', wrapper.raw_command)
|
213
|
+
assert_equal('last 45 "is finished" {{ 2+2 }} ever', wrapper.raw_body)
|
214
|
+
assert_equal(["@", "last", "45", "is finished", "4", "ever"], wrapper.parsed)
|
215
|
+
assert_equal(["last", "45", "is finished", "4", "ever"], wrapper.args)
|
216
|
+
end
|
217
|
+
|
200
218
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mysh
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.5.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Peter Camilleri
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-01-
|
11
|
+
date: 2017-01-31 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -155,11 +155,12 @@ files:
|
|
155
155
|
- lib/mysh/exceptions.rb
|
156
156
|
- lib/mysh/expression.rb
|
157
157
|
- lib/mysh/expression/lineage.rb
|
158
|
-
- lib/mysh/
|
158
|
+
- lib/mysh/external.rb
|
159
159
|
- lib/mysh/globalize.rb
|
160
160
|
- lib/mysh/handlebars.rb
|
161
161
|
- lib/mysh/handlebars/string.rb
|
162
162
|
- lib/mysh/init.rb
|
163
|
+
- lib/mysh/input_wrapper.rb
|
163
164
|
- lib/mysh/internal.rb
|
164
165
|
- lib/mysh/internal/action.rb
|
165
166
|
- lib/mysh/internal/action_pool.rb
|
@@ -225,6 +226,7 @@ files:
|
|
225
226
|
- lib/mysh/sources/parse.rb
|
226
227
|
- lib/mysh/sources/smart_auto_complete.rb
|
227
228
|
- lib/mysh/sources/string.rb
|
229
|
+
- lib/mysh/system.rb
|
228
230
|
- lib/mysh/user_input.rb
|
229
231
|
- lib/mysh/version.rb
|
230
232
|
- mysh.gemspec
|