shellator 0.1.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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 910e5c3bc880f7b7d403eeab00e89019a9a4834d5a5301bd821a1a3b8beba744
4
+ data.tar.gz: 40e4ff1c28a6b836069699c0049f5bced903e31b32940bb86091dc1df3e269e0
5
+ SHA512:
6
+ metadata.gz: e7a901c3d2c85d5da874b71f7f1dc97dae84866488e15125448f6027530576a50762092596b8f2eea054e42de8fa2bade2ad8df972478043de90eb39438ee8fe
7
+ data.tar.gz: 625b540a316833e15534ad635cd2e82174e1c6f7a2ad52c482f1c936e474b70ffac564e2b7fe21b1e0582e8a6fc28c209bb55a83eda18b52a1a5125d8790ed2a
data/.gitignore ADDED
@@ -0,0 +1,8 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
data/.rubocop.yml ADDED
@@ -0,0 +1,162 @@
1
+ # Relaxed.Ruby.Style
2
+ ## Version 2.1
3
+
4
+ Style/Alias:
5
+ Enabled: false
6
+ StyleGuide: http://relaxed.ruby.style/#stylealias
7
+
8
+ Style/AsciiComments:
9
+ Enabled: false
10
+ StyleGuide: http://relaxed.ruby.style/#styleasciicomments
11
+
12
+ Style/BeginBlock:
13
+ Enabled: false
14
+ StyleGuide: http://relaxed.ruby.style/#stylebeginblock
15
+
16
+ Style/BlockDelimiters:
17
+ Enabled: false
18
+ StyleGuide: http://relaxed.ruby.style/#styleblockdelimiters
19
+
20
+ Style/CommentAnnotation:
21
+ Enabled: false
22
+ StyleGuide: http://relaxed.ruby.style/#stylecommentannotation
23
+
24
+ Style/Documentation:
25
+ Enabled: false
26
+ StyleGuide: http://relaxed.ruby.style/#styledocumentation
27
+
28
+ Layout/DotPosition:
29
+ Enabled: false
30
+ StyleGuide: http://relaxed.ruby.style/#layoutdotposition
31
+
32
+ Style/DoubleNegation:
33
+ Enabled: false
34
+ StyleGuide: http://relaxed.ruby.style/#styledoublenegation
35
+
36
+ Style/EndBlock:
37
+ Enabled: false
38
+ StyleGuide: http://relaxed.ruby.style/#styleendblock
39
+
40
+ Style/FormatString:
41
+ Enabled: false
42
+ StyleGuide: http://relaxed.ruby.style/#styleformatstring
43
+
44
+ Style/IfUnlessModifier:
45
+ Enabled: false
46
+ StyleGuide: http://relaxed.ruby.style/#styleifunlessmodifier
47
+
48
+ Style/Lambda:
49
+ Enabled: false
50
+ StyleGuide: http://relaxed.ruby.style/#stylelambda
51
+
52
+ Style/ModuleFunction:
53
+ Enabled: false
54
+ StyleGuide: http://relaxed.ruby.style/#stylemodulefunction
55
+
56
+ Style/MultilineBlockChain:
57
+ Enabled: false
58
+ StyleGuide: http://relaxed.ruby.style/#stylemultilineblockchain
59
+
60
+ Style/NegatedIf:
61
+ Enabled: false
62
+ StyleGuide: http://relaxed.ruby.style/#stylenegatedif
63
+
64
+ Style/NegatedWhile:
65
+ Enabled: false
66
+ StyleGuide: http://relaxed.ruby.style/#stylenegatedwhile
67
+
68
+ Style/ParallelAssignment:
69
+ Enabled: false
70
+ StyleGuide: http://relaxed.ruby.style/#styleparallelassignment
71
+
72
+ Style/PercentLiteralDelimiters:
73
+ Enabled: false
74
+ StyleGuide: http://relaxed.ruby.style/#stylepercentliteraldelimiters
75
+
76
+ Style/PerlBackrefs:
77
+ Enabled: false
78
+ StyleGuide: http://relaxed.ruby.style/#styleperlbackrefs
79
+
80
+ Style/Semicolon:
81
+ Enabled: false
82
+ StyleGuide: http://relaxed.ruby.style/#stylesemicolon
83
+
84
+ Style/SignalException:
85
+ Enabled: false
86
+ StyleGuide: http://relaxed.ruby.style/#stylesignalexception
87
+
88
+ Style/SingleLineBlockParams:
89
+ Enabled: false
90
+ StyleGuide: http://relaxed.ruby.style/#stylesinglelineblockparams
91
+
92
+ Style/SingleLineMethods:
93
+ Enabled: false
94
+ StyleGuide: http://relaxed.ruby.style/#stylesinglelinemethods
95
+
96
+ Layout/SpaceBeforeBlockBraces:
97
+ Enabled: false
98
+ StyleGuide: http://relaxed.ruby.style/#layoutspacebeforeblockbraces
99
+
100
+ Layout/SpaceInsideParens:
101
+ Enabled: false
102
+ StyleGuide: http://relaxed.ruby.style/#layoutspaceinsideparens
103
+
104
+ Style/SpecialGlobalVars:
105
+ Enabled: false
106
+ StyleGuide: http://relaxed.ruby.style/#stylespecialglobalvars
107
+
108
+ Style/StringLiterals:
109
+ Enabled: false
110
+ StyleGuide: http://relaxed.ruby.style/#stylestringliterals
111
+
112
+ Style/TrailingCommaInArguments:
113
+ Enabled: false
114
+ StyleGuide: http://relaxed.ruby.style/#styletrailingcommainarguments
115
+
116
+ Style/TrailingCommaInLiteral:
117
+ Enabled: false
118
+ StyleGuide: http://relaxed.ruby.style/#styletrailingcommainliteral
119
+
120
+ Style/WhileUntilModifier:
121
+ Enabled: false
122
+ StyleGuide: http://relaxed.ruby.style/#stylewhileuntilmodifier
123
+
124
+ Style/WordArray:
125
+ Enabled: false
126
+ StyleGuide: http://relaxed.ruby.style/#stylewordarray
127
+
128
+ Lint/AmbiguousRegexpLiteral:
129
+ Enabled: false
130
+ StyleGuide: http://relaxed.ruby.style/#lintambiguousregexpliteral
131
+
132
+ Lint/AssignmentInCondition:
133
+ Enabled: false
134
+ StyleGuide: http://relaxed.ruby.style/#lintassignmentincondition
135
+
136
+ Metrics/AbcSize:
137
+ Enabled: false
138
+
139
+ Metrics/BlockNesting:
140
+ Enabled: false
141
+
142
+ Metrics/ClassLength:
143
+ Enabled: false
144
+
145
+ Metrics/ModuleLength:
146
+ Enabled: false
147
+
148
+ Metrics/CyclomaticComplexity:
149
+ Enabled: false
150
+
151
+ Metrics/LineLength:
152
+ Enabled: false
153
+
154
+ Metrics/MethodLength:
155
+ Enabled: false
156
+
157
+ Metrics/ParameterLists:
158
+ Enabled: false
159
+
160
+ Metrics/PerceivedComplexity:
161
+ Enabled: false
162
+
@@ -0,0 +1,74 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ In the interest of fostering an open and welcoming environment, we as
6
+ contributors and maintainers pledge to making participation in our project and
7
+ our community a harassment-free experience for everyone, regardless of age, body
8
+ size, disability, ethnicity, gender identity and expression, level of experience,
9
+ nationality, personal appearance, race, religion, or sexual identity and
10
+ orientation.
11
+
12
+ ## Our Standards
13
+
14
+ Examples of behavior that contributes to creating a positive environment
15
+ include:
16
+
17
+ * Using welcoming and inclusive language
18
+ * Being respectful of differing viewpoints and experiences
19
+ * Gracefully accepting constructive criticism
20
+ * Focusing on what is best for the community
21
+ * Showing empathy towards other community members
22
+
23
+ Examples of unacceptable behavior by participants include:
24
+
25
+ * The use of sexualized language or imagery and unwelcome sexual attention or
26
+ advances
27
+ * Trolling, insulting/derogatory comments, and personal or political attacks
28
+ * Public or private harassment
29
+ * Publishing others' private information, such as a physical or electronic
30
+ address, without explicit permission
31
+ * Other conduct which could reasonably be considered inappropriate in a
32
+ professional setting
33
+
34
+ ## Our Responsibilities
35
+
36
+ Project maintainers are responsible for clarifying the standards of acceptable
37
+ behavior and are expected to take appropriate and fair corrective action in
38
+ response to any instances of unacceptable behavior.
39
+
40
+ Project maintainers have the right and responsibility to remove, edit, or
41
+ reject comments, commits, code, wiki edits, issues, and other contributions
42
+ that are not aligned to this Code of Conduct, or to ban temporarily or
43
+ permanently any contributor for other behaviors that they deem inappropriate,
44
+ threatening, offensive, or harmful.
45
+
46
+ ## Scope
47
+
48
+ This Code of Conduct applies both within project spaces and in public spaces
49
+ when an individual is representing the project or its community. Examples of
50
+ representing a project or community include using an official project e-mail
51
+ address, posting via an official social media account, or acting as an appointed
52
+ representative at an online or offline event. Representation of a project may be
53
+ further defined and clarified by project maintainers.
54
+
55
+ ## Enforcement
56
+
57
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
58
+ reported by contacting the project team at ed@edropple.com. All
59
+ complaints will be reviewed and investigated and will result in a response that
60
+ is deemed necessary and appropriate to the circumstances. The project team is
61
+ obligated to maintain confidentiality with regard to the reporter of an incident.
62
+ Further details of specific enforcement policies may be posted separately.
63
+
64
+ Project maintainers who do not follow or enforce the Code of Conduct in good
65
+ faith may face temporary or permanent repercussions as determined by other
66
+ members of the project's leadership.
67
+
68
+ ## Attribution
69
+
70
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
71
+ available at [http://contributor-covenant.org/version/1/4][version]
72
+
73
+ [homepage]: http://contributor-covenant.org
74
+ [version]: http://contributor-covenant.org/version/1/4/
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ source "https://rubygems.org"
2
+
3
+ git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
4
+
5
+ # Specify your gem's dependencies in shellator.gemspec
6
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,26 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ shellator (0.1.0)
5
+
6
+ GEM
7
+ remote: https://rubygems.org/
8
+ specs:
9
+ coderay (1.1.2)
10
+ method_source (0.9.0)
11
+ pry (0.11.3)
12
+ coderay (~> 1.1.0)
13
+ method_source (~> 0.9.0)
14
+ rake (10.5.0)
15
+
16
+ PLATFORMS
17
+ ruby
18
+
19
+ DEPENDENCIES
20
+ bundler (~> 1.16)
21
+ pry
22
+ rake (~> 10.0)
23
+ shellator!
24
+
25
+ BUNDLED WITH
26
+ 1.16.1
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2018 Ed Ropple
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,94 @@
1
+ # Shellator
2
+ Shelling out in Ruby is way harder than it should be. Shellator, which is in
3
+ part a gem _just because it's a good name_, wraps `Open.popen3` in a consistent,
4
+ mostly-not-dumb way.
5
+
6
+ I've been dragging around a variant of [this blog post]() for about three years
7
+ now and finally, _finally_, I have shamed myself into packaging it as a library
8
+ for use by friends, enemies, minions, and miscellaneous alike.
9
+
10
+ Enjoy.
11
+
12
+ ## Installation
13
+ Add this line to your application's Gemfile:
14
+
15
+ ```ruby
16
+ gem 'shellator'
17
+ ```
18
+
19
+ And then execute:
20
+
21
+ $ bundle
22
+
23
+ Or install it yourself as:
24
+
25
+ $ gem install shellator
26
+
27
+ ## Usage
28
+ ### Non-interactive commands ###
29
+ ```rb
30
+ require 'shellator'
31
+
32
+ Shellator.noninteractive("docker build .",
33
+ stdout: ->(line) { puts line },
34
+ stderr: ->(line) { puts line })
35
+
36
+ ```
37
+
38
+ ### Providing non-interactively ###
39
+ `stdin_content` is optional. A newline will be appended after the content is
40
+ written to the subprocess stdout unless `stdin_newlines` is set to false.
41
+
42
+ ```rb
43
+ require 'shellator'
44
+
45
+ Shellator.noninteractive("cat | tr abcdef ABCDEF",
46
+ stdin_content: ["a b c", "d e f"],
47
+ stdout: ->(line) { puts line },
48
+ stderr: ->(line) { puts "ERR: #{line}" })
49
+
50
+ # Output (on stdout):
51
+ # A B C
52
+ # D E F
53
+
54
+ Shellator.noninteractive("cat | tr abcdef ABCDEF",
55
+ stdin_content: ["a b c", "d e f"],
56
+ stdin_newlines: false,
57
+ stdout: ->(line) { puts line },
58
+ stderr: ->(line) { puts "ERR: #{line}" })
59
+
60
+ # Output (on stdout):
61
+ # A B CD E F
62
+ ```
63
+
64
+ ### Interactive commands ###
65
+ Not currently supported. I'd like to figure out a way to weld the `popen3`
66
+ approach
67
+
68
+ ## Development
69
+ After checking out the repo, run `bin/setup` to install dependencies. You can
70
+ also run `bin/console` for an interactive prompt that will allow you to
71
+ experiment.
72
+
73
+ To install this gem onto your local machine, run `bundle exec rake install`. To
74
+ release a new version, update the version number in `version.rb`, and then run
75
+ `bundle exec rake release`, which will create a git tag for the version, push
76
+ git commits and tags, and push the `.gem` file to
77
+ [rubygems.org](https://rubygems.org).
78
+
79
+ ## Contributing
80
+ Bug reports and pull requests are welcome on GitHub at
81
+ https://github.com/eropple/shellator. This project is intended to be a safe,
82
+ welcoming space for collaboration, and contributors are expected to adhere to
83
+ the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
84
+
85
+ ## License
86
+ The gem is available as open source under the terms of the [MIT
87
+ License](https://opensource.org/licenses/MIT).
88
+
89
+ ## Code of Conduct
90
+ Everyone interacting in the Shellator project’s codebases, issue trackers, chat
91
+ rooms and mailing lists is expected to follow the [code of
92
+ conduct](https://github.com/eropple/shellator/blob/master/CODE_OF_CONDUCT.md).
93
+
94
+ [this blog post]: https://nickcharlton.net/posts/ruby-subprocesses-with-stdout-stderr-streams.html
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+ task :default => :spec
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "shellator"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "pry"
14
+ Pry.start
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,3 @@
1
+ module Shellator
2
+ VERSION = "0.1.0"
3
+ end
data/lib/shellator.rb ADDED
@@ -0,0 +1,41 @@
1
+ require "shellator/version"
2
+
3
+ require "open3"
4
+
5
+ module Shellator
6
+ def self.noninteractive(cmd, in_directory: nil, stdin_content: [], stdin_newlines: true, stdout:, stderr:)
7
+ raise "cmd must be a String or array of Strings." \
8
+ unless cmd.is_a?(String) || (cmd.is_a?(Array) && cmd.all? { |c| c.is_a?(Stirng) })
9
+ raise "stdout must be a Proc." unless stdout.is_a?(Proc)
10
+ raise "stderr must be a Proc." unless stderr.is_a?(Proc)
11
+
12
+ stdin_content = [stdin_content].flatten
13
+ raise "stdin_content must be an Array of Strings." \
14
+ unless stdin_content.is_a?(Array) && stdin_content.all? { |c| c.is_a?(String) }
15
+
16
+ computed_cmd = [cmd].flatten.join(" ")
17
+
18
+ Dir.chdir(in_directory || Dir.pwd) do
19
+ Open3.popen3(computed_cmd) do |stdin_stream, stdout_stream, stderr_stream, thread|
20
+ stdin_content.each do |input_line|
21
+ stdin_stream.write(input_line)
22
+
23
+ stdin_stream.write("\n") unless input_line[-1] == "\n" || !stdin_newlines
24
+ end
25
+
26
+ stdin_stream.close
27
+
28
+ { stdout_stream => stdout, stderr_stream => stderr }.each_pair do |stream, callback|
29
+ Thread.new do
30
+ until (line = stream.gets).nil?
31
+ callback.call(line)
32
+ end
33
+ end
34
+ end
35
+
36
+ thread.join
37
+ thread.value
38
+ end
39
+ end
40
+ end
41
+ end
data/shellator.gemspec ADDED
@@ -0,0 +1,26 @@
1
+
2
+ lib = File.expand_path("../lib", __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require "shellator/version"
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "shellator"
8
+ spec.version = Shellator::VERSION
9
+ spec.authors = ["Ed Ropple"]
10
+ spec.email = ["ed@edropple.com"]
11
+
12
+ spec.summary = "A small library to wrap popen3 for easier shell use."
13
+ spec.homepage = "https://github.com/eropple/shellator"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
17
+ f.match(%r{^(test|spec|features)/})
18
+ end
19
+ spec.bindir = "exe"
20
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
21
+ spec.require_paths = ["lib"]
22
+
23
+ spec.add_development_dependency "bundler", "~> 1.16"
24
+ spec.add_development_dependency "pry"
25
+ spec.add_development_dependency "rake", "~> 10.0"
26
+ end
metadata ADDED
@@ -0,0 +1,99 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: shellator
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Ed Ropple
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2018-01-19 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.16'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.16'
27
+ - !ruby/object:Gem::Dependency
28
+ name: pry
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '10.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '10.0'
55
+ description:
56
+ email:
57
+ - ed@edropple.com
58
+ executables: []
59
+ extensions: []
60
+ extra_rdoc_files: []
61
+ files:
62
+ - ".gitignore"
63
+ - ".rubocop.yml"
64
+ - CODE_OF_CONDUCT.md
65
+ - Gemfile
66
+ - Gemfile.lock
67
+ - LICENSE.txt
68
+ - README.md
69
+ - Rakefile
70
+ - bin/console
71
+ - bin/setup
72
+ - lib/shellator.rb
73
+ - lib/shellator/version.rb
74
+ - shellator.gemspec
75
+ homepage: https://github.com/eropple/shellator
76
+ licenses:
77
+ - MIT
78
+ metadata: {}
79
+ post_install_message:
80
+ rdoc_options: []
81
+ require_paths:
82
+ - lib
83
+ required_ruby_version: !ruby/object:Gem::Requirement
84
+ requirements:
85
+ - - ">="
86
+ - !ruby/object:Gem::Version
87
+ version: '0'
88
+ required_rubygems_version: !ruby/object:Gem::Requirement
89
+ requirements:
90
+ - - ">="
91
+ - !ruby/object:Gem::Version
92
+ version: '0'
93
+ requirements: []
94
+ rubyforge_project:
95
+ rubygems_version: 2.7.3
96
+ signing_key:
97
+ specification_version: 4
98
+ summary: A small library to wrap popen3 for easier shell use.
99
+ test_files: []