command_line 1.1.0 → 2.0.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: aaa71300b625158d9cf0460e8be73d20fdc1e045ff0f7dcab2e7483019f96408
4
- data.tar.gz: 6d5eb5b7ff2083b75ae156c14038cc01ecbda66572a1cf8c5b9fa017f35b05f1
3
+ metadata.gz: 2be62115c457c82067cee8e0a5239f98e38a66de71e3e8041abdcc3438fa9370
4
+ data.tar.gz: a406fab9a99fe399f84ff5bfa8eda39a579fe939404adef3c37666bc99fa6969
5
5
  SHA512:
6
- metadata.gz: b4335254d86f1369417000bdecc9fd486040918368d3757976e884da50f4a213dc197b5f20de55ed0176497dcd21b3f6998774443928b9967c356019546db639
7
- data.tar.gz: 8116f37462c0cda552988f526bbd75f768db92a9520646959a0cb50328930328ec4b4282ae2da44ec45ef22a66436ab6ac412d80a3f9069c45693560af84eb22
6
+ metadata.gz: 18073bff45489bc86735085782f4f76ab19397e91f421f6bdd68db1c700c74d74919474479366bf5bd660a526288a8167fce1d7e9080a735f12e795e53db950f
7
+ data.tar.gz: 8f0f6075cc00e1f9adabf826441be43e597ab97debd0b3db458e4d8e2bd6e64c0438e98b7c43758e04ae67138934664924ca8528aa112e386dc2e91da7dfde90
@@ -0,0 +1,22 @@
1
+ name: Linux
2
+
3
+ on: [push, pull_request]
4
+
5
+ jobs:
6
+ build:
7
+ runs-on: ubuntu-latest
8
+ strategy:
9
+ matrix:
10
+ ruby: [2.7, 2.6, 2.5]
11
+ steps:
12
+ - uses: actions/checkout@v2
13
+ - name: Set up Ruby ${{ matrix.ruby }}
14
+ uses: actions/setup-ruby@v1
15
+ with:
16
+ ruby-version: ${{ matrix.ruby }}
17
+ - name: Build
18
+ run: |
19
+ gem install bundler
20
+ bundle install --jobs 4 --retry 3
21
+ - name: Test
22
+ run: bundle exec rake
@@ -0,0 +1,22 @@
1
+ name: MacOS
2
+
3
+ on: [push, pull_request]
4
+
5
+ jobs:
6
+ build:
7
+ runs-on: macos-latest
8
+ strategy:
9
+ matrix:
10
+ ruby: [2.7, 2.6, 2.5]
11
+ steps:
12
+ - uses: actions/checkout@v2
13
+ - name: Set up Ruby ${{ matrix.ruby }}
14
+ uses: actions/setup-ruby@v1
15
+ with:
16
+ ruby-version: ${{ matrix.ruby }}
17
+ - name: Build
18
+ run: |
19
+ gem install bundler
20
+ bundle install --jobs 4 --retry 3
21
+ - name: Test
22
+ run: bundle exec rake
@@ -0,0 +1,22 @@
1
+ name: Windows
2
+
3
+ on: [push, pull_request]
4
+
5
+ jobs:
6
+ build:
7
+ runs-on: windows-latest
8
+ strategy:
9
+ matrix:
10
+ ruby: [2.7, 2.6, 2.5]
11
+ steps:
12
+ - uses: actions/checkout@v2
13
+ - name: Set up Ruby ${{ matrix.ruby }}
14
+ uses: actions/setup-ruby@v1
15
+ with:
16
+ ruby-version: ${{ matrix.ruby }}
17
+ - name: Build
18
+ run: |
19
+ gem install bundler
20
+ bundle install --jobs 4 --retry 3
21
+ - name: Test
22
+ run: bundle exec rake
data/.gitignore CHANGED
@@ -3,4 +3,5 @@
3
3
  /pkg/
4
4
  /spec/reports/
5
5
  /spec/examples.txt
6
+ /doc
6
7
  Gemfile.lock
data/.rubocop.yml CHANGED
@@ -1,14 +1,14 @@
1
1
  AllCops:
2
- TargetRubyVersion: 2.4
2
+ TargetRubyVersion: 2.5
3
3
  Exclude:
