yap-shell 0.5.2 → 0.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.rspec +2 -0
- data/.ruby-version +1 -1
- data/.travis.yml +11 -0
- data/Gemfile.travis +8 -0
- data/README.md +9 -11
- data/addons/history/history.rb +1 -0
- data/addons/history_search/history_search.rb +21 -17
- data/bin/yap +47 -55
- data/bin/yap-dev +0 -1
- data/lib/yap/configuration.rb +25 -0
- data/lib/yap/shell/builtins/alias.rb +16 -0
- data/lib/yap/shell/commands.rb +15 -3
- data/lib/yap/shell/evaluation/shell_expansions.rb +10 -10
- data/lib/yap/shell/evaluation.rb +29 -4
- data/lib/yap/shell/execution/context.rb +3 -2
- data/lib/yap/shell/execution/file_system_command_execution.rb +9 -17
- data/lib/yap/shell/repl.rb +2 -5
- data/lib/yap/shell/version.rb +1 -1
- data/lib/yap/shell.rb +8 -2
- data/lib/yap/world.rb +23 -18
- data/lib/yap.rb +52 -7
- data/spec/features/aliases_spec.rb +78 -0
- data/spec/features/environment_variables_spec.rb +69 -0
- data/spec/features/filesystem_commands_spec.rb +61 -0
- data/spec/features/first_time_spec.rb +45 -0
- data/spec/features/grouping_spec.rb +81 -0
- data/spec/features/line_editing_spec.rb +166 -0
- data/spec/features/range_spec.rb +35 -0
- data/spec/features/redirection_spec.rb +225 -0
- data/spec/features/repetition_spec.rb +118 -0
- data/spec/features/shell_expansions_spec.rb +127 -0
- data/spec/spec_helper.rb +162 -0
- data/spec/support/matchers/have_not_printed.rb +30 -0
- data/spec/support/matchers/have_printed.rb +30 -0
- data/spec/support/very_soon.rb +9 -0
- data/spec/support/yap_spec_dsl.rb +240 -0
- data/yap-shell.gemspec +4 -2
- metadata +69 -8
@@ -0,0 +1,240 @@
|
|
1
|
+
require 'fileutils'
|
2
|
+
require 'pathname'
|
3
|
+
require 'timeout'
|
4
|
+
require 'ostruct'
|
5
|
+
|
6
|
+
module Yap
|
7
|
+
module Spec
|
8
|
+
class OutputFile
|
9
|
+
def initialize(filepath)
|
10
|
+
@filepath = filepath
|
11
|
+
end
|
12
|
+
|
13
|
+
def clear
|
14
|
+
`> #{@filepath}`
|
15
|
+
end
|
16
|
+
|
17
|
+
def read
|
18
|
+
file = File.open(@filepath, 'rb')
|
19
|
+
file.read.gsub(/\u0000/, '')
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
class Shell
|
24
|
+
def self.current
|
25
|
+
@instance
|
26
|
+
end
|
27
|
+
|
28
|
+
def self.new(**kwargs)
|
29
|
+
if @instance
|
30
|
+
@instance.stop
|
31
|
+
end
|
32
|
+
@instance = allocate.tap do |instance|
|
33
|
+
instance.send :initialize, **kwargs
|
34
|
+
instance.start
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
def initialize(dir:, args:, stdout:, stderr:)
|
39
|
+
@childprocess = nil
|
40
|
+
@dir = dir
|
41
|
+
@args = args
|
42
|
+
@stdout = stdout
|
43
|
+
@stderr = stderr
|
44
|
+
end
|
45
|
+
|
46
|
+
def io
|
47
|
+
@childprocess.io if @childprocess
|
48
|
+
end
|
49
|
+
|
50
|
+
def stop
|
51
|
+
if @childprocess
|
52
|
+
@childprocess.stop
|
53
|
+
@childprocess.wait
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
def start
|
58
|
+
return @childprocess if @childprocess
|
59
|
+
@childprocess = begin
|
60
|
+
process = ChildProcess.build(
|
61
|
+
'ruby',
|
62
|
+
@dir,
|
63
|
+
*@args
|
64
|
+
)
|
65
|
+
|
66
|
+
process.io.stdout = @stdout
|
67
|
+
process.io.stderr = @stderr
|
68
|
+
|
69
|
+
# make stdin available, writable
|
70
|
+
process.duplex = true
|
71
|
+
|
72
|
+
# tmpdir = File.dirname(__FILE__) + '/../tmp'
|
73
|
+
process.cwd = File.dirname(__FILE__)
|
74
|
+
process.start
|
75
|
+
|
76
|
+
# make sure clean-up child processes, hang if any fail
|
77
|
+
# to stop
|
78
|
+
at_exit do
|
79
|
+
process.stop
|
80
|
+
process.wait
|
81
|
+
end
|
82
|
+
|
83
|
+
process
|
84
|
+
end
|
85
|
+
end
|
86
|
+
end
|
87
|
+
|
88
|
+
module DSL
|
89
|
+
def very_soon(timeout: self.timeout, &block)
|
90
|
+
@wait_for_last_exception = nil
|
91
|
+
begin
|
92
|
+
Timeout.timeout(timeout) do
|
93
|
+
begin
|
94
|
+
block.call
|
95
|
+
rescue RSpec::Expectations::ExpectationNotMetError => ex
|
96
|
+
@wait_for_last_exception = ex
|
97
|
+
sleep 0.1
|
98
|
+
retry
|
99
|
+
end
|
100
|
+
end
|
101
|
+
rescue Timeout::Error
|
102
|
+
raise @wait_for_last_exception
|
103
|
+
rescue Exception => ex
|
104
|
+
raise ex
|
105
|
+
end
|
106
|
+
end
|
107
|
+
|
108
|
+
def touch(path)
|
109
|
+
FileUtils.touch path
|
110
|
+
end
|
111
|
+
|
112
|
+
def mkdir(path)
|
113
|
+
path = tmp_dir.join(path) unless path == tmp_dir
|
114
|
+
FileUtils.mkdir_p Pathname.new(path).expand_path
|
115
|
+
end
|
116
|
+
|
117
|
+
def chdir(path, &blk)
|
118
|
+
Dir.chdir(path, &blk)
|
119
|
+
end
|
120
|
+
|
121
|
+
def rmdir(path)
|
122
|
+
path = tmp_dir.join(path) unless path == tmp_dir
|
123
|
+
FileUtils.rm_rf Pathname.new(path).expand_path
|
124
|
+
end
|
125
|
+
|
126
|
+
def write_executable_script(filename, contents)
|
127
|
+
file = File.new(filename, 'w+')
|
128
|
+
file.write contents
|
129
|
+
file.chmod 0755
|
130
|
+
file.close
|
131
|
+
end
|
132
|
+
|
133
|
+
def tmp_dir
|
134
|
+
yap_dir.join('tmp/specroot').expand_path
|
135
|
+
end
|
136
|
+
|
137
|
+
def yap_dir
|
138
|
+
Pathname.new File.dirname(__FILE__) + '/../../'
|
139
|
+
end
|
140
|
+
|
141
|
+
def turn_on_debug_log(file: '/tmp/yap-debug.log', debug: '*')
|
142
|
+
ENV['TREEFELL_OUT'] = file
|
143
|
+
ENV['DEBUG'] = debug
|
144
|
+
reinitialize_shell
|
145
|
+
end
|
146
|
+
|
147
|
+
def set_yap_command_line_arguments(*args)
|
148
|
+
@yap_command_line_arguments = args
|
149
|
+
end
|
150
|
+
|
151
|
+
def yap_command_line_arguments
|
152
|
+
@yap_command_line_arguments
|
153
|
+
end
|
154
|
+
|
155
|
+
def initialize_shell
|
156
|
+
Shell.new(
|
157
|
+
dir: yap_dir.join('bin/yap-dev').to_s,
|
158
|
+
args: yap_command_line_arguments,
|
159
|
+
stdout: stdout,
|
160
|
+
stderr: stderr
|
161
|
+
)
|
162
|
+
end
|
163
|
+
|
164
|
+
def reinitialize_shell
|
165
|
+
initialize_shell
|
166
|
+
end
|
167
|
+
|
168
|
+
def shell
|
169
|
+
Shell.current
|
170
|
+
end
|
171
|
+
|
172
|
+
def set_prompt(str)
|
173
|
+
shell.io.stdin.print "!prompt = '#{str}'"
|
174
|
+
enter
|
175
|
+
end
|
176
|
+
|
177
|
+
def typed_content_awaiting_enter?
|
178
|
+
@typed_content_awaiting_enter
|
179
|
+
end
|
180
|
+
|
181
|
+
def type(str)
|
182
|
+
@typed_content_awaiting_enter = true
|
183
|
+
shell.io.stdin.print str
|
184
|
+
end
|
185
|
+
|
186
|
+
def enter
|
187
|
+
@typed_content_awaiting_enter = false
|
188
|
+
shell.io.stdin.print "\r"
|
189
|
+
end
|
190
|
+
|
191
|
+
def clear_all_output
|
192
|
+
output_file.clear
|
193
|
+
error_output_file.clear
|
194
|
+
end
|
195
|
+
|
196
|
+
def output
|
197
|
+
str = ANSIString.new output_file.read
|
198
|
+
without_ansi_str = str.without_ansi.force_encoding(
|
199
|
+
Encoding::ASCII_8BIT
|
200
|
+
).gsub(/(\x9B|\x1B\[)[0-?]*[ -\/]*[@-~]/n, '')
|
201
|
+
end
|
202
|
+
|
203
|
+
def error_output
|
204
|
+
str = ANSIString.new error_output_file.read
|
205
|
+
str.without_ansi.force_encoding(
|
206
|
+
Encoding::ASCII_8BIT
|
207
|
+
).gsub(/(\x9B|\x1B\[)[0-?]*[ -\/]*[@-~]/n, '')
|
208
|
+
end
|
209
|
+
|
210
|
+
def output_file
|
211
|
+
@output_file ||= OutputFile.new(stdout.path)
|
212
|
+
end
|
213
|
+
|
214
|
+
def error_output_file
|
215
|
+
@error_output_file ||= OutputFile.new(stderr.path)
|
216
|
+
end
|
217
|
+
|
218
|
+
def stdout
|
219
|
+
yap_dir
|
220
|
+
@stdout ||= begin
|
221
|
+
File.open yap_dir.join('stdout.log').expand_path, 'wb'
|
222
|
+
end
|
223
|
+
@stdout.sync = true
|
224
|
+
@stdout
|
225
|
+
end
|
226
|
+
|
227
|
+
def stderr
|
228
|
+
@stderr ||= begin
|
229
|
+
File.open yap_dir.join('stderr.log').expand_path, 'wb'
|
230
|
+
end
|
231
|
+
@stderr.sync = true
|
232
|
+
@stderr
|
233
|
+
end
|
234
|
+
|
235
|
+
def timeout
|
236
|
+
@timeout ||= 2 # seconds
|
237
|
+
end
|
238
|
+
end
|
239
|
+
end
|
240
|
+
end
|
data/yap-shell.gemspec
CHANGED
@@ -65,15 +65,17 @@ Gem::Specification.new do |spec|
|
|
65
65
|
spec.require_paths = ["lib"]
|
66
66
|
|
67
67
|
spec.add_dependency "pry-byebug", "~> 3.3.0"
|
68
|
-
spec.add_dependency "yap-shell-parser", "~> 0.
|
68
|
+
spec.add_dependency "yap-shell-parser", "~> 0.7.0"
|
69
69
|
spec.add_dependency "term-ansicolor", "~> 1.3"
|
70
70
|
spec.add_dependency "ruby-termios", "~> 0.9.6"
|
71
71
|
spec.add_dependency "ruby-terminfo", "~> 0.1.1"
|
72
|
-
spec.add_dependency "yap-rawline", "~> 0.
|
72
|
+
spec.add_dependency "yap-rawline", "~> 0.5.0"
|
73
73
|
spec.add_dependency "treefell", "~> 0.2.3"
|
74
74
|
|
75
75
|
spec.add_development_dependency "bundler", "~> 1.6"
|
76
76
|
spec.add_development_dependency "rake", "~> 10"
|
77
|
+
spec.add_development_dependency "rspec", "~> 3.4.0"
|
78
|
+
spec.add_development_dependency "childprocess", "~> 0.5.9"
|
77
79
|
|
78
80
|
#--BEGIN_ADDON_GEM_DEPENDENCIES--#
|
79
81
|
spec.add_dependency "chronic", "~> 0.10.2"
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: yap-shell
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.6.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Zach Dennis
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-
|
11
|
+
date: 2016-06-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: pry-byebug
|
@@ -30,14 +30,14 @@ dependencies:
|
|
30
30
|
requirements:
|
31
31
|
- - "~>"
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version: 0.
|
33
|
+
version: 0.7.0
|
34
34
|
type: :runtime
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
38
|
- - "~>"
|
39
39
|
- !ruby/object:Gem::Version
|
40
|
-
version: 0.
|
40
|
+
version: 0.7.0
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: term-ansicolor
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
@@ -86,14 +86,14 @@ dependencies:
|
|
86
86
|
requirements:
|
87
87
|
- - "~>"
|
88
88
|
- !ruby/object:Gem::Version
|
89
|
-
version: 0.
|
89
|
+
version: 0.5.0
|
90
90
|
type: :runtime
|
91
91
|
prerelease: false
|
92
92
|
version_requirements: !ruby/object:Gem::Requirement
|
93
93
|
requirements:
|
94
94
|
- - "~>"
|
95
95
|
- !ruby/object:Gem::Version
|
96
|
-
version: 0.
|
96
|
+
version: 0.5.0
|
97
97
|
- !ruby/object:Gem::Dependency
|
98
98
|
name: treefell
|
99
99
|
requirement: !ruby/object:Gem::Requirement
|
@@ -136,6 +136,34 @@ dependencies:
|
|
136
136
|
- - "~>"
|
137
137
|
- !ruby/object:Gem::Version
|
138
138
|
version: '10'
|
139
|
+
- !ruby/object:Gem::Dependency
|
140
|
+
name: rspec
|
141
|
+
requirement: !ruby/object:Gem::Requirement
|
142
|
+
requirements:
|
143
|
+
- - "~>"
|
144
|
+
- !ruby/object:Gem::Version
|
145
|
+
version: 3.4.0
|
146
|
+
type: :development
|
147
|
+
prerelease: false
|
148
|
+
version_requirements: !ruby/object:Gem::Requirement
|
149
|
+
requirements:
|
150
|
+
- - "~>"
|
151
|
+
- !ruby/object:Gem::Version
|
152
|
+
version: 3.4.0
|
153
|
+
- !ruby/object:Gem::Dependency
|
154
|
+
name: childprocess
|
155
|
+
requirement: !ruby/object:Gem::Requirement
|
156
|
+
requirements:
|
157
|
+
- - "~>"
|
158
|
+
- !ruby/object:Gem::Version
|
159
|
+
version: 0.5.9
|
160
|
+
type: :development
|
161
|
+
prerelease: false
|
162
|
+
version_requirements: !ruby/object:Gem::Requirement
|
163
|
+
requirements:
|
164
|
+
- - "~>"
|
165
|
+
- !ruby/object:Gem::Version
|
166
|
+
version: 0.5.9
|
139
167
|
- !ruby/object:Gem::Dependency
|
140
168
|
name: chronic
|
141
169
|
requirement: !ruby/object:Gem::Requirement
|
@@ -160,9 +188,12 @@ extensions: []
|
|
160
188
|
extra_rdoc_files: []
|
161
189
|
files:
|
162
190
|
- ".gitignore"
|
191
|
+
- ".rspec"
|
163
192
|
- ".ruby-version"
|
193
|
+
- ".travis.yml"
|
164
194
|
- DESIGN.md
|
165
195
|
- Gemfile
|
196
|
+
- Gemfile.travis
|
166
197
|
- LICENSE.txt
|
167
198
|
- README.md
|
168
199
|
- Rakefile
|
@@ -220,6 +251,21 @@ files:
|
|
220
251
|
- scripts/simulate-long-running
|
221
252
|
- scripts/write-to-stderr.rb
|
222
253
|
- scripts/write-to-stdout.rb
|
254
|
+
- spec/features/aliases_spec.rb
|
255
|
+
- spec/features/environment_variables_spec.rb
|
256
|
+
- spec/features/filesystem_commands_spec.rb
|
257
|
+
- spec/features/first_time_spec.rb
|
258
|
+
- spec/features/grouping_spec.rb
|
259
|
+
- spec/features/line_editing_spec.rb
|
260
|
+
- spec/features/range_spec.rb
|
261
|
+
- spec/features/redirection_spec.rb
|
262
|
+
- spec/features/repetition_spec.rb
|
263
|
+
- spec/features/shell_expansions_spec.rb
|
264
|
+
- spec/spec_helper.rb
|
265
|
+
- spec/support/matchers/have_not_printed.rb
|
266
|
+
- spec/support/matchers/have_printed.rb
|
267
|
+
- spec/support/very_soon.rb
|
268
|
+
- spec/support/yap_spec_dsl.rb
|
223
269
|
- test.rb
|
224
270
|
- update-rawline.sh
|
225
271
|
- yap-shell.gemspec
|
@@ -259,9 +305,24 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
259
305
|
version: '0'
|
260
306
|
requirements: []
|
261
307
|
rubyforge_project:
|
262
|
-
rubygems_version: 2.
|
308
|
+
rubygems_version: 2.5.1
|
263
309
|
signing_key:
|
264
310
|
specification_version: 4
|
265
311
|
summary: The Lagniappe "Yap" shell.
|
266
|
-
test_files:
|
312
|
+
test_files:
|
313
|
+
- spec/features/aliases_spec.rb
|
314
|
+
- spec/features/environment_variables_spec.rb
|
315
|
+
- spec/features/filesystem_commands_spec.rb
|
316
|
+
- spec/features/first_time_spec.rb
|
317
|
+
- spec/features/grouping_spec.rb
|
318
|
+
- spec/features/line_editing_spec.rb
|
319
|
+
- spec/features/range_spec.rb
|
320
|
+
- spec/features/redirection_spec.rb
|
321
|
+
- spec/features/repetition_spec.rb
|
322
|
+
- spec/features/shell_expansions_spec.rb
|
323
|
+
- spec/spec_helper.rb
|
324
|
+
- spec/support/matchers/have_not_printed.rb
|
325
|
+
- spec/support/matchers/have_printed.rb
|
326
|
+
- spec/support/very_soon.rb
|
327
|
+
- spec/support/yap_spec_dsl.rb
|
267
328
|
has_rdoc:
|