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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 4c09ea76ce613d4920ab0f2f0102fa56eb0ddc86
4
- data.tar.gz: 013d631b062d46df861787bf64107cf802fe4580
3
+ metadata.gz: b5b80eef1129c850eb5fc8ffb3dc816dcd7853d2
4
+ data.tar.gz: e49b51b178cf49bdcb0c73dc0e77f44a0a1951cc
5
5
  SHA512:
6
- metadata.gz: 4d05727a43ef3634d734eef36990cf8915072da01ccca1e57993a58b83fc5af2d638366e3d3c9fbe123d7aa99b0e03a9239a79cc178589cb1b0c6d411fab7421
7
- data.tar.gz: 60dba8be758e0ca850c573882ce14ed3da1200f9a6cb62020b2a9b92e2590b7acb396fd6b2914572b5337d7c9b92c559aa2f429158e203beff3c682ff6e80abf
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 easy way
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
@@ -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 = "backticks"
7
+ spec.name = 'backticks'
8
8
  spec.version = Backticks::VERSION
9
- spec.authors = ["Tony Spataro"]
10
- spec.email = ["xeger@xeger.net"]
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 processes' stdout, stderr and (optionally) stdin; uses PTY to avoid buffering.}
14
- spec.homepage = "https://github.com/xeger/backticks"
15
- spec.license = "MIT"
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 = "exe"
18
+ spec.bindir = 'exe'
19
19
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
20
- spec.require_paths = ["lib"]
20
+ spec.require_paths = ['lib']
21
21
 
22
- spec.add_development_dependency "bundler", "~> 1.10"
23
- spec.add_development_dependency "rake", "~> 10.0"
24
- spec.add_development_dependency "rspec"
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
@@ -1,7 +1,8 @@
1
- require "backticks/version"
2
- require "backticks/cli"
3
- require "backticks/command"
4
- require "backticks/runner"
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.
@@ -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)
@@ -0,0 +1,7 @@
1
+ module Backticks
2
+ module Ext
3
+ def `(str)
4
+ Backticks.command(str)
5
+ end
6
+ end
7
+ end
@@ -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 ysed to convert Ruby method parameters into command-line parameters
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 "bare" words; Hashes are translated to
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
- # The
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
- # @see #options for information on Hash-to-flag translation
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)
@@ -1,3 +1,3 @@
1
1
  module Backticks
2
- VERSION = "0.1.0"
2
+ VERSION = "0.1.1"
3
3
  end
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.0
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 processes' stdout, stderr and (optionally) stdin; uses PTY to
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