mysh 0.3.0 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (53) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +95 -28
  3. data/lib/mysh.rb +13 -39
  4. data/lib/mysh/binding_wrapper.rb +21 -0
  5. data/lib/mysh/exceptions.rb +4 -0
  6. data/lib/mysh/expression.rb +11 -4
  7. data/lib/mysh/external_ruby.rb +20 -7
  8. data/lib/mysh/globalize.rb +18 -0
  9. data/lib/mysh/handlebars.rb +0 -3
  10. data/lib/mysh/init.rb +26 -0
  11. data/lib/mysh/internal/action.rb +7 -2
  12. data/lib/mysh/internal/action_pool.rb +9 -4
  13. data/lib/mysh/internal/actions/command_line.rb +56 -0
  14. data/lib/mysh/internal/actions/command_line/debug.rb +39 -0
  15. data/lib/mysh/internal/actions/command_line/init.rb +50 -0
  16. data/lib/mysh/internal/actions/command_line/load.rb +25 -0
  17. data/lib/mysh/internal/actions/command_line/post_prompt.rb +44 -0
  18. data/lib/mysh/internal/actions/command_line/pre_prompt.rb +44 -0
  19. data/lib/mysh/internal/actions/command_line/prompt.rb +42 -0
  20. data/lib/mysh/internal/actions/command_line/quit.rb +19 -0
  21. data/lib/mysh/internal/actions/command_line/usage.rb +23 -0
  22. data/lib/mysh/internal/actions/comment.rb +20 -0
  23. data/lib/mysh/internal/actions/elapsed.rb +27 -0
  24. data/lib/mysh/internal/actions/exit.rb +2 -3
  25. data/lib/mysh/internal/actions/gls.rb +1 -1
  26. data/lib/mysh/internal/actions/help/expr.txt +6 -9
  27. data/lib/mysh/internal/actions/help/quick.txt +6 -0
  28. data/lib/mysh/internal/actions/help/sub_help.rb +1 -0
  29. data/lib/mysh/internal/actions/help/usage.txt +8 -0
  30. data/lib/mysh/internal/actions/help/vars.txt +2 -2
  31. data/lib/mysh/internal/actions/load.rb +42 -0
  32. data/lib/mysh/internal/actions/quit.rb +18 -0
  33. data/lib/mysh/internal/actions/say.rb +20 -0
  34. data/lib/mysh/internal/actions/show/env.rb +13 -11
  35. data/lib/mysh/internal/actions/type.rb +4 -3
  36. data/lib/mysh/internal/actions/vars.rb +5 -5
  37. data/lib/mysh/internal/manage.rb +1 -1
  38. data/lib/mysh/process.rb +52 -0
  39. data/lib/mysh/quick.rb +3 -1
  40. data/lib/mysh/shell_variables.rb +0 -1
  41. data/lib/mysh/sources/console.rb +44 -0
  42. data/lib/mysh/{user_input → sources}/parse.rb +1 -1
  43. data/lib/mysh/{user_input/smart_source.rb → sources/smart_auto_complete.rb} +1 -1
  44. data/lib/mysh/sources/string.rb +33 -0
  45. data/lib/mysh/user_input.rb +14 -30
  46. data/lib/mysh/version.rb +1 -1
  47. data/samples/load.rb +6 -0
  48. data/samples/script.mysh +11 -0
  49. data/samples/sleep.rb +6 -0
  50. data/samples/sleep.txt +2 -0
  51. data/tests/my_shell_tests.rb +6 -4
  52. metadata +30 -5
  53. data/lib/mysh/shell_variables/globalize.rb +0 -9
@@ -2,51 +2,35 @@
2
2
 
3
3
  require 'mini_readline'
4
4
 
5
- require_relative 'user_input/smart_source'
6
- require_relative 'user_input/parse'
5
+ require_relative 'sources/console'
6
+ require_relative 'sources/string'
7
+
8
+ require_relative 'sources/smart_auto_complete'
9
+ require_relative 'sources/parse'
7
10
 
8
11
  #* mysh/user_input.rb -- Get some text from the user.
9
12
  module Mysh
10
13
 
11
- class << self
12
- #The input text source.
13
- attr_reader :input
14
- end
15
-
16
14
  #Get one command from the user.
