cmds 0.1.5 → 0.2.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: d4dd9eb9dad554191cff2d860c105b44339cdcae
4
- data.tar.gz: f89fe5555622db117c1b94abf50307f9758bb062
3
+ metadata.gz: 5544a81fa667995302720f92e88872e4949466ee
4
+ data.tar.gz: 516e1876a14034bdba7b164684335bffbe1f07aa
5
5
  SHA512:
6
- metadata.gz: cac624f99ca246ac0f13c101c8f2066110eed0af071ae159e9d6f41bb82dfaa2534c42c4f4636d4c37d77fadfea90edd546025d1975270eaecab676730b2bc6c
7
- data.tar.gz: f5fd451da65e260f12bfa4b54b47aef1942e79bcc4c346b330e672133687f55cf702bbd2298ae2c9ca851f7f51ece6293bd5bfc99ba0fe32f2d641fdbbc893f9
6
+ metadata.gz: 1037d17f966fe5bc8ae2c463e4b02f3238eaa169463f57421d8890fe200a212aa15307b09adc2c3f87b68272318200d9709f12a4e56248593288c1988c7d9307
7
+ data.tar.gz: e24cdefc7757abaf9e22da51b80201698373952878d41f3f011fb11fd90ec0c48087fda7b4fafe3a7cad2a85d1130699bacfde90dec0a7898441ab142c74d6f4
data/README.md CHANGED
@@ -244,7 +244,7 @@ though keys with those names may be accessed directly via `@kwds.fetch(key)` and
244
244
  to test for a key's presence or optionally include a value, append `?` to the method name:
245
245
 
246
246
  ```
247
- c = Cmds::Cmd.new <<-BLOCK
247
+ c = Cmds.new <<-BLOCK
248
248
  defaults
249
249
  <% if current_host? %>
250
250
  -currentHost <%= current_host %>
@@ -350,7 +350,7 @@ Cmds.sub "50%" # => "50%"
350
350
  ## reuse commands
351
351
 
352
352
  ```
353
- playbook = Cmds::Cmd.new "ansible-playbook -i %{inventory} %{playbook}"
353
+ playbook = Cmds.new "ansible-playbook -i %{inventory} %{playbook}"
354
354
  playbook.call inventory: "./hosts", playbook: "blah.yml"
355
355
  ```
356
356
 
@@ -376,7 +376,7 @@ NEEDS TEST
376
376
  can be accomplished with reuse and currying stuff
377
377
 
378
378
  ```
379
- playbook = Cmds::Cmd.new "ansible-playbook -i %{inventory} %{playbook}", inventory: "inventory/dev"
379
+ playbook = Cmds.new "ansible-playbook -i %{inventory} %{playbook}", inventory: "inventory/dev"
380
380
 
381
381
  # run setup.yml on the development hosts
382
382
  playbook.call playbook: "setup.yml"
@@ -390,7 +390,7 @@ prod_playbook.call playbook: "setup.yml", inventory: "inventory/prod"
390
390
  ## input
391
391
 
392
392
  ```
393
- c = Cmds::Cmd.new("wc", input: "blah blah blah).call
393
+ c = Cmds.new("wc", input: "blah blah blah).call
394
394
  ```
395
395
 
396
396
 
data/Rakefile CHANGED
@@ -57,14 +57,14 @@ namespace :debug do
57
57
  end
58
58
 
59
59
  task :proxy => :conf do
60
- Cmds::Cmd.new("./test/questions.rb").proxy
60
+ Cmds.new("./test/questions.rb").proxy
61
61
  end
62
62
 
63
63
  namespace :capture do
64
64
  desc "capture with io-like input with debugging enabled"
65
65
  task :io_input => :conf do
66
66
  File.open "./test/lines.txt" do |f|
67
- Cmds::Cmd.new("./test/echo_cmd.rb", input: f).capture
67
+ Cmds.new("./test/echo_cmd.rb", input: f).capture
68
68
  end
69
69
  end
70
70
  end # ns capture
data/lib/cmds/debug.rb CHANGED
@@ -1,7 +1,7 @@
1
1
  require 'logger'
2
2
 
3
3
  # debug logging stuff
4
- module Cmds
4
+ class Cmds
5
5
 
6
6
  module Debug
7
7
  # constants
@@ -98,4 +98,4 @@ module Cmds
98
98
  return unless Debug.on?
99
99
  Debug.logger.debug Debug.format(msg, values)
