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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 9696599d94ed469efdc12d988e1fca5e033f5126
4
- data.tar.gz: bd16dac7ecb6b576fc009334f0f326c97eb7be8c
3
+ metadata.gz: 0d14bb08c98c661d3a7845b7d717b0afbd5e7e16
4
+ data.tar.gz: 5927f10314b976343eeb2e2464f89cddc1c5255b
5
5
  SHA512:
6
- metadata.gz: 6b5dd1d00c374dfdb3b482a518d8f3bdb8a7b3754e6b31efc05e02e178cef3db0d2eb1dd62da90098a3fef819a98c17f56e025a65d4cfac346aeab330f098d5e
7
- data.tar.gz: 717a6190bff1dd180906d447d440efeee689fbd425fde050a2bc556036a7644f71a977d0308b29337ebeb31dbe1a1b917a06664d68aad217b714a08dd0375626
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. Gotta love dem features!
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
- "Fixnum instance < Fixnum < Integer < Numeric < Object < BasicObject"
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 #<Mysh::ExecHost:0x1d71e18 @owner=Mysh>
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
- klass.name + " instance < " + klass.lineage
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
@@ -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
- #The mysh ruby expression processor.
12
- class ExecHost
13
-
14
- include Math
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
- #The execution binding used for ruby expressions.
23
- attr_accessor :exec_binding
24
- end
17
+ include Math
25
18
 
26
- #Set up a new execution environment
27
- def initialize(owner)
28
- @owner = owner
29
- mysh_binding
30
- end
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
- #Create a binding for mysh to execute expressions in.
33
- def mysh_binding
34
- ExecHost.exec_binding = binding
35
- end
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
- #Do the actual work of executing an expression.
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
- private
40
+ #Get the previous result
41
+ def result
42
+ $mysh_exec_result
43
+ end
46
44
 
47
- #Get the execute binding.
48
- def exec_binding
49
- self.class.exec_binding
50
- end
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
- #Set the current result
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
@@ -48,7 +48,7 @@ module Mysh
48
48
  buffer.concat(info(spec))
49
49
  end
50
50
 
51
- puts report.mysh_bulletize
51
+ puts report.format_mysh_bullets
52
52
  end
53
53
 
54
54
  #Get detailed information on a gem specification.
@@ -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 - 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
-
13
- path - An easy-to-read, formatted version of the current search path.
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
 
@@ -8,5 +8,5 @@ quick form, ? is used, the space is optional.
8
8
 
9
9
  The available help topics are:
10
10
 
11
- {{ HELP.actions_info.mysh_bulletize }}
11
+ {{ HELP.actions_info.format_mysh_bullets }}
12
12
 
@@ -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.mysh_bulletize }}
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
@@ -8,5 +8,5 @@ quick form, @ is used, the space is optional.
8
8
 
9
9
  The available show items are:
10
10
 
11
- {{ SHOW.actions_info.mysh_bulletize }}
11
+ {{ SHOW.actions_info.format_mysh_bullets }}
12
12
 
@@ -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.mysh_bulletize, "",
13
- path.mysh_bulletize, ""
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.mysh_bulletize, "",
13
- path.mysh_bulletize, ""
12
+ puts info.format_mysh_bullets, "",
13
+ path.format_mysh_bullets, ""
14
14
  end
15
15
 
16
16
  private
@@ -16,7 +16,7 @@ module Mysh
16
16
  if results.empty?
17
17
  puts "No modules found for filter #{filter.inspect}.", ""
18
18
  else
19
- puts results.mysh_bulletize, ""
19
+ puts results.format_mysh_bullets, ""
20
20
  end
21
21
  end
22
22
 
@@ -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 mysh_bulletize(page_width)
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 mysh_bulletize(page_width = Mysh::PAGE_WIDTH)
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| @exec_host.execute(str); :expression }
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
@@ -2,7 +2,7 @@
2
2
 
3
3
  module Mysh
4
4
  #The version string of MY SHell.
5
- VERSION = "0.2.5"
5
+ VERSION = "0.2.6"
6
6
 
7
7
  #A brief summary of this gem.
8
8
  SUMMARY = "mysh -- a Ruby inspired command line shell."
data/lib/mysh.rb CHANGED
@@ -20,7 +20,7 @@ module Mysh
20
20
  setup
21
21
 
22
22
  while @mysh_running do
23
- execute_a_command(@exec_host.eval_handlebars(get_command("mysh")))
23
+ execute_a_command($mysh_exec_host.eval_handlebars(get_command("mysh")))
24
24
  end
25
25
  end
26
26
 
data/mysh.reek CHANGED
@@ -38,6 +38,9 @@ LongYieldList:
38
38
  enabled: true
39
39
  exclude: []
40
40
  max_params: 3
41
+ ModuleInitialize:
42
+ enabled: false
43
+ exclude: []
41
44
  NestedIterators:
42
45
  enabled: true
43
46
  exclude: []
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)*(i+1)} ],
10
- ["Cubes", Array.new(count){|i| (i+1)*(i+1)*(i+1)} ]].mysh_bulletize }}
9
+ ["Squares", Array.new(count){|i| (i+1)**2} ],
10
+ ["Cubes", Array.new(count){|i| (i+1)**3} ]].format_mysh_bullets }}
11
11
 
@@ -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", "loses", "election", "3"],
66
- Mysh.parse_args("1 Trump loses election 3"))
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("String instance < String < Object < BasicObject",
72
+ assert_equal("Hello of String < Object < BasicObject",
75
73
  "Hello".lineage)
76
74
 
77
- assert_equal("Fixnum instance < Fixnum < Integer < Numeric < Object < BasicObject",
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.mysh_bulletize)
115
+ assert_equal(result, data.format_mysh_bullets)
118
116
 
119
- assert_equal("", [].mysh_bulletize)
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.mysh_bulletize)
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.5
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-03 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: bundler