systemcall 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 91dd4ada1cd740295fe5dbeb3a239a668149f5d0
4
+ data.tar.gz: eaba66f9badaffdf3cb9c17577400be8034d6593
5
+ SHA512:
6
+ metadata.gz: 60ab5951a1a7cf689e7c801c9f32946e2dcd2e0dfcaf7ec454219e2682116fbd47662b4bbbe587125c3e052331260be4112a888bdd491e0ef2491b2789094267
7
+ data.tar.gz: e6215adb3a1c8322b8218333283488fa3e059635aaa69793c4f1b1d8c379e5f5ee7aef77b0dccd6b5dbda6e0dfe692058f1b368a24146b1bf057f4e987a9f6ae
@@ -0,0 +1,11 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+
10
+ # rspec failure tracking
11
+ .rspec_status
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
@@ -0,0 +1,8 @@
1
+ require: rubocop-performance
2
+
3
+ AllCops:
4
+ TargetRubyVersion: '2.3'
5
+
6
+ Metrics/BlockLength:
7
+ Exclude:
8
+ - 'spec/**/*'
@@ -0,0 +1,10 @@
1
+ ---
2
+ sudo: false
3
+ language: ruby
4
+ cache: bundler
5
+ rvm:
6
+ - 2.3.8
7
+ - 2.4.5
8
+ - 2.5.3
9
+ - 2.6.1
10
+ before_install: gem install bundler -v 2.0.1
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ # frozen_string_literal: true
2
+
3
+ source 'https://rubygems.org'
4
+
5
+ # Specify your gem's dependencies in systemcall.gemspec
6
+ gemspec
@@ -0,0 +1,56 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ systemcall (1.0.0)
5
+
6
+ GEM
7
+ remote: https://rubygems.org/
8
+ specs:
9
+ ast (2.4.0)
10
+ diff-lcs (1.3)
11
+ jaro_winkler (1.5.2)
12
+ parallel (1.17.0)
13
+ parser (2.6.3.0)
14
+ ast (~> 2.4.0)
15
+ rainbow (3.0.0)
16
+ rake (10.5.0)
17
+ rspec (3.8.0)
18
+ rspec-core (~> 3.8.0)
19
+ rspec-expectations (~> 3.8.0)
20
+ rspec-mocks (~> 3.8.0)
21
+ rspec-core (3.8.0)
22
+ rspec-support (~> 3.8.0)
23
+ rspec-expectations (3.8.3)
24
+ diff-lcs (>= 1.2.0, < 2.0)
25
+ rspec-support (~> 3.8.0)
26
+ rspec-mocks (3.8.0)
27
+ diff-lcs (>= 1.2.0, < 2.0)
28
+ rspec-support (~> 3.8.0)
29
+ rspec-support (3.8.0)
30
+ rubocop (0.68.0)
31
+ jaro_winkler (~> 1.5.1)
32
+ parallel (~> 1.10)
33
+ parser (>= 2.5, != 2.5.1.1)
34
+ rainbow (>= 2.2.2, < 4.0)
35
+ ruby-progressbar (~> 1.7)
36
+ unicode-display_width (>= 1.4.0, < 1.6)
37
+ rubocop-performance (1.1.0)
38
+ rubocop (>= 0.67.0)
39
+ ruby-progressbar (1.10.0)
40
+ unicode-display_width (1.5.0)
41
+ yard (0.9.19)
42
+
43
+ PLATFORMS
44
+ ruby
45
+
46
+ DEPENDENCIES
47
+ bundler (~> 2.0)
48
+ rake (~> 10.0)
49
+ rspec (~> 3.0)
50
+ rubocop (~> 0.68.0)
51
+ rubocop-performance (~> 1.1.0)
52
+ systemcall!
53
+ yard (~> 0.9.19)
54
+
55
+ BUNDLED WITH
56
+ 2.0.1
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2019 Tobias Casper
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.
@@ -0,0 +1,99 @@
1
+ # System Call
2
+
3
+ [![Build Status](https://travis-ci.org/tlux/systemcall.svg?branch=master)](https://travis-ci.org/tlux/systemcall)
4
+
5
+ A simple wrapper around Ruby's Open3 to call CLI programs and process their
6
+ output.
7
+
8
+ ## Installation
9
+
10
+ Add this line to your application's Gemfile:
11
+
12
+ ```ruby
13
+ gem 'systemcall'
14
+ ```
15
+
16
+ And then execute:
17
+
18
+ $ bundle
19
+
20
+ Or install it yourself as:
21
+
22
+ $ gem install systemcall
23
+
24
+ ## Usage
25
+
26
+ ### Functional
27
+
28
+ To run a CLI program use the following method:
29
+
30
+ ```ruby
31
+ SystemCall.call('which', 'bash')
32
+ SystemCall.call(['which', 'bash'])
33
+ # => #<SystemCall::Result ...>
34
+ ```
35
+
36
+ A command that has been executed returns a result object. When the command has
37
+ run successfully, the result may look like so:
38
+
39
+ ```ruby
40
+ result = SystemCall.call('which', 'bash')
41
+ result.exit_code # => 0
42
+ result.success? # => true
43
+ result.error? # => false
44
+ result.success_result # => "/bin/bash"
45
+ result.error_result # => ""
46
+ result.result # => "/bin/bash"
47
+ ```
48
+
49
+ When the command failed, it may look like this:
50
+
51
+ ```ruby
52
+ result = SystemCall.call('which', 'unknown')
53
+ result.exit_code # => 1
54
+ result.success? # => false
55
+ result.error? # => true
56
+ ```
57
+
58
+ In critical cases, the method may also raise:
59
+
60
+ ```ruby
61
+ SystemCall.call('unknown')
62
+ # ** (Errno::ENOENT) No such file or directory - unknown
63
+ ```
64
+
65
+ ### Mixin
66
+
67
+ Alternatively, you can include the `SystemCall` module directly in your classes
68
+ or modules. The included method name is `system_call` but the API is the same as
69
+ for `SystemCall.call`.
70
+
71
+ ```ruby
72
+ include SystemCall
73
+
74
+ system_call('which', 'bash')
75
+ system_call(['which', 'bash'])
76
+ ```
77
+
78
+ ## Development
79
+
80
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run
81
+ `rake spec` to run the tests. You can also run `bin/console` for an interactive
82
+ prompt that will allow you to experiment.
83
+
84
+ To install this gem onto your local machine, run `bundle exec rake install`. To
85
+ release a new version, update the version number in `version.rb`, and then run
86
+ `bundle exec rake release`, which will create a git tag for the version, push
87
+ git commits and tags, and push the `.gem` file to
88
+ [rubygems.org](https://rubygems.org).
89
+
90
+ ## Contributing
91
+
92
+ Bug reports and pull requests are welcome on GitHub at
93
+ https://github.com/tlux/systemcall.
94
+
95
+ ## License
96
+
97
+ The gem is available as open source under the terms of the
98
+
99
+ [MIT License](https://opensource.org/licenses/MIT).
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'bundler/gem_tasks'
4
+ require 'rspec/core/rake_task'
5
+
6
+ RSpec::Core::RakeTask.new(:spec)
7
+
8
+ task default: :spec
@@ -0,0 +1,15 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ require 'bundler/setup'
5
+ require 'systemcall'
6
+
7
+ # You can add fixtures and/or initialization code here to make experimenting
8
+ # with your gem easier. You can also use a different console, if you like.
9
+
10
+ # (If you use this, don't forget to add pry to your Gemfile!)
11
+ # require 'pry'
12
+ # Pry.start
13
+
14
+ require 'irb'
15
+ IRB.start(__FILE__)
@@ -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,29 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'system_call/version'
4
+
5
+ ##
6
+ # A simple wrapper around Ruby's Open3 to call CLI programs and process their
7
+ # output.
8
+ module SystemCall
9
+ autoload :Command, 'system_call/command'
10
+ autoload :Result, 'system_call/result'
11
+
12
+ ##
13
+ # Initializes and calls a {Command}, then returns the {Result}.
14
+ #
15
+ # @param args [Array] The command line arguments.
16
+ # @return [Result]
17
+ def self.call(*args)
18
+ Command.call(*args)
19
+ end
20
+
21
+ ##
22
+ # Initializes and calls a {Command}, then returns the {Result}.
23
+ #
24
+ # @param args [Array] The command line arguments.
25
+ # @return [Result]
26
+ def system_call(*args)
27
+ Command.call(*args)
28
+ end
29
+ end
@@ -0,0 +1,50 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'open3'
4
+
5
+ module SystemCall
6
+ ##
7
+ # A class responsible for communication with command line interfaces.
8
+ #
9
+ # @!attribute [r] args
10
+ # @return [Array]
11
+ class Command
12
+ attr_reader :args
13
+
14
+ ##
15
+ # Initializes a {Command}.
16
+ #
17
+ # @param args [Array] The command line arguments.
18
+ def initialize(*args)
19
+ @args = args.flatten
20
+ end
21
+
22
+ ##
23
+ # Initializes and calls a {Command}, then returns the {Result}.
24
+ #
25
+ # @param args [Array] The command line arguments.
26
+ # @return [Result]
27
+ def self.call(*args)
28
+ new(*args).call
29
+ end
30
+
31
+ ##
32
+ # Invokes the {Command} and returns the {Result}.
33
+ #
34
+ # @return [Result]
35
+ def call
36
+ Open3.popen3(*args) do |_, stdout, stderr, wait_thr|
37
+ success_result = readlines(stdout)
38
+ error_result = readlines(stderr)
39
+ exit_status = wait_thr.value
40
+ Result.new(exit_status, success_result, error_result)
41
+ end
42
+ end
43
+
44
+ private
45
+
46
+ def readlines(io)
47
+ io.readlines.join.chomp
48
+ end
49
+ end
50
+ end
@@ -0,0 +1,76 @@
1
+ # frozen_string_literal: true
2
+
3
+ module SystemCall
4
+ ##
5
+ # A class that represents a result of a system call.
6
+ #
7
+ # @!attribute [r] exit_status
8
+ # @return [Process::Status] The exit status of the result.
9
+ # @!attribute [r] success_result
10
+ # @return [String] The STDOUT of the result.
11
+ # @!attribute [r] error_result
12
+ # @return [String] The STDERR of the result.
13
+ class Result
14
+ include Comparable
15
+
16
+ attr_reader :exit_status, :success_result, :error_result
17
+
18
+ ##
19
+ # Initializes a new {Result}.
20
+ #
21
+ # @param exit_status [Process::Status] The exit status of the result.
22
+ # @param success_result [String] The STDOUT of the result.
23
+ # @param error_result [String] The STDERR of the result.
24
+ def initialize(exit_status, success_result, error_result)
25
+ @exit_status = exit_status
26
+ @success_result = success_result
27
+ @error_result = error_result
28
+ end
29
+
30
+ ##
31
+ # Gets the exit code of the process.
32
+ #
33
+ # @return [Integer]
34
+ def exit_code
35
+ exit_status.exitstatus
36
+ end
37
+
38
+ ##
39
+ # Indicates whether the command has been executed successfully.
40
+ #
41
+ # @return [Boolean]
42
+ def success?
43
+ exit_status.success?
44
+ end
45
+
46
+ ##
47
+ # Indicates whether the command has not been executed successfully.
48
+ #
49
+ # @return [Boolean]
50
+ def error?
51
+ !success?
52
+ end
53
+
54
+ ##
55
+ # Returns the command result.
56
+ #
57
+ # @return [String] Returns result from {#success_result} when command exited
58
+ # successfully. Otherwise returns result from {#error_result}.
59
+ def result
60
+ success? ? success_result : error_result
61
+ end
62
+
63
+ alias to_s result
64
+
65
+ ##
66
+ # Compares the result with the result of {#to_s} from another object.
67
+ #
68
+ # @param other [#to_s, nil]
69
+ # @return [Integer, nil]
70
+ def <=>(other)
71
+ return nil if other.nil?
72
+
73
+ result <=> other.to_s
74
+ end
75
+ end
76
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module SystemCall
4
+ VERSION = '1.0.0'
5
+ end
@@ -0,0 +1,3 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'system_call'
@@ -0,0 +1,39 @@
1
+ # frozen_string_literal: true
2
+
3
+ lib = File.expand_path('lib', __dir__)
4
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
5
+ require 'system_call/version'
6
+
7
+ Gem::Specification.new do |spec|
8
+ spec.name = 'systemcall'
9
+ spec.version = SystemCall::VERSION
10
+ spec.authors = ['Tobias Casper']
11
+ spec.email = ['tobias.casper@gmail.com']
12
+
13
+ spec.summary = 'A simple wrapper to run CLI programs.'
14
+ spec.description = "A simple wrapper around Ruby's Open3 to call CLI " \
15
+ 'programs and process their output.'
16
+ spec.homepage = 'https://github.com/tlux/systemcall'
17
+ spec.license = 'MIT'
18
+
19
+ # Specify which files should be added to the gem when it is released.
20
+ # The `git ls-files -z` loads the files in the RubyGem that have been added
21
+ # into git.
22
+ spec.files = Dir.chdir(File.expand_path(__dir__)) do
23
+ `git ls-files -z`.split("\x0").reject do |f|
24
+ f.match(%r{^(test|spec|features)/})
25
+ end
26
+ end
27
+
28
+ spec.bindir = 'exe'
29
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
30
+ spec.require_paths = ['lib']
31
+ spec.required_ruby_version = '>= 2.3.0'
32
+
33
+ spec.add_development_dependency 'bundler', '~> 2.0'
34
+ spec.add_development_dependency 'rake', '~> 10.0'
35
+ spec.add_development_dependency 'rspec', '~> 3.0'
36
+ spec.add_development_dependency 'rubocop', '~> 0.68.0'
37
+ spec.add_development_dependency 'rubocop-performance', '~> 1.1.0'
38
+ spec.add_development_dependency 'yard', '~> 0.9.19'
39
+ end
metadata ADDED
@@ -0,0 +1,146 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: systemcall
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Tobias Casper
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2019-04-29 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: '2.0'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '2.0'
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
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '3.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '3.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rubocop
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: 0.68.0
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: 0.68.0
69
+ - !ruby/object:Gem::Dependency
70
+ name: rubocop-performance
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: 1.1.0
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: 1.1.0
83
+ - !ruby/object:Gem::Dependency
84
+ name: yard
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: 0.9.19
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: 0.9.19
97
+ description: A simple wrapper around Ruby's Open3 to call CLI programs and process
98
+ their output.
99
+ email:
100
+ - tobias.casper@gmail.com
101
+ executables: []
102
+ extensions: []
103
+ extra_rdoc_files: []
104
+ files:
105
+ - ".gitignore"
106
+ - ".rspec"
107
+ - ".rubocop.yml"
108
+ - ".travis.yml"
109
+ - Gemfile
110
+ - Gemfile.lock
111
+ - LICENSE.txt
112
+ - README.md
113
+ - Rakefile
114
+ - bin/console
115
+ - bin/setup
116
+ - lib/system_call.rb
117
+ - lib/system_call/command.rb
118
+ - lib/system_call/result.rb
119
+ - lib/system_call/version.rb
120
+ - lib/systemcall.rb
121
+ - systemcall.gemspec
122
+ homepage: https://github.com/tlux/systemcall
123
+ licenses:
124
+ - MIT
125
+ metadata: {}
126
+ post_install_message:
127
+ rdoc_options: []
128
+ require_paths:
129
+ - lib
130
+ required_ruby_version: !ruby/object:Gem::Requirement
131
+ requirements:
132
+ - - ">="
133
+ - !ruby/object:Gem::Version
134
+ version: 2.3.0
135
+ required_rubygems_version: !ruby/object:Gem::Requirement
136
+ requirements:
137
+ - - ">="
138
+ - !ruby/object:Gem::Version
139
+ version: '0'
140
+ requirements: []
141
+ rubyforge_project:
142
+ rubygems_version: 2.6.14
143
+ signing_key:
144
+ specification_version: 4
145
+ summary: A simple wrapper to run CLI programs.
146
+ test_files: []