mysh 0.2.5 → 0.2.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +9 -4
- data/lib/mysh/expression/lineage.rb +2 -2
- data/lib/mysh/expression.rb +34 -58
- data/lib/mysh/internal/actions/gls.rb +1 -1
- data/lib/mysh/internal/actions/help/env.txt +13 -8
- data/lib/mysh/internal/actions/help/h_o_h.txt +1 -1
- data/lib/mysh/internal/actions/help/help.txt +1 -1
- data/lib/mysh/internal/actions/help/show.txt +1 -1
- data/lib/mysh/internal/actions/show/env.rb +2 -2
- data/lib/mysh/internal/actions/show/ruby.rb +2 -2
- data/lib/mysh/internal/actions/vls.rb +1 -1
- data/lib/mysh/internal/format/array.rb +2 -2
- data/lib/mysh/quick.rb +1 -1
- data/lib/mysh/version.rb +1 -1
- data/lib/mysh.rb +1 -1
- data/mysh.reek +3 -0
- data/samples/show.txt +2 -2
- data/tests/my_shell_tests.rb +9 -11
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0d14bb08c98c661d3a7845b7d717b0afbd5e7e16
|
4
|
+
data.tar.gz: 5927f10314b976343eeb2e2464f89cddc1c5255b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c238988c73db100b3fe65c9071b944a1e5f227429c33655a1f012431799878c5848630725c70cf81ee84f66b2bf583f494c0f4acaf6c5a681cdd014468d6a7f9
|
7
|
+
data.tar.gz: 95d6b03f15eb614fe34115c9007fc15fc1604ecb476ee1c510f5109d1593f055b34943d4e1ad10ccc4fa82fe9118c5ee81f857bb471bf0817970fd3a0cbea670
|
data/README.md
CHANGED
@@ -25,7 +25,8 @@ See the original article at:
|
|
25
25
|
(http://www.blackbytes.info/2016/07/writing-a-shell-in-ruby/)
|
26
26
|
|
27
27
|
By the way. The briefest look at the code will reveal that mysh has grown to be
|
28
|
-
way more than 25 lines long.
|
28
|
+
way more than 25 lines long. As Thomas Edison once said: 1% inspiration, 99%
|
29
|
+
perspiration. Enjoy!
|
29
30
|
|
30
31
|
## Installation
|
31
32
|
|
@@ -90,11 +91,11 @@ mysh>=a
|
|
90
91
|
mysh>=result
|
91
92
|
42
|
92
93
|
mysh>=a.lineage
|
93
|
-
"
|
94
|
+
"42 of Fixnum < Integer < Numeric < Object < BasicObject"
|
94
95
|
mysh>=reset
|
95
96
|
|
96
97
|
mysh>=a
|
97
|
-
NameError: undefined local variable or method `a' for
|
98
|
+
NameError: undefined local variable or method `a' for #<#<Class:0x1c57a10>:0x1c57938>
|
98
99
|
mysh>=result
|
99
100
|
|
100
101
|
mysh>
|
@@ -284,6 +285,8 @@ the args array will contain:
|
|
284
285
|
|
285
286
|
## Contributing
|
286
287
|
|
288
|
+
All participation is welcomed. There are two fabulous plans to choose from:
|
289
|
+
|
287
290
|
#### Plan A
|
288
291
|
|
289
292
|
1. Fork it ( https://github.com/PeterCamilleri/mysh/fork )
|
@@ -297,4 +300,6 @@ the args array will contain:
|
|
297
300
|
|
298
301
|
Go to the GitHub repository at (https://github.com/PeterCamilleri/mysh) and
|
299
302
|
raise an issue calling attention to some aspect that could use some TLC or a
|
300
|
-
suggestion or an idea.
|
303
|
+
suggestion or an idea or a comment.
|
304
|
+
|
305
|
+
This is a low pressure environment. All are welcome!
|
@@ -6,7 +6,7 @@ class Object
|
|
6
6
|
#Get the lineage of this object.
|
7
7
|
def lineage
|
8
8
|
klass = self.class
|
9
|
-
|
9
|
+
to_s + " of " + klass.lineage
|
10
10
|
end
|
11
11
|
|
12
12
|
end
|
@@ -17,7 +17,7 @@ class Class
|
|
17
17
|
#Get the lineage of this class.
|
18
18
|
def lineage
|
19
19
|
klass = superclass
|
20
|
-
name + (klass ? " < " + klass.lineage : "")
|
20
|
+
(name || to_s) + (klass ? " < " + klass.lineage : "")
|
21
21
|
end
|
22
22
|
|
23
23
|
end
|
data/lib/mysh/expression.rb
CHANGED
@@ -8,72 +8,48 @@ require_relative 'expression/lineage'
|
|
8
8
|
#* mysh/expression.rb -- The mysh ruby expression processor.
|
9
9
|
module Mysh
|
10
10
|
|
11
|
-
#
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
#These variables live here so that they are not part of the mysh
|
17
|
-
#execution environment. This provides a little bit of isolation.
|
18
|
-
class << self
|
19
|
-
#The result of the last expression evaluated.
|
20
|
-
attr_accessor :result
|
11
|
+
#Reset the state of the execution hosting environment.
|
12
|
+
#<br>Endemic Code Smells
|
13
|
+
# :reek:TooManyStatements -- False positive
|
14
|
+
def self.reset_host
|
15
|
+
exec_class = Class.new do
|
21
16
|
|
22
|
-
|
23
|
-
attr_accessor :exec_binding
|
24
|
-
end
|
17
|
+
include Math
|
25
18
|
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
19
|
+
#Set up a new execution environment
|
20
|
+
#<br>Endemic Code Smells
|
21
|
+
# :reek:ModuleInitialize -- False positive turned off in mysh.reek
|
22
|
+
def initialize
|
23
|
+
$mysh_exec_result = nil
|
24
|
+
$mysh_exec_binding = binding
|
25
|
+
end
|
31
26
|
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
27
|
+
#Do the actual work of executing an expression.
|
28
|
+
#<br>Note:
|
29
|
+
#* The expression string always begins with an '=' character.
|
30
|
+
def execute(expression)
|
31
|
+
pp $mysh_exec_binding.eval("$mysh_exec_result" + expression)
|
32
|
+
rescue Interrupt, StandardError, ScriptError => err
|
33
|
+
puts "#{err.class.to_s}: #{err}"
|
34
|
+
ensure
|
35
|
+
return :expression
|
36
|
+
end
|
36
37
|
|
37
|
-
|
38
|
-
def execute(str)
|
39
|
-
self.result = exec_binding.eval(str[1..-1])
|
40
|
-
send(result ? :pp : :puts, result)
|
41
|
-
rescue Interrupt, StandardError, ScriptError => err
|
42
|
-
puts "#{err.class.to_s}: #{err}"
|
43
|
-
end
|
38
|
+
private
|
44
39
|
|
45
|
-
|
40
|
+
#Get the previous result
|
41
|
+
def result
|
42
|
+
$mysh_exec_result
|
43
|
+
end
|
46
44
|
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
45
|
+
#Reset the state of the execution host.
|
46
|
+
def reset
|
47
|
+
Mysh.reset_host
|
48
|
+
nil
|
49
|
+
end
|
51
50
|
|
52
|
-
#Get the previous result
|
53
|
-
def result
|
54
|
-
self.class.result
|
55
51
|
end
|
56
52
|
|
57
|
-
|
58
|
-
def result=(value)
|
59
|
-
self.class.result=value
|
60
|
-
end
|
61
|
-
|
62
|
-
#Reset the state of the execution host.
|
63
|
-
def reset
|
64
|
-
@owner.reset_host
|
65
|
-
nil
|
66
|
-
end
|
67
|
-
|
68
|
-
#Evaluate the string in the my shell context.
|
69
|
-
def mysh_eval(str)
|
70
|
-
exec_binding.eval(str)
|
71
|
-
end
|
53
|
+
$mysh_exec_host = exec_class.new
|
72
54
|
end
|
73
|
-
|
74
|
-
#Reset the state of the execution hosting environment.
|
75
|
-
def self.reset_host
|
76
|
-
@exec_host = ExecHost.new(self)
|
77
|
-
end
|
78
|
-
|
79
55
|
end
|
@@ -3,12 +3,17 @@ Help: mysh show env command summary:
|
|
3
3
|
The show env (or @env) command is used to display useful information about the
|
4
4
|
current execution environment. This includes:
|
5
5
|
|
6
|
-
user
|
7
|
-
home
|
8
|
-
name
|
9
|
-
shell
|
10
|
-
host
|
11
|
-
os
|
12
|
-
|
13
|
-
|
6
|
+
user - The current user name.
|
7
|
+
home - The current home directory.
|
8
|
+
name - The path/name of the mysh program currently executing.
|
9
|
+
shell - The path/name of the system command shell.
|
10
|
+
host - The name of the host computer.
|
11
|
+
os - The current operating system.
|
12
|
+
platform - The operating platform detected by the low-level terminal gem.
|
13
|
+
java - Is the current platform powered by Java?
|
14
|
+
term - What terminal is defined by the system, if one is defined.
|
15
|
+
disp - What display is defined by the system, if one is defined.
|
16
|
+
edit - What editor is defined by the system, if one is defined.
|
17
|
+
|
18
|
+
path - An easy-to-read, formatted version of the current search path.
|
14
19
|
|
@@ -11,7 +11,7 @@ In mysh, commands fall into one of three broad categories. There are:
|
|
11
11
|
2) Internal mysh commands are processed within mysh itself. The following set
|
12
12
|
of commands are supported:
|
13
13
|
|
14
|
-
{{ Mysh::COMMANDS.actions_info.
|
14
|
+
{{ Mysh::COMMANDS.actions_info.format_mysh_bullets }}
|
15
15
|
|
16
16
|
3) All other commands are executed by the system using the standard shell or
|
17
17
|
the appropriate ruby interpreter. If the command has a '.rb' extension, it
|
@@ -9,8 +9,8 @@ module Mysh
|
|
9
9
|
#Execute the ? shell command.
|
10
10
|
def call(_args)
|
11
11
|
puts "Key mysh environment information.", ""
|
12
|
-
puts info.
|
13
|
-
path.
|
12
|
+
puts info.format_mysh_bullets, "",
|
13
|
+
path.format_mysh_bullets, ""
|
14
14
|
end
|
15
15
|
|
16
16
|
private
|
@@ -9,8 +9,8 @@ module Mysh
|
|
9
9
|
#Execute the ? shell command.
|
10
10
|
def call(_args)
|
11
11
|
puts "Key ruby environment information.", ""
|
12
|
-
puts info.
|
13
|
-
path.
|
12
|
+
puts info.format_mysh_bullets, "",
|
13
|
+
path.format_mysh_bullets, ""
|
14
14
|
end
|
15
15
|
|
16
16
|
private
|
@@ -46,7 +46,7 @@ class Array
|
|
46
46
|
|
47
47
|
#Print out the array as bullet points.
|
48
48
|
def puts_mysh_bullets(page_width = Mysh::PAGE_WIDTH)
|
49
|
-
puts
|
49
|
+
puts format_mysh_bullets(page_width)
|
50
50
|
end
|
51
51
|
|
52
52
|
#Convert the array to strings with bullet points.
|
@@ -54,7 +54,7 @@ class Array
|
|
54
54
|
#* A string.
|
55
55
|
#<br>Endemic Code Smells
|
56
56
|
#* :reek:FeatureEnvy -- false positive.
|
57
|
-
def
|
57
|
+
def format_mysh_bullets(page_width = Mysh::PAGE_WIDTH)
|
58
58
|
return "" if empty?
|
59
59
|
|
60
60
|
builder = Mysh::BulletPoints.new(page_width)
|
data/lib/mysh/quick.rb
CHANGED
@@ -7,7 +7,7 @@ module Mysh
|
|
7
7
|
QUICK = Hash.new(lambda {|_str| false})
|
8
8
|
|
9
9
|
QUICK['!'] = lambda {|str| HISTORY_COMMAND.quick_parse_and_call(str) }
|
10
|
-
QUICK['='] = lambda {|str|
|
10
|
+
QUICK['='] = lambda {|str| $mysh_exec_host.execute(str) }
|
11
11
|
QUICK['?'] = lambda {|str| HELP_COMMAND.quick_parse_and_call(str) }
|
12
12
|
QUICK['@'] = lambda {|str| SHOW_COMMAND.quick_parse_and_call(str) }
|
13
13
|
|
data/lib/mysh/version.rb
CHANGED
data/lib/mysh.rb
CHANGED
data/mysh.reek
CHANGED
data/samples/show.txt
CHANGED
@@ -6,6 +6,6 @@ Args = {{ args.inspect }}
|
|
6
6
|
{{ count = 100 #}}
|
7
7
|
|
8
8
|
{{ [["Numbers", Array.new(count){|i| (i+1)} ],
|
9
|
-
["Squares", Array.new(count){|i| (i+1)
|
10
|
-
["Cubes", Array.new(count){|i| (i+1)
|
9
|
+
["Squares", Array.new(count){|i| (i+1)**2} ],
|
10
|
+
["Cubes", Array.new(count){|i| (i+1)**3} ]].format_mysh_bullets }}
|
11
11
|
|
data/tests/my_shell_tests.rb
CHANGED
@@ -24,7 +24,6 @@ class MyShellTester < Minitest::Test
|
|
24
24
|
assert_equal(Module, Mysh.class)
|
25
25
|
assert_equal(Class, Mysh::Action.class)
|
26
26
|
assert_equal(Class, Mysh::ActionPool.class)
|
27
|
-
assert_equal(Class, Mysh::ExecHost.class)
|
28
27
|
|
29
28
|
assert_equal(Mysh::ActionPool, Mysh::COMMANDS.class)
|
30
29
|
assert_equal(Mysh::ActionPool, Mysh::HELP.class)
|
@@ -62,19 +61,18 @@ class MyShellTester < Minitest::Test
|
|
62
61
|
|
63
62
|
assert_equal(["1", "2", "3"], Mysh.parse_args("1 2 3"))
|
64
63
|
|
65
|
-
assert_equal(["1", "Trump", "
|
66
|
-
Mysh.parse_args("1 Trump
|
67
|
-
|
68
|
-
assert_equal(["1", "Trump loses election", "3"],
|
69
|
-
Mysh.parse_args('1 "Trump loses election" 3'))
|
64
|
+
assert_equal(["1", "Trump", "impeached", "3"],
|
65
|
+
Mysh.parse_args("1 Trump impeached 3"))
|
70
66
|
|
67
|
+
assert_equal(["1", "Trump impeached", "3"],
|
68
|
+
Mysh.parse_args('1 "Trump impeached" 3'))
|
71
69
|
end
|
72
70
|
|
73
71
|
def test_the_lineage_method
|
74
|
-
assert_equal("
|
72
|
+
assert_equal("Hello of String < Object < BasicObject",
|
75
73
|
"Hello".lineage)
|
76
74
|
|
77
|
-
assert_equal("
|
75
|
+
assert_equal("4 of Fixnum < Integer < Numeric < Object < BasicObject",
|
78
76
|
(4).lineage)
|
79
77
|
end
|
80
78
|
|
@@ -114,13 +112,13 @@ class MyShellTester < Minitest::Test
|
|
114
112
|
" 4 9 14 19 24 29 34 39 44 49 54 59 64 69 74 79 84 89 94 99\n" +
|
115
113
|
"pie 3.141592653589793"
|
116
114
|
|
117
|
-
assert_equal(result, data.
|
115
|
+
assert_equal(result, data.format_mysh_bullets)
|
118
116
|
|
119
|
-
assert_equal("", [].
|
117
|
+
assert_equal("", [].format_mysh_bullets)
|
120
118
|
|
121
119
|
data = ["apple", "cherry", "victory"]
|
122
120
|
result = "* apple\n* cherry\n* victory"
|
123
|
-
assert_equal(result, data.
|
121
|
+
assert_equal(result, data.format_mysh_bullets)
|
124
122
|
|
125
123
|
end
|
126
124
|
|
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.2.
|
4
|
+
version: 0.2.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Peter Camilleri
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-11-
|
11
|
+
date: 2016-11-12 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|