shellfold 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,15 @@
1
+ ---
2
+ !binary "U0hBMQ==":
3
+ metadata.gz: !binary |-
4
+ YzljZDMxNGIyZmRiMjZhOTkyMjlmNWRjNzYzODY2NTA1N2UyZTY1OQ==
5
+ data.tar.gz: !binary |-
6
+ MmNiYmQ1YWRjOGVmYTExMDEyNjEyMmI3MmZiM2IzMWJlN2E3Y2MyNg==
7
+ SHA512:
8
+ metadata.gz: !binary |-
9
+ ZWQ2MGU5NTdhM2RjMGU2OTA2YTllZTg0Y2Y4OGFmY2FjMTUyYzdkN2JlYmVk
10
+ Nzc4OGFkNmFhNzZmNzg0ZmViYjhiODViYjg5ZmRmNTJjMDc4OTU5ZTgzYmY2
11
+ ZWIyN2RkNWRkNTVjMjgyNTczOTM4YTc5ZTExNWE1ZjA0MDA0N2Y=
12
+ data.tar.gz: !binary |-
13
+ MjBjYmJjNDZjY2YyYWY0ZmFhOTEwYWE2ZjI0MGJjMjRkNjkxZGM3MzBhNTBk
14
+ N2IzY2MzYjA2ZDdmODcwNjMyNDU4MmJmMTk1OTE5Yjk5YjlmZDc0NWM2MzEz
15
+ Mzk0MDIyZDU2ZWZlMmFjYTY3Mjc1MmE2M2FlY2FkZDVkODE1MzQ=
data/.gitignore ADDED
@@ -0,0 +1,11 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ /shellfold*.gem
11
+ *.swp
data/.travis.yml ADDED
@@ -0,0 +1,10 @@
1
+ language: ruby
2
+ rvm: 2.2.1
3
+ deploy:
4
+ provider: rubygems
5
+ api_key:
6
+ secure: VcdkzS67nJymeQT1Um45+MEEPOc1yCdqRJLj5PG2kk1enAqqNjVbBokttit/qGbbSswJp7DQIOG5e4vJarHKi1KaASt+0DC+XPfHQeFbMLbCODvApEIa3ZQr3avHq4DOxwzv+7eRj1HCFEQ+yjkZkeYyu1db8W6101pWoNNGAaYaL8Ra0nrfgjMH/xwyujqLKDiPzi5QkIAJy/45bMa96zMq8qKNMGE5B29ISufZ9GVfn93a8rdbCJlBQB01sdz8/r/px5HOHtXcSpHd5kBMPNzL/843rt7cXgmu01Hdo4qglD4GtEfTEogeRIAzqp2sMxa4dECKME5PFMmcfCdenChJyAVZBIBQYjSS4zGmKMwcJ+hIB2Hex9Em2jvxN78DyDlO9TBn+2ljbIPTPqeZpX6S+DneTnowmmVETP7cQrDUhznmst7TDrZS0viCIwySG7DXybfNtWxYm0J4hh5GHxcutDZPNT9f+fmlmqkTgH50QpgzOzYSkaNZfurGiU/nEi6n9SaGIuBEB9RPyWKJbFiFLbmF1wqQdxYRYblKx+OCbNv4/2n6KbhexzjAiy+JvZqMfdW+/mjpyNH5NMyEk+tKCYedqnM/yNgsmDNDJhaXjdbljh59xnwrXruer28szJU2QyXCYtcsgd27surcaTWmmNxWwyCdIrk84oh8nZc=
7
+ gem: shellfold
8
+ on:
9
+ tags: true
10
+ repo: flant/shellfold
data/Gemfile ADDED
@@ -0,0 +1,2 @@
1
+ source 'https://rubygems.org'
2
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2016 Timofey Kirillov
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 @@
1
+ # shellfold
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require 'bundler/gem_tasks'
2
+ require 'rspec/core/rake_task'
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task default: :spec
@@ -0,0 +1,3 @@
1
+ module Shellfold
2
+ VERSION = '0.0.1'
3
+ end
data/lib/shellfold.rb ADDED
@@ -0,0 +1,103 @@
1
+ require 'mixlib/shellout'
2
+ require 'stringio'
3
+
4
+ require 'shellfold/version'
5
+
6
+ module Shellfold
7
+ class Command
8
+ include MonitorMixin
9
+
10
+ attr_reader :desc
11
+ attr_reader :out
12
+ attr_reader :out_bar
13
+ attr_reader :command
14
+
15
+ def initialize(*args, desc: nil,
16
+ out: $stdout,
17
+ last_output_max: 200, **kwargs)
18
+ super()
19
+
20
+ @out = out
21
+ @last_output_max = last_output_max
22
+ @command = Mixlib::ShellOut.new(*args, **kwargs)
23
+ @desc = desc || command.command
24
+ @running = false
25
+ end
26
+
27
+ def run!
28
+ run(ignore_failure: false)
29
+ end
30
+
31
+ def run(ignore_failure: true)
32
+ running!
33
+ write_out{"#{desc}"}
34
+
35
+ thr = Thread.new do
36
+ loop do
37
+ sleep 10
38
+ break unless running?
39
+ write_out{' '} if not @been_here.tap{@been_here = true}
40
+ write_out{'.'}
41
+ end
42
+ end
43
+
44
+ on_command_finish = proc do
45
+ if not command.status.success?
46
+ write_out{" [FAILED: #{command.status.inspect}]"}
47
+ if ignore_failure
48
+ write_out{"\n"}
49
+ else
50
+ msg = ["# COMMAND: #{command.command}\n",
51
+ "# LAST OUTPUT BEGIN:\n",
52
+ *[*command.stdout.lines,
53
+ *command.stderr.lines].reverse[0...@last_output_max].reverse,
54
+ "# LAST OUTPUT END\n"].join
55
+ write_out{"\n#{msg}"}
56
+ end
57
+ else
58
+ write_out{" [DONE]\n"}
59
+ end
60
+ end
61
+
62
+ begin
63
+ command.run_command
64
+ stopped!
65
+ on_command_finish.call
66
+ rescue Mixlib::ShellOut::CommandTimeout
67
+ on_command_finish.call
68
+ ensure
69
+ thr.kill
70
+ end
71
+
72
+ command
73
+ end
74
+
75
+ def running?
76
+ synchronize{ @running }
77
+ end
78
+
79
+ private
80
+
81
+ def write_out(&blk)
82
+ synchronize{ out.write(blk.call) }
83
+ end
84
+
85
+ def running!
86
+ synchronize{ @running = true }
87
+ end
88
+
89
+ def stopped!
90
+ synchronize{ @running = false }
91
+ end
92
+ end # Command
93
+
94
+ class << self
95
+ def run(*args)
96
+ Command.new(*args).run
97
+ end
98
+
99
+ def run!(*args)
100
+ Command.new(*args).run!
101
+ end
102
+ end # << self
103
+ end # Shellfold
data/shellfold.gemspec ADDED
@@ -0,0 +1,27 @@
1
+ lib = File.expand_path('../lib', __FILE__)
2
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
+ require 'shellfold/version'
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = "shellfold"
7
+ spec.version = Shellfold::VERSION
8
+ spec.authors = ["flant"]
9
+ spec.email = ["256@flant.com"]
10
+ spec.summary = "Run shell commands and fold output gently"
11
+ spec.description = "#{spec.summary}."
12
+ spec.license = "MIT"
13
+ spec.homepage = "https://github.com/flant/shellfold"
14
+
15
+ spec.files = `git ls-files -z`.split("\x0")
16
+ spec.require_paths = ["lib"]
17
+
18
+ spec.required_ruby_version = '>= 2.2.1'
19
+
20
+ spec.add_dependency "mixlib-shellout", ">= 2.2.6", "< 3.0"
21
+
22
+ spec.add_development_dependency 'bundler', '~> 1.7'
23
+ spec.add_development_dependency 'rake', '~> 10.0'
24
+ spec.add_development_dependency 'rspec', '~> 3.4', '>= 3.4.0'
25
+ spec.add_development_dependency 'pry', '>= 0.10.3', '< 1.0'
26
+ spec.add_development_dependency 'travis', '~> 1.8', '>= 1.8.2'
27
+ end
@@ -0,0 +1,7 @@
1
+ require 'spec_helper'
2
+
3
+ describe Shellfold do
4
+ it 'has a version number' do
5
+ expect(Shellfold::VERSION).not_to be nil
6
+ end
7
+ end
@@ -0,0 +1,5 @@
1
+ require 'bundler/setup'
2
+
3
+ Bundler.setup
4
+
5
+ require 'shellfold'
metadata ADDED
@@ -0,0 +1,163 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: shellfold
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - flant
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2016-03-17 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: mixlib-shellout
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ! '>='
18
+ - !ruby/object:Gem::Version
19
+ version: 2.2.6
20
+ - - <
21
+ - !ruby/object:Gem::Version
22
+ version: '3.0'
23
+ type: :runtime
24
+ prerelease: false
25
+ version_requirements: !ruby/object:Gem::Requirement
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: 2.2.6
30
+ - - <
31
+ - !ruby/object:Gem::Version
32
+ version: '3.0'
33
+ - !ruby/object:Gem::Dependency
34
+ name: bundler
35
+ requirement: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - ~>
38
+ - !ruby/object:Gem::Version
39
+ version: '1.7'
40
+ type: :development
41
+ prerelease: false
42
+ version_requirements: !ruby/object:Gem::Requirement
43
+ requirements:
44
+ - - ~>
45
+ - !ruby/object:Gem::Version
46
+ version: '1.7'
47
+ - !ruby/object:Gem::Dependency
48
+ name: rake
49
+ requirement: !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - ~>
52
+ - !ruby/object:Gem::Version
53
+ version: '10.0'
54
+ type: :development
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ requirements:
58
+ - - ~>
59
+ - !ruby/object:Gem::Version
60
+ version: '10.0'
61
+ - !ruby/object:Gem::Dependency
62
+ name: rspec
63
+ requirement: !ruby/object:Gem::Requirement
64
+ requirements:
65
+ - - ~>
66
+ - !ruby/object:Gem::Version
67
+ version: '3.4'
68
+ - - ! '>='
69
+ - !ruby/object:Gem::Version
70
+ version: 3.4.0
71
+ type: :development
72
+ prerelease: false
73
+ version_requirements: !ruby/object:Gem::Requirement
74
+ requirements:
75
+ - - ~>
76
+ - !ruby/object:Gem::Version
77
+ version: '3.4'
78
+ - - ! '>='
79
+ - !ruby/object:Gem::Version
80
+ version: 3.4.0
81
+ - !ruby/object:Gem::Dependency
82
+ name: pry
83
+ requirement: !ruby/object:Gem::Requirement
84
+ requirements:
85
+ - - ! '>='
86
+ - !ruby/object:Gem::Version
87
+ version: 0.10.3
88
+ - - <
89
+ - !ruby/object:Gem::Version
90
+ version: '1.0'
91
+ type: :development
92
+ prerelease: false
93
+ version_requirements: !ruby/object:Gem::Requirement
94
+ requirements:
95
+ - - ! '>='
96
+ - !ruby/object:Gem::Version
97
+ version: 0.10.3
98
+ - - <
99
+ - !ruby/object:Gem::Version
100
+ version: '1.0'
101
+ - !ruby/object:Gem::Dependency
102
+ name: travis
103
+ requirement: !ruby/object:Gem::Requirement
104
+ requirements:
105
+ - - ~>
106
+ - !ruby/object:Gem::Version
107
+ version: '1.8'
108
+ - - ! '>='
109
+ - !ruby/object:Gem::Version
110
+ version: 1.8.2
111
+ type: :development
112
+ prerelease: false
113
+ version_requirements: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ~>
116
+ - !ruby/object:Gem::Version
117
+ version: '1.8'
118
+ - - ! '>='
119
+ - !ruby/object:Gem::Version
120
+ version: 1.8.2
121
+ description: Run shell commands and fold output gently.
122
+ email:
123
+ - 256@flant.com
124
+ executables: []
125
+ extensions: []
126
+ extra_rdoc_files: []
127
+ files:
128
+ - .gitignore
129
+ - .travis.yml
130
+ - Gemfile
131
+ - LICENSE.txt
132
+ - README.md
133
+ - Rakefile
134
+ - lib/shellfold.rb
135
+ - lib/shellfold/version.rb
136
+ - shellfold.gemspec
137
+ - spec/shellfold_spec.rb
138
+ - spec/spec_helper.rb
139
+ homepage: https://github.com/flant/shellfold
140
+ licenses:
141
+ - MIT
142
+ metadata: {}
143
+ post_install_message:
144
+ rdoc_options: []
145
+ require_paths:
146
+ - lib
147
+ required_ruby_version: !ruby/object:Gem::Requirement
148
+ requirements:
149
+ - - ! '>='
150
+ - !ruby/object:Gem::Version
151
+ version: 2.2.1
152
+ required_rubygems_version: !ruby/object:Gem::Requirement
153
+ requirements:
154
+ - - ! '>='
155
+ - !ruby/object:Gem::Version
156
+ version: '0'
157
+ requirements: []
158
+ rubyforge_project:
159
+ rubygems_version: 2.4.5
160
+ signing_key:
161
+ specification_version: 4
162
+ summary: Run shell commands and fold output gently
163
+ test_files: []