backticks 0.3.1 → 0.4.0

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: b155f73a14fe3ee0afa0d26a7e72187cca00a7b3
4
- data.tar.gz: 403f3296c832847f3ba8cde407f7bf2e75ba7a29
3
+ metadata.gz: 156e6dd6cd59ca1201a48b9679e1f6151caf6b43
4
+ data.tar.gz: 225c905201c500af8cde4a7561490befaf797caa
5
5
  SHA512:
6
- metadata.gz: ae13cb81eabdee1ae6e8ee49688aa9224bb3764c3376e759bf71ff5b184a2de2dc5e4bb9752caf6457be5c0cb82d1bcec18c6b28972da09d26c087246f730faf
7
- data.tar.gz: bb8367fb27bf005dd592b6eaaff7532ae3e9663423007c640d1b01c288367af6f0c3b102e488de4f3fa8c145da9e954ac855456cf67dfa2ac2ec9c9887cd3793
6
+ metadata.gz: b7230c03f69e71a6aeadb1cd0f3d43f0a12ad166231d0aecaea8c9c41bf8373e3cb5e3fbdfaf8ddb08be35c4e0632404edafb4b9de36e55213e6166f19134a1d
7
+ data.tar.gz: bb4bfa7199f80179fba4147379667b9e4e80ad2b8d3208e4d072953aaffbc2d42e4c1c8f52ce46059bec9c0b978600c3661b0650c23f2b7330da1fac7d9ddd8f
data/.rspec CHANGED
@@ -1,2 +1,4 @@
1
1
  --format documentation
2
2
  --color
3
+ --order random
4
+ --require spec_helper
@@ -1,4 +1,7 @@
1
+ sudo: false
1
2
  language: ruby
2
3
  rvm:
3
- - 2.2.2
4
- before_install: gem install bundler -v 1.10.6
4
+ - 1.9
5
+ - 2.2
6
+ before_install: gem install bundler -v '~> 1.10'
7
+ script: bundle exec rake spec
data/Gemfile CHANGED
@@ -2,3 +2,7 @@ source 'https://rubygems.org'
2
2
 
3
3
  # Specify your gem's dependencies in backticks.gemspec
4
4
  gemspec
5
+
6
+ group :test do
7
+ gem 'coveralls', require: false
8
+ end
data/README.md CHANGED
@@ -3,6 +3,8 @@
3
3
  Backticks is a powerful, intuitive OOP wrapper for invoking command-line processes and
4
4
  interacting with them.
5
5
 
