process_output_wrapper 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +8 -0
- data/Gemfile +6 -0
- data/Gemfile.lock +20 -0
- data/LICENSE.txt +21 -0
- data/README.md +45 -0
- data/Rakefile +2 -0
- data/bin/console +7 -0
- data/bin/setup +6 -0
- data/lib/process_output_wrapper.rb +7 -0
- data/lib/process_output_wrapper/command.rb +95 -0
- data/lib/process_output_wrapper/dsl.rb +9 -0
- data/lib/process_output_wrapper/version.rb +3 -0
- data/lib/process_output_wrapper/whenever.rb +15 -0
- data/process_output_wrapper.gemspec +28 -0
- metadata +85 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: f43843c763315a7998253b5aadec7034e4e1524ccb0d8b8e2dad269a6db80615
|
4
|
+
data.tar.gz: 3d80d67897194c25c22e3af8f0b6b6b9ea0242479f67d799b5c4ea954d4ffcbc
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: dc178be5684de0da88babd04e73b3cecb711752c657a0c4e040a2dbdbf9f24525a1cc9da7b7f787017b13d931a8fc3fb942280d5bd773752b198ffa07aef366c
|
7
|
+
data.tar.gz: da828465539672efaa3db3145c166d7fccb78699721c3110bb654a5a5a801903dc3c74d5b917612d2d510fc1f7d969676906ce23d1b20f742f7f075be01c8d00
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
process_output_wrapper (0.1.0)
|
5
|
+
|
6
|
+
GEM
|
7
|
+
remote: https://rubygems.org/
|
8
|
+
specs:
|
9
|
+
rake (10.4.2)
|
10
|
+
|
11
|
+
PLATFORMS
|
12
|
+
ruby
|
13
|
+
|
14
|
+
DEPENDENCIES
|
15
|
+
bundler (~> 1.17)
|
16
|
+
process_output_wrapper!
|
17
|
+
rake (~> 10.0)
|
18
|
+
|
19
|
+
BUNDLED WITH
|
20
|
+
1.17.3
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2019 Daniel Inkpen
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,45 @@
|
|
1
|
+
# ProcessOutputWrapper
|
2
|
+
|
3
|
+
## Installation
|
4
|
+
|
5
|
+
Add this line to your application's Gemfile:
|
6
|
+
|
7
|
+
```ruby
|
8
|
+
gem 'process_output_wrapper'
|
9
|
+
```
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle
|
14
|
+
|
15
|
+
Or install it yourself as:
|
16
|
+
|
17
|
+
$ gem install process_output_wrapper
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
Here's an example:
|
22
|
+
|
23
|
+
```
|
24
|
+
include ProcessOutputWrapper::DSL
|
25
|
+
|
26
|
+
run_this "echo hello; echo hi; echo hey" do
|
27
|
+
whenever { line.start_with?("he") }
|
28
|
+
.do { puts(line + " world") }
|
29
|
+
end
|
30
|
+
```
|
31
|
+
|
32
|
+
Which outputs the following:
|
33
|
+
|
34
|
+
``` ruby
|
35
|
+
hello world
|
36
|
+
hey world
|
37
|
+
```
|
38
|
+
|
39
|
+
Within the `do` block, you can toggle state on whether output should be filtered using `print_normally!` and `print_wrapped!`.
|
40
|
+
|
41
|
+
If the Ruby process is run with the environment variable `VERBOSE=true`, the output of the process would print as normal.
|
42
|
+
|
43
|
+
## License
|
44
|
+
|
45
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
data/Rakefile
ADDED
data/bin/console
ADDED
data/bin/setup
ADDED
@@ -0,0 +1,95 @@
|
|
1
|
+
module ProcessOutputWrapper
|
2
|
+
class Command
|
3
|
+
def initialize(command)
|
4
|
+
@command = command
|
5
|
+
@line = ""
|
6
|
+
@print_normally = false
|
7
|
+
end
|
8
|
+
|
9
|
+
def execute
|
10
|
+
if ENV['VERBOSE'] == 'true'
|
11
|
+
execute_normally
|
12
|
+
else
|
13
|
+
execute_wrapped
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
def whenever(&blk)
|
18
|
+
Whenever.new(&blk).tap do |w|
|
19
|
+
conditionals << w
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
private
|
24
|
+
|
25
|
+
attr_reader :command,
|
26
|
+
:line
|
27
|
+
|
28
|
+
def print_normally!
|
29
|
+
@print_normally = true
|
30
|
+
end
|
31
|
+
|
32
|
+
def print_wrapped!
|
33
|
+
@print_normally = false
|
34
|
+
end
|
35
|
+
|
36
|
+
def conditionals
|
37
|
+
@conditionals ||= []
|
38
|
+
end
|
39
|
+
|
40
|
+
def check_conditionals
|
41
|
+
return if @line.length == 0
|
42
|
+
@line = without_color(@line)
|
43
|
+
|
44
|
+
conditionals.each do |conditional|
|
45
|
+
if instance_eval(&conditional.condition)
|
46
|
+
instance_eval(&conditional.result)
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
def without_color(str)
|
52
|
+
str.gsub(/\x1B\[([0-9]{1,3}((;[0-9]{1,3})*)?)?[m|K]/, "")
|
53
|
+
end
|
54
|
+
|
55
|
+
def execute_normally
|
56
|
+
system(command)
|
57
|
+
end
|
58
|
+
|
59
|
+
def execute_wrapped
|
60
|
+
@output = ""
|
61
|
+
@line = ""
|
62
|
+
input_thread = nil
|
63
|
+
|
64
|
+
IO.console.raw!
|
65
|
+
|
66
|
+
PTY.spawn(command) do |read, write, pid|
|
67
|
+
write.winsize = STDOUT.winsize
|
68
|
+
Signal.trap(:WINCH) { write.winsize = STDOUT.winsize }
|
69
|
+
input_thread = Thread.new { IO.copy_stream(STDIN, write) }
|
70
|
+
|
71
|
+
read.each_char do |char|
|
72
|
+
@output.concat(char)
|
73
|
+
print(char) if @print_normally
|
74
|
+
|
75
|
+
case char
|
76
|
+
when "\n", "\r"
|
77
|
+
IO.console.cooked!
|
78
|
+
check_conditionals
|
79
|
+
IO.console.raw!
|
80
|
+
@line = ""
|
81
|
+
else
|
82
|
+
@line.concat(char)
|
83
|
+
end
|
84
|
+
end
|
85
|
+
|
86
|
+
Process.wait(pid)
|
87
|
+
end
|
88
|
+
input_thread.kill if input_thread
|
89
|
+
|
90
|
+
IO.console.cooked!
|
91
|
+
|
92
|
+
$?.exitstatus
|
93
|
+
end
|
94
|
+
end
|
95
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
|
2
|
+
lib = File.expand_path("../lib", __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require "process_output_wrapper/version"
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "process_output_wrapper"
|
8
|
+
spec.version = ProcessOutputWrapper::VERSION
|
9
|
+
spec.authors = ["Daniel Inkpen"]
|
10
|
+
spec.email = ["dan2552@gmail.com"]
|
11
|
+
|
12
|
+
spec.summary = %q{Process wrapper which customizes output of the given command}
|
13
|
+
spec.description = spec.summary
|
14
|
+
spec.homepage = "http://github.com/Dan2552/process_output_wrapper"
|
15
|
+
spec.license = "MIT"
|
16
|
+
|
17
|
+
# Specify which files should be added to the gem when it is released.
|
18
|
+
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
19
|
+
spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
|
20
|
+
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
21
|
+
end
|
22
|
+
spec.bindir = "exe"
|
23
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
24
|
+
spec.require_paths = ["lib"]
|
25
|
+
|
26
|
+
spec.add_development_dependency "bundler", "~> 1.17"
|
27
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
28
|
+
end
|
metadata
ADDED
@@ -0,0 +1,85 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: process_output_wrapper
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Daniel Inkpen
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2019-10-05 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.17'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.17'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '10.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '10.0'
|
41
|
+
description: Process wrapper which customizes output of the given command
|
42
|
+
email:
|
43
|
+
- dan2552@gmail.com
|
44
|
+
executables: []
|
45
|
+
extensions: []
|
46
|
+
extra_rdoc_files: []
|
47
|
+
files:
|
48
|
+
- ".gitignore"
|
49
|
+
- Gemfile
|
50
|
+
- Gemfile.lock
|
51
|
+
- LICENSE.txt
|
52
|
+
- README.md
|
53
|
+
- Rakefile
|
54
|
+
- bin/console
|
55
|
+
- bin/setup
|
56
|
+
- lib/process_output_wrapper.rb
|
57
|
+
- lib/process_output_wrapper/command.rb
|
58
|
+
- lib/process_output_wrapper/dsl.rb
|
59
|
+
- lib/process_output_wrapper/version.rb
|
60
|
+
- lib/process_output_wrapper/whenever.rb
|
61
|
+
- process_output_wrapper.gemspec
|
62
|
+
homepage: http://github.com/Dan2552/process_output_wrapper
|
63
|
+
licenses:
|
64
|
+
- MIT
|
65
|
+
metadata: {}
|
66
|
+
post_install_message:
|
67
|
+
rdoc_options: []
|
68
|
+
require_paths:
|
69
|
+
- lib
|
70
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
71
|
+
requirements:
|
72
|
+
- - ">="
|
73
|
+
- !ruby/object:Gem::Version
|
74
|
+
version: '0'
|
75
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
76
|
+
requirements:
|
77
|
+
- - ">="
|
78
|
+
- !ruby/object:Gem::Version
|
79
|
+
version: '0'
|
80
|
+
requirements: []
|
81
|
+
rubygems_version: 3.0.3
|
82
|
+
signing_key:
|
83
|
+
specification_version: 4
|
84
|
+
summary: Process wrapper which customizes output of the given command
|
85
|
+
test_files: []
|