mysh 0.3.0 → 0.4.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 +95 -28
- data/lib/mysh.rb +13 -39
- data/lib/mysh/binding_wrapper.rb +21 -0
- data/lib/mysh/exceptions.rb +4 -0
- data/lib/mysh/expression.rb +11 -4
- data/lib/mysh/external_ruby.rb +20 -7
- data/lib/mysh/globalize.rb +18 -0
- data/lib/mysh/handlebars.rb +0 -3
- data/lib/mysh/init.rb +26 -0
- data/lib/mysh/internal/action.rb +7 -2
- data/lib/mysh/internal/action_pool.rb +9 -4
- data/lib/mysh/internal/actions/command_line.rb +56 -0
- data/lib/mysh/internal/actions/command_line/debug.rb +39 -0
- data/lib/mysh/internal/actions/command_line/init.rb +50 -0
- data/lib/mysh/internal/actions/command_line/load.rb +25 -0
- data/lib/mysh/internal/actions/command_line/post_prompt.rb +44 -0
- data/lib/mysh/internal/actions/command_line/pre_prompt.rb +44 -0
- data/lib/mysh/internal/actions/command_line/prompt.rb +42 -0
- data/lib/mysh/internal/actions/command_line/quit.rb +19 -0
- data/lib/mysh/internal/actions/command_line/usage.rb +23 -0
- data/lib/mysh/internal/actions/comment.rb +20 -0
- data/lib/mysh/internal/actions/elapsed.rb +27 -0
- data/lib/mysh/internal/actions/exit.rb +2 -3
- data/lib/mysh/internal/actions/gls.rb +1 -1
- data/lib/mysh/internal/actions/help/expr.txt +6 -9
- data/lib/mysh/internal/actions/help/quick.txt +6 -0
- data/lib/mysh/internal/actions/help/sub_help.rb +1 -0
- data/lib/mysh/internal/actions/help/usage.txt +8 -0
- data/lib/mysh/internal/actions/help/vars.txt +2 -2
- data/lib/mysh/internal/actions/load.rb +42 -0
- data/lib/mysh/internal/actions/quit.rb +18 -0
- data/lib/mysh/internal/actions/say.rb +20 -0
- data/lib/mysh/internal/actions/show/env.rb +13 -11
- data/lib/mysh/internal/actions/type.rb +4 -3
- data/lib/mysh/internal/actions/vars.rb +5 -5
- data/lib/mysh/internal/manage.rb +1 -1
- data/lib/mysh/process.rb +52 -0
- data/lib/mysh/quick.rb +3 -1
- data/lib/mysh/shell_variables.rb +0 -1
- data/lib/mysh/sources/console.rb +44 -0
- data/lib/mysh/{user_input → sources}/parse.rb +1 -1
- data/lib/mysh/{user_input/smart_source.rb → sources/smart_auto_complete.rb} +1 -1
- data/lib/mysh/sources/string.rb +33 -0
- data/lib/mysh/user_input.rb +14 -30
- data/lib/mysh/version.rb +1 -1
- data/samples/load.rb +6 -0
- data/samples/script.mysh +11 -0
- data/samples/sleep.rb +6 -0
- data/samples/sleep.txt +2 -0
- data/tests/my_shell_tests.rb +6 -4
- metadata +30 -5
- data/lib/mysh/shell_variables/globalize.rb +0 -9
data/lib/mysh/user_input.rb
CHANGED
@@ -2,51 +2,35 @@
|
|
2
2
|
|
3
3
|
require 'mini_readline'
|
4
4
|
|
5
|
-
require_relative '
|
6
|
-
require_relative '
|
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
|
-
|
18
|
-
|
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
|
-
|
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.
|
46
|
-
@input
|
47
|
-
|
48
|
-
|
49
|
-
|
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
data/samples/load.rb
ADDED
data/samples/script.mysh
ADDED
data/samples/sleep.rb
ADDED
data/samples/sleep.txt
ADDED
data/tests/my_shell_tests.rb
CHANGED
@@ -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.
|
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:
|
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
|