100
100
  end
101
- end # module Cmds
101
+ end # class Cmds
@@ -1,5 +1,7 @@
1
- module Cmds
1
+ class Cmds
2
2
  class ERBContext < BasicObject
3
+ attr_reader :args
4
+
3
5
  def initialize args, kwds
4
6
  @args = args
5
7
  @kwds = kwds
@@ -38,4 +40,4 @@ module Cmds
38
40
  @args.fetch(@arg_index).tap {@arg_index += 1}
39
41
  end
40
42
  end # end ERBContext
41
- end # module Cmds
43
+ end # class Cmds
@@ -1,4 +1,4 @@
1
- module Cmds
1
+ class Cmds
2
2
  class IOHandler
3
3
  attr_accessor :in, :out, :err
4
4
 
@@ -73,4 +73,4 @@ module Cmds
73
73
 
74
74
  # end private
75
75
  end # end IOHandler
76
- end # module Cmds
76
+ end # class Cmds
data/lib/cmds/pipe.rb CHANGED
@@ -1,4 +1,4 @@
1
- module Cmds
1
+ class Cmds
2
2
  # stupid little wrapper around IO.pipe that can have some extra info
3
3
  # attached to it
4
4
  class Pipe
data/lib/cmds/result.rb CHANGED
@@ -2,7 +2,7 @@ require 'nrser/refinements'
2
2
 
3
3
  using NRSER
4
4
 
5
- module Cmds
5
+ class Cmds
6
6
  # a simple data structure returned from calling {Cmds#capture}
7
7
  # on a {Cmd} instance.
8
8
  #
@@ -1,11 +1,11 @@
1
1
  require 'erubis'
2
2
 
3
- module Cmds
3
+ class Cmds
4
4
  # extension of Erubis' EscapedEruby (which auto-escapes `<%= %>` and
5
5
  # leaves `<%== %>` raw) that calls `Cmds.expand_sub` on the value
6
6
  class ShellEruby < Erubis::EscapedEruby
7
7
  def escaped_expr code
8
- "::Cmds.expand_sub(#{code.strip})"
8
+ "::Cmds.tokenize(#{code.strip})"
9
9
  end
10
10
  end
11
- end # module Cmds
11
+ end # class Cmds
data/lib/cmds/spawn.rb CHANGED
@@ -12,7 +12,7 @@ require 'cmds/io_handler'
12
12
 
13
13
  using NRSER
14
14
 
15
- module Cmds
15
+ class Cmds
16
16
  # internal core function to spawn and stream inputs and/or outputs using
17
17
  # threads.
18
18
  #
data/lib/cmds/sugar.rb CHANGED
@@ -21,7 +21,7 @@ def Cmds! template, *args, **kwds, &io_block
21
21
  end
22
22
 
23
23
 
24
- module Cmds
24
+ class Cmds
25
25
  # create a new {Cmd} instance with the template and parameters and
26
26
  # calls {Cmd#prepare}.
27
27
  #
@@ -38,7 +38,7 @@ module Cmds
38
38
  # rendered and formatted command string ready to be executed.
39
39
  #
40
40
  def self.prepare template, *args, **kwds
41
- Cmd.new(template).prepare *args, **kwds
41
+ Cmds.new(template).prepare *args, **kwds
42
42
  end
43
43
 
44
44
 
@@ -57,7 +57,7 @@ module Cmds
57
57
  # result with command string, exist status, stdout and stderr.
58
58
  #
59
59
  def self.capture template, *args, **kwds, &input_block
60
- Cmd.new(template).capture *args, **kwds, &input_block
60
+ Cmds.new(template).capture *args, **kwds, &input_block
61
61
  end
62
62
 
63
63
 
@@ -73,28 +73,28 @@ module Cmds
73
73
  # result with command string, exist status, stdout and stderr.
74
74
  #
75
75
  def self.ok? template, *args, **kwds, &io_block
76
- Cmd.new(template).ok? *args, **kwds, &io_block
76
+ Cmds.new(template).ok? *args, **kwds, &io_block
77
77
  end
78
78
 
79
79
 
80
80
  def self.error? template, *args, **kwds, &io_block
81
- Cmd.new(template).error? *args, **kwds, &io_block
81
+ Cmds.new(template).error? *args, **kwds, &io_block
82
82
  end
83
83
 
84
84
 
85
85
  # create a new {Cmd} and
