backticks 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +10 -1
- data/backticks.gemspec +11 -11
- data/lib/backticks.rb +5 -4
- data/lib/backticks/command.rb +2 -0
- data/lib/backticks/ext.rb +7 -0
- data/lib/backticks/runner.rb +14 -8
- data/lib/backticks/version.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b5b80eef1129c850eb5fc8ffb3dc816dcd7853d2
|
4
|
+
data.tar.gz: e49b51b178cf49bdcb0c73dc0e77f44a0a1951cc
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3e267a2020567274d2335bc848421de16736cd9aa370d103b5c561474f9a85a8851909cda40f114b298d59ad583336f66e3caf017e29c63f7711f53b56a82a14
|
7
|
+
data.tar.gz: 728b478ae95cc2676fbf64c22809f4815e11a3b0b50031c7fb002eda006893309f56cb8201e4079e2046c806580f43bd43defc95723ce7834f81620a62e8e289
|
data/README.md
CHANGED
@@ -26,7 +26,16 @@ Or install it yourself as:
|
|
26
26
|
```ruby
|
27
27
|
require 'backticks'
|
28
28
|
|
29
|
-
# The
|
29
|
+
# The lazy way; provides no CLI sugar, but benefits from unbuffered output.
|
30
|
+
# Many Unix utilities produce colorized output when stdout is a TTY; be
|
31
|
+
# prepared to handle escape codes in the output.
|
32
|
+
shell = Object.new ; shell.extend(Backticks::Ext)
|
33
|
+
shell.instance_eval do
|
34
|
+
puts `ls -l`
|
35
|
+
raise 'Oh no!' unless $?.success?
|
36
|
+
end
|
37
|
+
|
38
|
+
# The easy way.
|
30
39
|
output = Backticks.command('ls', R:true, '*.rb')
|
31
40
|
puts "Exit status #{$?.to_i}. Output:"
|
32
41
|
puts output
|
data/backticks.gemspec
CHANGED
@@ -4,22 +4,22 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
|
4
4
|
require 'backticks/version'
|
5
5
|
|
6
6
|
Gem::Specification.new do |spec|
|
7
|
-
spec.name =
|
7
|
+
spec.name = 'backticks'
|
8
8
|
spec.version = Backticks::VERSION
|
9
|
-
spec.authors = [
|
10
|
-
spec.email = [
|
9
|
+
spec.authors = ['Tony Spataro']
|
10
|
+
spec.email = ['xeger@xeger.net']
|
11
11
|
|
12
12
|
spec.summary = %q{Intuitive OOP wrapper for command-line processes}
|
13
|
-
spec.description = %q{Captures
|
14
|
-
spec.homepage =
|
15
|
-
spec.license =
|
13
|
+
spec.description = %q{Captures stdout, stderr and (optionally) stdin; uses PTY to avoid buffering.}
|
14
|
+
spec.homepage = 'https://github.com/xeger/backticks'
|
15
|
+
spec.license = 'MIT'
|
16
16
|
|
17
17
|
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
18
|
-
spec.bindir =
|
18
|
+
spec.bindir = 'exe'
|
19
19
|
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
20
|
-
spec.require_paths = [
|
20
|
+
spec.require_paths = ['lib']
|
21
21
|
|
22
|
-
spec.add_development_dependency
|
23
|
-
spec.add_development_dependency
|
24
|
-
spec.add_development_dependency
|
22
|
+
spec.add_development_dependency 'bundler', '~> 1.10'
|
23
|
+
spec.add_development_dependency 'rake', '~> 10.0'
|
24
|
+
spec.add_development_dependency 'rspec'
|
25
25
|
end
|
data/lib/backticks.rb
CHANGED
@@ -1,7 +1,8 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
1
|
+
require_relative 'backticks/version'
|
2
|
+
require_relative 'backticks/cli'
|
3
|
+
require_relative 'backticks/command'
|
4
|
+
require_relative 'backticks/runner'
|
5
|
+
require_relative 'backticks/ext'
|
5
6
|
|
6
7
|
module Backticks
|
7
8
|
# Run a command.
|
data/lib/backticks/command.rb
CHANGED
@@ -31,6 +31,8 @@ module Backticks
|
|
31
31
|
@stderr = stderr
|
32
32
|
@interactive = interactive
|
33
33
|
|
34
|
+
stdin.close unless @interactive
|
35
|
+
|
34
36
|
@captured_input = String.new.force_encoding(Encoding::BINARY)
|
35
37
|
@captured_output = String.new.force_encoding(Encoding::BINARY)
|
36
38
|
@captured_error = String.new.force_encoding(Encoding::BINARY)
|
data/lib/backticks/runner.rb
CHANGED
@@ -28,8 +28,11 @@ module Backticks
|
|
28
28
|
# @return [Boolean]
|
29
29
|
attr_accessor :buffered
|
30
30
|
|
31
|
+
# @return [#parameters] the CLI-translation object used by this runner
|
32
|
+
attr_reader :cli
|
33
|
+
|
31
34
|
# Create an instance of Runner.
|
32
|
-
# @param [#parameters] cli object
|
35
|
+
# @param [#parameters] cli object used to convert Ruby method parameters into command-line parameters
|
33
36
|
def initialize(cli:Backticks::CLI::Getopt)
|
34
37
|
@interactive = false
|
35
38
|
@buffered = false
|
@@ -39,19 +42,22 @@ module Backticks
|
|
39
42
|
# Run a command whose parameters are expressed using some Rubyish sugar.
|
40
43
|
# This method accepts an arbitrary number of positional parameters; each
|
41
44
|
# parameter can be a Hash, an array, or a simple Object. Arrays and simple
|
42
|
-
# objects are appended to argv as
|
43
|
-
# command-line options and then appended to argv.
|
45
|
+
# objects are appended to argv as words of the command; Hashes are
|
46
|
+
# translated to command-line options and then appended to argv.
|
47
|
+
#
|
48
|
+
# Hashes are processed by @cli, defaulting to Backticks::CLI::Getopt and
|
49
|
+
# easily overridden by passing the `cli` option to #initialize.
|
44
50
|
#
|
45
|
-
#
|
51
|
+
# @see Backticks::CLI::Getopt for option-Hash format information
|
52
|
+
#
|
53
|
+
# @param [Array] args list of command words and options
|
46
54
|
#
|
47
55
|
# @return [Command] the running command
|
48
56
|
#
|
49
57
|
# @example Run docker-compose with complex parameters
|
50
58
|
# command('docker-compose', {file: 'joe.yml'}, 'up', {d:true}, 'mysvc')
|
51
|
-
|
52
|
-
|
53
|
-
def command(*cmd)
|
54
|
-
argv = @cli.parameters(*cmd)
|
59
|
+
def command(*args)
|
60
|
+
argv = @cli.parameters(*args)
|
55
61
|
|
56
62
|
if self.buffered
|
57
63
|
run_buffered(argv)
|
data/lib/backticks/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: backticks
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Tony Spataro
|
@@ -52,8 +52,7 @@ dependencies:
|
|
52
52
|
- - ">="
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: '0'
|
55
|
-
description: Captures
|
56
|
-
avoid buffering.
|
55
|
+
description: Captures stdout, stderr and (optionally) stdin; uses PTY to avoid buffering.
|
57
56
|
email:
|
58
57
|
- xeger@xeger.net
|
59
58
|
executables: []
|
@@ -73,6 +72,7 @@ files:
|
|
73
72
|
- lib/backticks.rb
|
74
73
|
- lib/backticks/cli.rb
|
75
74
|
- lib/backticks/command.rb
|
75
|
+
- lib/backticks/ext.rb
|
76
76
|
- lib/backticks/runner.rb
|
77
77
|
- lib/backticks/version.rb
|
78
78
|
homepage: https://github.com/xeger/backticks
|