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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 350b01648cfd3ae1c8f431daeb9586e8720f629b2f3895f32d31b0334fdbb5a3
4
- data.tar.gz: 5bf083a1baceeb1d1026fa4fb18e51ed6b6fb62a0be065ecf94596696805c091
3
+ metadata.gz: 2dac1c9873809c992d116dbf21c3e679f56c7b28abb27d39515d5794b8bf9d49
4
+ data.tar.gz: 03e036131a0daf08132f1f510c9b0efde5de15650764db0a417ddc0312b2a6fb
5
5
  SHA512:
6
- metadata.gz: 69010f0366eaed9b2aa0011c6d9208bf59971d42462bb37da40199181d22219ca7e9ddeb209d49a0e98f7d75613b370627f1886e63818f651c143acf5977de58
7
- data.tar.gz: 670d48fd373609ec1107ccf7a1a0d0d8f5fb373121d8e59bb12e77b4d9d6baf1663d0e21cd3d0b44a498c5fd0f1ff7ac7e7320c9dcdb206cd771e4a3735f9200
6
+ metadata.gz: af746113586125b22ee0b7940832cac5fcecde9c725575cedb93576b69a45672ca35335549131077419612e161852bc46684bf4603d4431c3ae361f0175ee5bc
7
+ data.tar.gz: 0df20b2e7544e886aa53569ecb8f85982ed9320d67220717b7feaef4abe110a8059b827e669bc9b609d7c0dd470406a2f62c16ba1a85d577fb20902733026c49
data/.gitignore CHANGED
@@ -6,6 +6,7 @@
6
6
  /pkg/
7
7
  /spec/reports/
8
8
  /tmp/
9
+ /*.gem
9
10
 
10
11
  # rspec failure tracking
11
12
  .rspec_status
@@ -1,3 +1,3 @@
1
1
  class Scallop
2
- VERSION = "0.1.0"
2
+ VERSION = "0.2.0"
3
3
  end
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
- [*cmd]
59
- .map(&:to_s)
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
- [prefix, @cmd].compact.join(" ")
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
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: scallop
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - FetLife