6
+ ![Build Status](https://travis-ci.org/xeger/backticks.svg) [![Coverage Status](https://coveralls.io/repos/xeger/backticks/badge.svg?branch=master&service=github)](https://coveralls.io/github/xeger/backticks?branch=master)
7
+
6
8
  "Powerful" comes from features that make Backticks especially well suited for time-sensitive
7
9
  or record/playback applications:
8
10
  - Uses [pseudoterminals](https://en.wikipedia.org/wiki/Pseudoterminal) for realtime stdout/stdin
@@ -59,7 +61,7 @@ puts output
59
61
 
60
62
  # The hard way. Allows customized behavior; returns a Command object that
61
63
  # allows you to interact with the running command.
62
- command = Backticks::Runner.new(interactive:true).command('ls', R:true, '*.rb')
64
+ command = Backticks::Runner.new(interactive:true).run('ls', R:true, '*.rb')
63
65
  command.join
64
66
  puts "Exit status: #{command.status.to_i}. Output:"
65
67
  puts command.captured_output
@@ -93,7 +95,7 @@ accordingly:
93
95
  ```ruby
94
96
  require 'io/console'
95
97
  # In IRB, call raw! on same line as command; IRB prompt uses raw I/O
96
- STDOUT.raw! ; Backticks::Runner.new(interactive:true).command('vi').join
98
+ STDOUT.raw! ; Backticks::Runner.new(interactive:true).run('vi').join
97
99
  ```
98
100
 
99
101
  ### Literally Overriding Ruby's Backticks
@@ -19,6 +19,8 @@ Gem::Specification.new do |spec|
19
19
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
20
20
  spec.require_paths = ['lib']
21
21
 
22
+ spec.required_ruby_version = Gem::Requirement.new("~> 2.0")
23
+
22
24
  spec.add_development_dependency 'bundler', '~> 1.10'
23
25
  spec.add_development_dependency 'rake', '~> 10.0'
24
26
  spec.add_development_dependency 'rspec'
@@ -5,31 +5,38 @@ require_relative 'backticks/runner'
5
5
  require_relative 'backticks/ext'
6
6
 
7
7
  module Backticks
8
- # Run a command; return a Command object that can be used to interact with
9
- # the running process.
8
+ # Run a command with default invocation options; return a Command object that
9
+ # can be used to interact with the running process.
10
10
  #
11
- # @param [String] cmd
11
+ # @param [Array] sugar list of command words and options
12
12
  # @return [Backticks::Command] a running command
13
- def self.new(cmd)
14
- Backticks::Runner.new.command(cmd)
13
+ # @see Backticks::Runner#run for a better description of sugar
14
+ # @see Backticks::Runner for more control over process invocation
15
+ def self.new(*sugar)
16
+ Backticks::Runner.new.run(*sugar)
15
17
  end
16
18
 
17
- # Run a command; return its stdout.
19
+ # Run a command with default invocation options; wait for to exit, then return
20
+ # its output. Populate $? with the command's status before returning.
18
21
  #
19
- # @param [String] cmd
22
+ # @param [Array] sugar list of command words and options
20
23
  # @return [String] the command's output
21
- def self.run(cmd)
22
- command = self.new(*cmd)
24
+ # @see Backticks::Runner#run for a better description of sugar
25
+ # @see Backticks::Runner for more control over process invocation
26
+ def self.run(*sugar)
27
+ command = self.new(*sugar)
23
28
  command.join
24
29
  command.captured_output
25
30
  end
26
31
 
27
- # Run a command; return its success or failure.
32
+ # Run a command; return whether it succeeded or failed.
28
33
  #
29
- # @param [String] cmd
34
+ # @param [Array] sugar list of command words and options
30
35
  # @return [Boolean] true if the command succeeded; false otherwise
31
- def self.system(*cmd)
32
- command = self.new(*cmd)
36
+ # @see Backticks::Runner#run for a better description of sugar
37
+ # @see Backticks::Runner for more control over process invocation
38
+ def self.system(*sugar)
39
+ command = self.new(*sugar)
33
40
  command.join
34
41
  $?.success?
35
42
  end
@@ -10,14 +10,14 @@ module Backticks
10
10
  # golang flags, and most Java utilities. It's a great choice of default
11
11
  # CLI.
12
12
  module Getopt
13
- # Translate a series of positional and keyword arguments into command-line
14
- # line parameters consisting of words and options.
13
+ # Translate a series Ruby positional and keyword arguments into command-
14
+ # parameters consisting of words and options.
15
15
  #
16
16
  # Each positional argument can be a Hash, an Array, or another object.
17
17
  # They are handled as follows:
18
18
  # - Hash is translated to a sequence of options; see #options
19
19
  # - Array is appended to the command line as a sequence of words
20
- # - other objects are turned into a strong with #to_s and appended to the command line as a single word
20
+ # - other objects are turned into a string with #to_s and appended to the command line as a single word
21
21
  #
22
22
  # @return [Array] list of String words and options
23
23
  #
@@ -26,10 +26,10 @@ module Backticks
26
26
  #
27
27
  # @example install your favorite gem
28
28
  # parameters('gem', 'install', no_document:true, 'backticks')
29
- def self.parameters(*cmd)
29
+ def self.parameters(*sugar)
30
30
  argv = []
31
31
 
32
- cmd.each do |item|
32
+ sugar.each do |item|
33
33
  case item
34
34
  when Array
35
35
  # list of words to append to argv
@@ -46,7 +46,7 @@ module Backticks
46
46
  argv
47
47
  end
48
48
 
49
- # Translate Ruby method parameters into command-line parameters using a
49
+ # Translate Ruby keyword arguments into command-line parameters using a
50
50
  # notation that is compatible with traditional Unix getopt. Command lines
51
51
  # generated by this method are also mostly compatible with the following:
52
52
  # - GNU getopt
@@ -70,12 +70,12 @@ module Backticks
70
70
  # Unix-like parameters.
71
71
  #
72
72
  # @return [Array] list of String command-line options
73
- def self.options(**opts)
73
+ def self.options(kwargs={})
74
74
  flags = []
75
75
 
76
76
  # Transform opts into golang flags-style command line parameters;
77
77
  # append them to the command.
78
- opts.each do |kw, arg|
78
+ kwargs.each do |kw, arg|
79
79
  if kw.length == 1
80
80
  if arg == true
81
81
  # true: boolean flag
@@ -104,4 +104,4 @@ module Backticks
104
104
  end
105
105
  end
106
106
  end
107
- end
107
+ end
@@ -46,6 +46,8 @@ module Backticks
46
46
  #
47
47
  # @param [Float,Integer] limit number of seconds to wait before returning
48
48
  def join(limit=nil)
49
+ return self if @status
50
+
49
51
  if limit
50
52
  tf = Time.now + limit
51
53
  else
@@ -33,10 +33,22 @@ module Backticks
33
33
 
34
34
  # Create an instance of Runner.
35
35
  # @param [#parameters] cli object used to convert Ruby method parameters into command-line parameters
36
- def initialize(buffered:false, cli:Backticks::CLI::Getopt, interactive:false)
37
- @buffered = buffered
38
- @cli = cli
39
- @interactive = interactive
36
+ def initialize(options={})
37
+ options = {
38
+ :buffered => false,
39
+ :cli => Backticks::CLI::Getopt,
40
+ :interactive => false,
41
+ }.merge(options)
42
+
43
+ @buffered = options[:buffered]
44
+ @cli = options[:cli]
45
+ @interactive = options[:interactive]
46
+ end
47
+
48
+ # @deprecated
49
+ def command(*sugar)
50
+ warn 'Backticks::Runner#command is deprecated; please call #run instead'
51
+ run(*sugar)
40
52
  end
41
53
 
42
54
  # Run a command whose parameters are expressed using some Rubyish sugar.
@@ -50,15 +62,23 @@ module Backticks
50
62
  #
51
63
  # @see Backticks::CLI::Getopt for option-Hash format information
52
64
  #
53
- # @param [Array] args list of command words and options
65
+ # @param [Array] sugar list of command words and options
54
66
  #
55
67
  # @return [Command] the running command
56
68
  #
57
69
  # @example Run docker-compose with complex parameters
58
- # command('docker-compose', {file: 'joe.yml'}, 'up', {d:true}, 'mysvc')
59
- def command(*args)
60
- argv = @cli.parameters(*args)
70
+ # run('docker-compose', {file: 'joe.yml'}, 'up', {d:true}, 'mysvc')
71
+ def run(*sugar)
72
+ run_without_sugar(@cli.parameters(*sugar))
73
+ end
61
74
 
75
+ # Run a command whose argv is specified in the same manner as Kernel#exec,
76
+ # with no Rubyish sugar.
77
+ #
78
+ # @param [Array] argv command to run; argv[0] is program name and the
79
+ # remaining elements are parameters and flags
80
+ # @return [Command] the running command
81
+ def run_without_sugar(argv)
62
82
  if self.buffered
63
83
  run_buffered(argv)
64
84
  else
@@ -1,3 +1,3 @@
1
1
  module Backticks
2
- VERSION = "0.3.1"
2
+ VERSION = "0.4.0"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: backticks
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.1
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tony Spataro
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2016-02-11 00:00:00.000000000 Z
11
+ date: 2016-02-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -85,9 +85,9 @@ require_paths:
85
85
  - lib
86
86
  required_ruby_version: !ruby/object:Gem::Requirement
87
87
  requirements:
88
- - - ">="
88
+ - - "~>"
89
89
  - !ruby/object:Gem::Version
90
- version: '0'
90
+ version: '2.0'
91
91
  required_rubygems_version: !ruby/object:Gem::Requirement
92
92
  requirements:
93
93
  - - ">="