17
- #<br>Endemic Code Smells
18
- #* :reek:TooManyStatements
19
- def self.get_command
20
- puts MNV[:pre_prompt] if MNV.key?(:pre_prompt)
21
-
22
- initial_input = @input.readline(prompt: MNV[:prompt] + '>')
23
- @input.instance_options[:initial] = ""
24
- get_command_extra(initial_input)
25
-
26
- rescue MiniReadlineEOI
27
- @mysh_running = false
28
- "\n"
15
+ def self.get_command(source)
16
+ get_command_extra(source, source.get_command)
29
17
  end
30
18
 
31
- private
32
-
33
19
  #Get any continuations of the inputs
34
- def self.get_command_extra(str)
20
+ def self.get_command_extra(source, str)
35
21
  if /\\\s*$/ =~ str
36
- parms = {prompt: MNV[:post_prompt] + '\\', prefix: str[0] }
37
- get_command_extra($PREMATCH + "\n" + @input.readline(parms))
22
+ get_command_extra(source, $PREMATCH + "\n" + source.get_command_extra(str))
38
23
  else
39
24
  str
40
25
  end
41
-
42
26
  end
43
27
 
44
28
  #Get the user input ready.
45
- def self.init_input
46
- @input = MiniReadline::Readline.new(history: true,
47
- eoi_detect: true,
48
- auto_complete: true,
49
- auto_source: SmartSource)
29
+ def self.input
30
+ @input ||= MiniReadline::Readline.new(history: true,
31
+ eoi_detect: true,
32
+ auto_complete: true,
33
+ auto_source: SmartSource)
50
34
  end
51
35
 
52
36
  end
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.3.0"
5
+ VERSION = "0.4.0"
6
6
 
7
7
  #A brief summary of this gem.
8
8
  SUMMARY = "mysh -- a Ruby inspired command line shell."