4
4
  - '*.gemspec'
5
5
  - Gemfile
6
6
  - Rakefile
7
7
  - spec/fixtures/**/*
8
8
  - bin/**/*
9
- Layout/AlignArguments:
9
+ Layout/ArgumentAlignment:
10
10
  EnforcedStyle: with_fixed_indentation
11
- Layout/IndentFirstHashElement:
11
+ Layout/FirstHashElementIndentation:
12
12
  EnforcedStyle: consistent
13
13
  Metrics/BlockLength:
14
14
  Exclude:
data/.yardopts ADDED
@@ -0,0 +1,6 @@
1
+ --markup markdown
2
+ --markup-provider redcarpet
3
+ --readme README.md
4
+ -
5
+ CHANGELOG.md
6
+ LICENSE.txt
data/CHANGELOG.md CHANGED
@@ -1,4 +1,19 @@
1
- # [1.1.0] (TBD)
1
+ # [2.0.0] (2020-04-13)
2
+
3
+ ## Changed
4
+
5
+ - Arguments are now always sent as a single command to `Open3.popen3`. Sending as multiple arguments can cause it to not use the shell. Passing as a single argument ensures the shell is always used.
6
+ - Drop support for Ruby 2.4.
7
+
8
+ ## Added
9
+
10
+ - The `:env` flag now accepts non-string keys and will convert them to strings.
11
+
12
+ ## Fixed
13
+
14
+ - Deprecation warning about keyword arguments.
15
+
16
+ # [1.1.0] (2019-10-23)
2
17
 
3
18
  ## Added
4
19
 
@@ -16,5 +31,6 @@
16
31
 
17
32
  Initial release.
18
33
 
34
+ [2.0.0]: https://github.com/DragonRuby/command_line/compare/v1.1.0...v2.0.0
19
35
  [1.1.0]: https://github.com/DragonRuby/command_line/compare/v1.0.1...v1.1.0
20
36
  [1.0.1]: https://github.com/DragonRuby/command_line/compare/v1.0.0...v1.0.1
data/CONTRIBUTING.md ADDED
@@ -0,0 +1,24 @@
1
+ # Steps
2
+
3
+ 1. [Fork][] the repo.
4
+ 2. Add a breaking test for your change.
5
+ 3. Make the tests pass.
6
+ 4. Push your fork.
7
+ 5. Submit a pull request.
8
+
9
+ ## Code Style
10
+
11
+ This project uses [EditorConfig] to tell editors what formatting to use.
12
+ It's built into many editors and there are plugins for nearly every other editor that will automatically enforce the formatting.
13
+ If you want to handle it manually you can look at the [.editorconfig] file to see the rules to follow.
14
+
15
+ # Testing
16
+
17
+ Running the tests using `rake` (with no args) will also check for style issues in the code.
18
+ Ideally all submissions would pass these checks.
19
+ If the code style is causing issues we can work with you to correct it.
20
+ Don't let it stop you from contributing.
21
+
22
+ [fork]: https://github.com/DragonRuby/command_line
23
+ [EditorConfig]: https://editorconfig.org/
24
+ [.editorconfig]: .editorconfig
data/README.md CHANGED
@@ -1,8 +1,9 @@
1
1
  # CommandLine
2
2
 
