scallop 0.1.0 → 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/.gitignore +1 -0
- data/lib/scallop/version.rb +1 -1
- data/lib/scallop.rb +37 -10
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2dac1c9873809c992d116dbf21c3e679f56c7b28abb27d39515d5794b8bf9d49
|
4
|
+
data.tar.gz: 03e036131a0daf08132f1f510c9b0efde5de15650764db0a417ddc0312b2a6fb
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: af746113586125b22ee0b7940832cac5fcecde9c725575cedb93576b69a45672ca35335549131077419612e161852bc46684bf4603d4431c3ae361f0175ee5bc
|
7
|
+
data.tar.gz: 0df20b2e7544e886aa53569ecb8f85982ed9320d67220717b7feaef4abe110a8059b827e669bc9b609d7c0dd470406a2f62c16ba1a85d577fb20902733026c49
|
data/.gitignore
CHANGED
data/lib/scallop/version.rb
CHANGED
data/lib/scallop.rb
CHANGED
@@ -19,9 +19,9 @@ class Scallop
|
|
19
19
|
end
|
20
20
|
|
21
21
|
class Result < Hashie::Dash
|
22
|
-
property :stdout
|
23
|
-
property :stderr
|
24
|
-
property :status
|
22
|
+
property :stdout, required: true
|
23
|
+
property :stderr, required: true
|
24
|
+
property :status, required: true
|
25
25
|
|
26
26
|
def self.from_capture3(result)
|
27
27
|
stdout, stderr, status = result
|
@@ -38,6 +38,10 @@ class Scallop
|
|
38
38
|
end
|
39
39
|
end
|
40
40
|
|
41
|
+
class Param < Hashie::Dash
|
42
|
+
property :key, required: true
|
43
|
+
end
|
44
|
+
|
41
45
|
class << self
|
42
46
|
DSL_METHODS = %i{ cmd run run! sudo }
|
43
47
|
|
@@ -46,6 +50,14 @@ class Scallop
|
|
46
50
|
new.public_send(method, *args)
|
47
51
|
end
|
48
52
|
end
|
53
|
+
|
54
|
+
def param(key)
|
55
|
+
Param.new(key: key)
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
def initialize
|
60
|
+
@params = {}
|
49
61
|
end
|
50
62
|
|
51
63
|
def sudo(sudo = true)
|
@@ -54,17 +66,17 @@ class Scallop
|
|
54
66
|
end
|
55
67
|
|
56
68
|
def cmd(*cmd)
|
57
|
-
@cmd =
|
58
|
-
|
59
|
-
|
60
|
-
.map(&Shellwords.method(:escape))
|
61
|
-
.join(" ")
|
69
|
+
@cmd = cmd
|
70
|
+
self
|
71
|
+
end
|
62
72
|
|
73
|
+
def set(params)
|
74
|
+
@params.merge!(params)
|
63
75
|
self
|
64
76
|
end
|
65
77
|
|
66
78
|
def to_command
|
67
|
-
raise ValidationFailed.new("cmd missing") if @cmd.nil?
|
79
|
+
raise Errors::ValidationFailed.new("cmd missing") if @cmd.nil?
|
68
80
|
|
69
81
|
prefix =
|
70
82
|
case @sudo
|
@@ -73,7 +85,22 @@ class Scallop
|
|
73
85
|
else nil
|
74
86
|
end
|
75
87
|
|
76
|
-
|
88
|
+
cmd =
|
89
|
+
[*@cmd]
|
90
|
+
.map do |cmd_part|
|
91
|
+
case cmd_part
|
92
|
+
when Param
|
93
|
+
@params[cmd_part.key].tap do |value|
|
94
|
+
raise Errors::ValidationFailed.new("value for param '#{cmd_part.key}' not set") if value.nil?
|
95
|
+
end
|
96
|
+
else
|
97
|
+
cmd_part.to_s
|
98
|
+
end
|
99
|
+
end
|
100
|
+
.map(&Shellwords.method(:escape))
|
101
|
+
.join(" ")
|
102
|
+
|
103
|
+
[prefix, cmd].compact.join(" ")
|
77
104
|
end
|
78
105
|
|
79
106
|
def run
|