data/samples/load.rb ADDED
@@ -0,0 +1,6 @@
1
+ #A sample test file to be run.
2
+
3
+ puts "Accessing mysh from a Ruby script", ""
4
+
5
+ mysh "@env"
6
+
@@ -0,0 +1,11 @@
1
+ say This is a sample mysh script file.
2
+ say
3
+
4
+ say Let's try a gls!
5
+ gls
6
+
7
+ say Let's try a vls!
8
+ vls
9
+
10
+ say Let's try an @env!
11
+ @env
data/samples/sleep.rb ADDED
@@ -0,0 +1,6 @@
1
+ puts "Time for a 10 second nap!"
2
+
3
+ sleep(10)
4
+
5
+ puts "Nap time done!"
6
+
data/samples/sleep.txt ADDED
@@ -0,0 +1,2 @@
1
+ Time for a 10 second nap! {{ sleep(10) #}}
2
+ Nap time done!
@@ -48,8 +48,6 @@ class MyShellTester < Minitest::Test
48
48
  end
49
49
 
50
50
  def test_handlebars
51
- Mysh.reset_host
52
-
53
51
  assert_equal("ABC 123 DEF",
54
52
  "ABC {{ (1..3).to_a.join }} DEF".eval_handlebars)
55
53
 
@@ -127,8 +125,6 @@ class MyShellTester < Minitest::Test
127
125
  end
128
126
 
129
127
  def test_mysh_variables
130
- Mysh.reset_host
131
-
132
128
  assert_equal("", MNV[:test])
133
129
  assert_equal("", MNV.get_source(:test))
134
130
  refute(MNV.key?(:test), "MNV[:test] should not exist.")
@@ -195,4 +191,10 @@ class MyShellTester < Minitest::Test
195
191
  assert_equal("OK", MNV[:bad]) #And this too!
196
192
  end
197
193
 
194
+ def test_executing_some_strings
195
+ Mysh.process_string("$c=43\n$d=99")
196
+ assert_equal("43", MNV[:c])
197
+ assert_equal("99", MNV[:d])
198
+ end
199
+
198
200
  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.3.0
4
+ version: 0.4.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: 2016-12-21 00:00:00.000000000 Z
11
+ date: 2017-01-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -151,16 +151,31 @@ files:
151
151
  - README.md
152
152
  - bin/mysh
153
153
  - lib/mysh.rb
154
+ - lib/mysh/binding_wrapper.rb
155
+ - lib/mysh/exceptions.rb
154
156
  - lib/mysh/expression.rb
155
157
  - lib/mysh/expression/lineage.rb
156
158
  - lib/mysh/external_ruby.rb
159
+ - lib/mysh/globalize.rb
157
160
  - lib/mysh/handlebars.rb
158
161
  - lib/mysh/handlebars/string.rb
162
+ - lib/mysh/init.rb
159
163
  - lib/mysh/internal.rb
160
164
  - lib/mysh/internal/action.rb
161
165
  - lib/mysh/internal/action_pool.rb
162
166
  - lib/mysh/internal/actions/actions_path.rb
163
167
  - lib/mysh/internal/actions/cd.rb
168
+ - lib/mysh/internal/actions/command_line.rb
169
+ - lib/mysh/internal/actions/command_line/debug.rb
170
+ - lib/mysh/internal/actions/command_line/init.rb
171
+ - lib/mysh/internal/actions/command_line/load.rb
172
+ - lib/mysh/internal/actions/command_line/post_prompt.rb
173
+ - lib/mysh/internal/actions/command_line/pre_prompt.rb
174
+ - lib/mysh/internal/actions/command_line/prompt.rb
175
+ - lib/mysh/internal/actions/command_line/quit.rb
176
+ - lib/mysh/internal/actions/command_line/usage.rb
177
+ - lib/mysh/internal/actions/comment.rb
178
+ - lib/mysh/internal/actions/elapsed.rb
164
179
  - lib/mysh/internal/actions/exit.rb
165
180
  - lib/mysh/internal/actions/gls.rb
166
181
  - lib/mysh/internal/actions/help.rb
@@ -177,9 +192,13 @@ files:
177
192
  - lib/mysh/internal/actions/help/ruby.txt
178
193
  - lib/mysh/internal/actions/help/show.txt
179
194
  - lib/mysh/internal/actions/help/sub_help.rb
195
+ - lib/mysh/internal/actions/help/usage.txt
180
196
  - lib/mysh/internal/actions/help/vars.txt
181
197
  - lib/mysh/internal/actions/history.rb
198
+ - lib/mysh/internal/actions/load.rb
182
199
  - lib/mysh/internal/actions/pwd.rb
200
+ - lib/mysh/internal/actions/quit.rb
201
+ - lib/mysh/internal/actions/say.rb
183
202
  - lib/mysh/internal/actions/show.rb
184
203
  - lib/mysh/internal/actions/show/env.rb
185
204
  - lib/mysh/internal/actions/show/ruby.rb
@@ -196,21 +215,27 @@ files:
196
215
  - lib/mysh/internal/format/string.rb
197
216
  - lib/mysh/internal/manage.rb
198
217
  - lib/mysh/pre_processor.rb
218
+ - lib/mysh/process.rb
199
219
  - lib/mysh/quick.rb
200
220
  - lib/mysh/shell_variables.rb
201
221
  - lib/mysh/shell_variables/evaluate.rb
202
- - lib/mysh/shell_variables/globalize.rb
203
222
  - lib/mysh/shell_variables/shell_variable_keeper.rb
204
223
  - lib/mysh/shell_variables/shell_variable_store.rb
224
+ - lib/mysh/sources/console.rb
225
+ - lib/mysh/sources/parse.rb
226
+ - lib/mysh/sources/smart_auto_complete.rb
227
+ - lib/mysh/sources/string.rb
205
228
  - lib/mysh/user_input.rb
206
- - lib/mysh/user_input/parse.rb
207
- - lib/mysh/user_input/smart_source.rb
208
229
  - lib/mysh/version.rb
209
230
  - mysh.gemspec
210
231
  - mysh.reek
211
232
  - rakefile.rb
212
233
  - reek.txt
234
+ - samples/load.rb
235
+ - samples/script.mysh
213
236
  - samples/show.txt
237
+ - samples/sleep.rb
238
+ - samples/sleep.txt
214
239
  - samples/test.rb
215
240
  - tests/my_shell_tests.rb
216
241
  homepage: https://github.com/PeterCamilleri/mysh
@@ -1,9 +0,0 @@
1
- # coding: utf-8
2
-
3
- #Monkey patches for Mysh variables
4
- class Object
5
-
6
- #Make the environment variable store accessible everywhere.
7
- MNV = Mysh::MNV
8
-
9
- end