3
3
  [![Version](https://img.shields.io/gem/v/command_line.svg?style=flat-square)](https://rubygems.org/gems/command_line)
4
- [![Linux and OS X Build](https://img.shields.io/travis/com/DragonRuby/command_line?label=Linux%20and%20OS%20X&style=flat-square)](https://travis-ci.com/DragonRuby/command_line)
5
- [![Windows Build](https://img.shields.io/appveyor/ci/AaronLasseigne/command-line?label=Windows&style=flat-square)](https://ci.appveyor.com/project/AaronLasseigne/command-line)
4
+ [![Linux Build](https://img.shields.io/github/workflow/status/DragonRuby/command_line/Linux?label=Linux&style=flat-square)](https://github.com/DragonRuby/command_line/actions?query=workflow%3ALinux)
5
+ [![MacOS Build](https://img.shields.io/github/workflow/status/DragonRuby/command_line/MacOS?label=MacOS&style=flat-square)](https://github.com/DragonRuby/command_line/actions?query=workflow%3AMacOS)
6
+ [![Windows Build](https://img.shields.io/github/workflow/status/DragonRuby/command_line/Windows?label=Windows&style=flat-square)](https://github.com/DragonRuby/command_line/actions?query=workflow%3AWindows)
6
7
 
7
8
  CommandLine provides an easier way to run command-line applications.
8
9
  It captures all outputs, can handle applications that require stdin, and can pass environment variables.
@@ -17,13 +18,13 @@ This project uses [Semantic Versioning](http://semver.org/spec/v2.0.0.html).
17
18
  Add this line to your application's Gemfile:
18
19
 
19
20
  ```ruby
20
- gem 'command_line', '~> 1.1'
21
+ gem 'command_line', '~> 2.0'
21
22
  ```
22
23
 
23
24
  If you want `command_line` available globally you can add this line to your application's Gemfile:
24
25
 
25
26
  ```ruby
26
- gem 'command_line', '~> 1.1', require: 'command_line/global'
27
+ gem 'command_line', '~> 2.0', require: 'command_line/global'
27
28
  ```
28
29
 
29
30
  Or manually install it yourself with:
@@ -74,7 +75,7 @@ end
74
75
  Environment variables can be passed after the command and arguments are passed.
75
76
 
76
77
  ```ruby
77
- command_line('some_webserver', env: { 'PORT' => '80' })
78
+ command_line('some_webserver', env: { PORT: '80' })
78
79
  ```
79
80
 
80
81
  If you're concerned about the command running too long you can set a `:timeout`.
@@ -106,11 +107,3 @@ end
106
107
  ```
107
108
 
108
109
  This will make `command_line` available in your test suite.
109
-
110
- ## Contributing
111
-
112
- Bug reports and pull requests are welcome on GitHub at https://github.com/DragonRuby/command_line.
113
-
114
- ## License
115
-
116
- The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
data/command_line.gemspec CHANGED
@@ -1,6 +1,4 @@
1
- lib = File.expand_path('../lib', __FILE__)
2
- $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
- require 'command_line/version'
1
+ require_relative 'lib/command_line/version'
4
2
 
5
3
  Gem::Specification.new do |spec|
6
4
  spec.name = 'command_line'
@@ -29,8 +27,9 @@ Gem::Specification.new do |spec|
29
27
  spec.require_paths = ['lib']
30
28
 
31
29
  spec.add_development_dependency 'bundler', '~> 2.0'
32
- spec.add_development_dependency 'rake', '~> 10.0'
30
+ spec.add_development_dependency 'rake', '~> 13.0'
33
31
  spec.add_development_dependency 'rspec', '~> 3.9'
34
- spec.add_development_dependency 'rubocop', '~> 0.75.0'
32
+ spec.add_development_dependency 'rubocop', '~> 0.81.0'
35
33
  spec.add_development_dependency 'yard', '~> 0.9.20'
34
+ spec.add_development_dependency 'redcarpet', '~> 3.5.0'
36
35
  end
data/lib/command_line.rb CHANGED
@@ -27,9 +27,9 @@ module CommandLine
27
27
  # @param command [String] The command to run.
28
28
  # @param args [Array] Any arguments passed to the command. All arguments will
29
29
  # be converted to strings using `to_s`.
30
- # @param [Hash] env: Pass environment variables to use. The key should
31
- # be a String representing the environment variable name. The value
32
- # is the value you want that variable to have.
30
+ # @param [Hash] env: Pass environment variables to use. The key is the name
31
+ # of the environment variable. The value is the value you want that variable
32
+ # to have.
33
33
  # @param [Integer, Float, nil] Number of seconds to wait for the block to
34
34
  # terminate. Floats can be used to specify fractional seconds. A value of 0
35
35
  # or nil will execute the block without any timeout.
@@ -47,7 +47,7 @@ module CommandLine
47
47
  # end
48
48
  #
49
49
  # @example
50
- # command_line('some_webserver', env: { 'PORT' => '80' })
50
+ # command_line('some_webserver', env: { PORT: '80' })
51
51
  #
52
52
  # @return [Result]
53
53
  def command_line(command, *args, env: {}, timeout: nil)
@@ -55,29 +55,29 @@ module CommandLine
55
55
  stderr = ''
56
56
  status = nil
57
57
 
58
- Open3.popen3(env, command.to_str, *args.map(&:to_s)) do |i, o, e, wait_thr|
59
- begin
60
- threads = []
58
+ full_command = [command, *args].map(&:to_s).join(' ')
59
+ environment = env.transform_keys(&:to_s)
60
+ Open3.popen3(environment, full_command) do |i, o, e, wait_thr|
61
+ threads = []
61
62
 
62
- Timeout.timeout(timeout, TimeoutError) do
63
- yield i if block_given?
63
+ Timeout.timeout(timeout, TimeoutError) do
64
+ yield i if block_given?
64
65
 
65
- threads << Thread.new { stdout = o.read }
66
- threads << Thread.new { stderr = e.read }
67
- threads.each(&:join)
68
- status = wait_thr.value
69
- end
70
- rescue TimeoutError => e
71
- threads.map(&:kill)
72
-
73
- raise e
66
+ threads << Thread.new { stdout = o.read }
67
+ threads << Thread.new { stderr = e.read }
68
+ threads.each(&:join)
69
+ status = wait_thr.value
74
70
  end
71
+ rescue TimeoutError => e
72
+ threads.map(&:kill)
73
+
74
+ raise e
75
75
  end
76
76
 
77
77
  Result.new(stdout, stderr, status)
78
78
  end
79
79
 
80
- # Same as CommandLine.command_line except that a failure on exit raises an
80
+ # Same as {CommandLine.command_line} except that a failure on exit raises an
81
81
  # error.
82
82
  #
83
83
  # @see CommandLine.command_line
@@ -9,9 +9,9 @@ require 'command_line'
9
9
  # @param command [String] The command to run.
10
10
  # @param args [Array] Any arguments passed to the command. All arguments will
11
11
  # be converted to strings using `to_s`.
12
- # @param [Hash] env: Pass environment variables to use. The key should
13
- # be a String representing the environment variable name. The value
14
- # is the value you want that variable to have.
12
+ # @param [Hash] env: Pass environment variables to use. The key is the name
13
+ # of the environment variable. The value is the value you want that variable
14
+ # to have.
15
15
  # @param [Integer, Float, nil] Number of seconds to wait for the block to
16
16
  # terminate. Floats can be used to specify fractional seconds. A value of 0
17
17
  # or nil will execute the block without any timeout.
@@ -29,11 +29,11 @@ require 'command_line'
29
29
  # end
30
30
  #
31
31
  # @example
32
- # command_line('some_webserver', env: { 'PORT' => '80' })
32
+ # command_line('some_webserver', env: { PORT: '80' })
33
33
  #
34
34
  # @return [Result]
35
- def command_line(*args, &block)
36
- CommandLine.command_line(*args, &block)
35
+ def command_line(*args, **kwargs, &block)
36
+ CommandLine.command_line(*args, **kwargs, &block)
37
37
  end
38
38
 
39
39
  # Same as CommandLine.command_line except that a failure on exit raises an
@@ -51,6 +51,6 @@ end
51
51
  # @return [Result]
52
52
  # @raise [CommandLine::ExitFailureError] If the application exits with an
53
53
  # error status. The message will be the contents of Result#stderr.
54
- def command_line!(*args, &block)
55
- CommandLine.command_line!(*args, &block)
54
+ def command_line!(*args, **kwargs, &block)
55
+ CommandLine.command_line!(*args, **kwargs, &block)
56
56
  end
@@ -27,7 +27,7 @@ module CommandLine
27
27
  # @return [String]
28
28
  attr_reader :stderr
29
29
 
30
- # Returns true if the application exited normally.
30
+ # Returns `true` if the application exited normally.
31
31
  #
32
32
  # @example
33
33
  # command_line('grep').exited?
@@ -50,7 +50,7 @@ module CommandLine
50
50
  @status.exitstatus
51
51
  end
52
52
 
53
- # Returns true if the command exited normally with a success status.
53
+ # Returns `true` if the command exited normally with a success status.
54
54
  #
55
55
  # @example
56
56
  # command_line('echo', 'hi').success?
@@ -61,7 +61,7 @@ module CommandLine
61
61
  !@status.nil? && @status.success?
62
62
  end
63
63
 
64
- # Returns true if the command failed to exit normally or exited with a
64
+ # Returns `true` if the command failed to exit normally or exited with a
65
65
  # failing status.
66
66
  #
67
67
  # @example
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module CommandLine
4
- VERSION = '1.1.0'
4
+ VERSION = '2.0.0'
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: command_line
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.0
4
+ version: 2.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Aaron Lasseigne
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2019-10-23 00:00:00.000000000 Z
11
+ date: 2020-04-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -30,14 +30,14 @@ dependencies:
30
30
  requirements:
31
31
  - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: '10.0'
33
+ version: '13.0'
34
34
  type: :development
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: '10.0'
40
+ version: '13.0'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: rspec
43
43
  requirement: !ruby/object:Gem::Requirement
@@ -58,14 +58,14 @@ dependencies:
58
58
  requirements:
59
59
  - - "~>"
60
60
  - !ruby/object:Gem::Version
61
- version: 0.75.0
61
+ version: 0.81.0
62
62
  type: :development
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
66
  - - "~>"
67
67
  - !ruby/object:Gem::Version
68
- version: 0.75.0
68
+ version: 0.81.0
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: yard
71
71
  requirement: !ruby/object:Gem::Requirement
@@ -80,6 +80,20 @@ dependencies:
80
80
  - - "~>"
81
81
  - !ruby/object:Gem::Version
82
82
  version: 0.9.20
83
+ - !ruby/object:Gem::Dependency
84
+ name: redcarpet
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: 3.5.0
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: 3.5.0
83
97
  description: An easier way execute command line applications and get all of the output.
84
98
  email:
85
99
  - aaron.lasseigne@dragonruby.org
@@ -88,16 +102,19 @@ extensions: []
88
102
  extra_rdoc_files: []
89
103
  files:
90
104
  - ".editorconfig"
105
+ - ".github/workflows/linux.yml"
106
+ - ".github/workflows/macos.yml"
107
+ - ".github/workflows/windows.yml"
91
108
  - ".gitignore"
92
109
  - ".rspec"
93
110
  - ".rubocop.yml"
94
- - ".travis.yml"
111
+ - ".yardopts"
95
112
  - CHANGELOG.md
113
+ - CONTRIBUTING.md
96
114
  - Gemfile
97
115
  - LICENSE.txt
98
116
  - README.md
99
117
  - Rakefile
100
- - appveyor.yml
101
118
  - bin/console
102
119
  - bin/setup
103
120
  - command_line.gemspec
@@ -127,7 +144,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
127
144
  - !ruby/object:Gem::Version
128
145
  version: '0'
129
146
  requirements: []
130
- rubygems_version: 3.0.3
147
+ rubygems_version: 3.1.2
131
148
  signing_key:
132
149
  specification_version: 4
133
150
  summary: An easier way execute command line applications and get all of the output.
data/.travis.yml DELETED
@@ -1,23 +0,0 @@
1
- language: ruby
2
- before_install: # for bundler 2.0+
3
- - gem install bundler
4
- script: bundle exec rake $RAKE_TASK
5
- matrix:
6
- include:
7
- # Linux - Tests and Linting
8
- - os: linux
9
- rvm: 2.6
10
- - os: linux
11
- rvm: 2.5
12
- - os: linux
13
- rvm: 2.4
14
- # OS X - Tests
15
- - os: osx
16
- rvm: 2.6
17
- env: RAKE_TASK=spec
18
- - os: osx
19
- rvm: 2.5
20
- env: RAKE_TASK=spec
21
- - os: osx
22
- rvm: 2.4
23
- env: RAKE_TASK=spec
data/appveyor.yml DELETED
@@ -1,19 +0,0 @@
1
- environment:
2
- matrix:
3
- - RUBY_VERSION: 26
4
- - RUBY_VERSION: 25
5
- - RUBY_VERSION: 24
6
-
7
- install:
8
- - set PATH=C:\Ruby%RUBY_VERSION%\bin;%PATH%
9
- - bundle install
10
-
11
- build: off
12
-
13
- before_test:
14
- - ruby -v
15
- - gem -v
16
- - bundle -v
17
-
18
- test_script:
19
- - bundle exec rake spec