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 +4 -4
- data/README.md +4 -4
- data/Rakefile +2 -2
- data/lib/cmds/debug.rb +2 -2
- data/lib/cmds/erb_context.rb +4 -2
- data/lib/cmds/io_handler.rb +2 -2
- data/lib/cmds/pipe.rb +1 -1
- data/lib/cmds/result.rb +1 -1
- data/lib/cmds/shell_eruby.rb +3 -3
- data/lib/cmds/spawn.rb +1 -1
- data/lib/cmds/sugar.rb +10 -10
- data/lib/cmds/util/defaults.rb +1 -1
- data/lib/cmds/util/params.rb +1 -1
- data/lib/cmds/util/tokenize_option.rb +1 -1
- data/lib/cmds/util/tokenize_options.rb +1 -1
- data/lib/cmds/util.rb +24 -14
- data/lib/cmds/version.rb +2 -2
- data/lib/cmds.rb +406 -1
- data/scratch/proxy.rb +1 -1
- data/spec/cmds/assert_spec.rb +1 -1
- data/spec/cmds/capture_spec.rb +7 -7
- data/spec/cmds/chomp_spec.rb +5 -5
- data/spec/cmds/curry_spec.rb +1 -1
- data/spec/cmds/env_spec.rb +3 -3
- data/spec/cmds/err_spec.rb +2 -2
- data/spec/cmds/error_spec.rb +2 -2
- data/spec/cmds/ok_spec.rb +2 -2
- data/spec/cmds/out_spec.rb +5 -5
- data/spec/cmds/prepare_spec.rb +10 -2
- data/spec/cmds/stream_spec.rb +4 -4
- data/spec/cmds_spec.rb +1 -1
- metadata +1 -2
- data/lib/cmds/cmd.rb +0 -411
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5544a81fa667995302720f92e88872e4949466ee
|
4
|
+
data.tar.gz: 516e1876a14034bdba7b164684335bffbe1f07aa
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
|
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
|
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
|
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
|
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
|
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
|
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
|
-
|
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 #
|
101
|
+
end # class Cmds
|
data/lib/cmds/erb_context.rb
CHANGED
@@ -1,5 +1,7 @@
|
|
1
|
-
|
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 #
|
43
|
+
end # class Cmds
|
data/lib/cmds/io_handler.rb
CHANGED
data/lib/cmds/pipe.rb
CHANGED
data/lib/cmds/result.rb
CHANGED
data/lib/cmds/shell_eruby.rb
CHANGED
@@ -1,11 +1,11 @@
|
|
1
1
|
require 'erubis'
|
2
2
|
|
3
|
-
|
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.
|
8
|
+
"::Cmds.tokenize(#{code.strip})"
|
9
9
|
end
|
10
10
|
end
|
11
|
-
end #
|
11
|
+
end # class Cmds
|
data/lib/cmds/spawn.rb
CHANGED
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
|
-
|
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
|
-
|
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
|
-
|
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
|
-
|
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
|
-
|
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
|
-
|
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
|
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
|
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
|
-
|
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
|
-
|
136
|
+
Cmds.new(template).out! *args, **kwds, &input_block
|
137
137
|
end
|
138
138
|
|
139
139
|
|
data/lib/cmds/util/defaults.rb
CHANGED
data/lib/cmds/util/params.rb
CHANGED
data/lib/cmds/util.rb
CHANGED
@@ -5,7 +5,7 @@ require 'shellwords'
|
|
5
5
|
|
6
6
|
require 'cmds/util/tokenize_options'
|
7
7
|
|
8
|
-
|
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
|
-
#
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
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 #
|
108
|
+
end # class Cmds
|
data/lib/cmds/version.rb
CHANGED
@@ -1,3 +1,3 @@
|
|
1
|
-
|
2
|
-
VERSION = "0.
|
1
|
+
class Cmds
|
2
|
+
VERSION = "0.2.0"
|
3
3
|
end
|