86
86
  def self.assert template, *args, **kwds, &io_block
87
- Cmd.new(template).capture(*args, **kwds, &io_block).assert
87
+ Cmds.new(template).capture(*args, **kwds, &io_block).assert
88
88
  end
89
89
 
90
90
 
91
91
  def self.stream template, *subs, &input_block
92
- Cmds::Cmd.new(template).stream *subs, &input_block
92
+ Cmds.new(template).stream *subs, &input_block
93
93
  end
94
94
 
95
95
 
96
96
  def self.stream! template, *subs, &input_block
97
- Cmds::Cmd.new(template, assert: true).stream *subs, &input_block
97
+ Cmds.new(template, assert: true).stream *subs, &input_block
98
98
  end # ::stream!
99
99
 
100
100
 
@@ -112,7 +112,7 @@ module Cmds
112
112
  # the command's stdout.
113
113
  #
114
114
  def self.out template, *args, **kwds, &input_block
115
- Cmd.new(template).out *args, **kwds, &input_block
115
+ Cmds.new(template).out *args, **kwds, &input_block
116
116
  end
117
117
 
118
118
 
@@ -133,7 +133,7 @@ module Cmds
133
133
  # if the command fails (non-zero exit status).
134
134
  #
135
135
  def self.out! template, *args, **kwds, &input_block
136
- Cmd.new(template).out! *args, **kwds, &input_block
136
+ Cmds.new(template).out! *args, **kwds, &input_block
137
137
  end
138
138
 
139
139
 
@@ -1,4 +1,4 @@
1
- module Cmds
1
+ class Cmds
2
2
  # hash of common default values used in method options.
3
3
  #
4
4
  # don't use them directly -- use {Cmds.defaults}.
@@ -1,4 +1,4 @@
1
- module Cmds
1
+ class Cmds
2
2
  class Params
3
3
  # Cmds instance execution methods take a splat and block
4
4
  def self.normalize *params, &input
@@ -5,7 +5,7 @@ using NRSER
5
5
 
6
6
  require_relative "defaults"
7
7
 
8
- module Cmds
8
+ class Cmds
9
9
  # turn an option name and value into an array of shell-escaped string
10
10
  # token suitable for use in a command.
11
11
  #
@@ -1,6 +1,6 @@
1
1
  require_relative 'tokenize_option'
2
2
 
3
- module Cmds
3
+ class Cmds
4
4
  # escape option hash.
5
5
  #
6
6
  # this is only useful for the two common option styles:
data/lib/cmds/util.rb CHANGED
@@ -5,7 +5,7 @@ require 'shellwords'
5
5
 
6
6
  require 'cmds/util/tokenize_options'
7
7
 
8
- module Cmds
8
+ class Cmds
9
9
  # class methods
10
10
  # =============
11
11
 
@@ -16,18 +16,28 @@ module Cmds
16
16
  Shellwords.escape str
17
17
  end
18
18
 
19
- # expand one of the substitutions
20
- def self.expand_sub sub
21
- case sub
22
- when nil
23
- # nil is just an empty string, NOT an empty string bash token
24
- ''
25
- when Hash
26
- tokenize_options sub
27
- else
28
- esc sub.to_s
29
- end
30
- end # ::expand_sub
19
+ # tokenize values for the shell. each values is tokenized individually
20
+ # and the results are joined with a space.
21
+ #
22
+ # @param [Array<Object>] *values
23
+ # values to tokenize.
24
+ #
25
+ # @return [String]
26
+ # tokenized string ready for the shell.
27
+ #
28
+ def self.tokenize *values
29
+ values.map {|value|
30
+ case value
31
+ when nil
32
+ # nil is just an empty string, NOT an empty string bash token
33
+ ''
34
+ when Hash
35
+ tokenize_options value
36
+ else
37
+ esc value.to_s
38
+ end
39
+ }.join ' '
40
+ end # ::tokenize
31
41
 
32
42
  # formats a command string
33
43
  def self.format string, with = :squish
@@ -95,4 +105,4 @@ module Cmds
95
105
  )
96
106
  end # ::replace_shortcuts
97
107
 
98
- end # module Cmds
108
+ end # class Cmds
data/lib/cmds/version.rb CHANGED
@@ -1,3 +1,3 @@
1
- module Cmds
2
- VERSION = "0.1.5"
1
+ class Cmds
2
+ VERSION = "0.2.0"
3
3
  end