cmds 0.1.1 → 0.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 3f2767abdf674497cad3cfc8913da88fddcf6cbc
4
- data.tar.gz: cd2458c8f02672b9e66d060557e7b996cfc1c8dc
3
+ metadata.gz: d08e416bc459776d37657d008c179166f451c196
4
+ data.tar.gz: 4e74d4eef712368c163114a5f10871820dff7125
5
5
  SHA512:
6
- metadata.gz: 52d88272291712ae57550d0822ae406d9723433866116a2f2802ac65c34423366eef8d1aeb6cb5e6aa778d46abaac3ed830fb96e1060e023f475b9bb4ac86727
7
- data.tar.gz: c1125b57ebc1036bec4480bf7b3db332ed75305b65c73933e738a400e85892a0b9dafbb4fe49790042d053f14f4b2ab541e48ec631f80952afca81a744b1ba9e
6
+ metadata.gz: 347c9989f03c843dec1db86153e2850be3c404879dd08cd68eca284433773609d24442cb0001939f49fdc6bdac2bee531cddb31bee4cdbdb307b0f728cab6f10
7
+ data.tar.gz: 5e235a6b41d0956cfd3bed4c56425a70a65abbe1163ffff02d14b922c234c25100a37100977b2567d1a1e797ac5a1fde32c368a32ce8a5206dee343ce8980c81
data/lib/cmds/cmd.rb CHANGED
@@ -1,3 +1,7 @@
1
+ # deps
2
+ require 'nrser'
3
+
4
+ # project
1
5
  require 'cmds/debug'
2
6
  require 'cmds/util'
3
7
  require 'cmds/spawn'
@@ -109,6 +113,7 @@ module Cmds
109
113
  @assert = opts[:assert] || false
110
114
  @env = opts[:env] || {}
111
115
  @format = opts[:format] || :squish
116
+ @env_mode = opts[:env_mode] || :inline
112
117
  end # #initialize
113
118
 
114
119
 
@@ -141,8 +146,17 @@ module Cmds
141
146
  def render *args, **kwds
142
147
  context = Cmds::ERBContext.new((@args + args), @kwds.merge(kwds))
143
148
  erb = Cmds::ShellEruby.new Cmds.replace_shortcuts(@template)
144
-
145
- erb.result(context.get_binding)
149
+ rendered = NRSER.dedent erb.result(context.get_binding)
150
+
151
+ if @env_mode == :inline && !@env.empty?
152
+ rendered = @env.sort_by {|name, value|
153
+ name
154
+ }.map {|name, value|
155
+ "#{ name }=#{ Cmds.esc value }"
156
+ }.join("\n\n") + "\n\n" + rendered
157
+ end
158
+
159
+ rendered
146
160
  end
147
161
 
148
162
 
@@ -165,7 +179,11 @@ module Cmds
165
179
  kwds: kwds,
166
180
  io_block: io_block
167
181
 
168
- Cmds.spawn prepare(*args, **kwds), @input, @env, &io_block
182
+ Cmds.spawn prepare(*args, **kwds),
183
+ @input,
184
+ # include env if mode is spawn argument
185
+ (@env_mode == :spawn_arg ? @env : {}),
186
+ &io_block
169
187
  end # #stream
170
188
 
171
189
 
@@ -210,7 +228,13 @@ module Cmds
210
228
 
211
229
  Cmds.debug "calling Cmds.spawn..."
212
230
 
213
- status = Cmds.spawn cmd, nil, @env do |io|
231
+ status = Cmds.spawn(
232
+ cmd,
233
+ # we deal with input in the block
234
+ nil,
235
+ # include env if mode is spawn argument
236
+ (@env_mode == :spawn_arg ? @env : {}),
237
+ ) do |io|
214
238
  # send the input to stream, which sends it to spawn
215
239
  io.in = input
216
240
 
data/lib/cmds/util.rb CHANGED
@@ -44,11 +44,17 @@ module Cmds
44
44
  end
45
45
 
46
46
  def self.pretty_format string
47
+ string = string.gsub(/\n(\s*\n)+\n/, "\n\n")
48
+
47
49
  string.lines.map {|line|
48
50
  line = line.rstrip
49
51
 
50
52
  if line.end_with? '\\'
51
53
  line
54
+ elsif line == ''
55
+ '\\'
56
+ elsif line =~ /\s$/
57
+ line + '\\'
52
58
  else
53
59
  line + ' \\'
54
60
  end
data/lib/cmds/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Cmds
2
- VERSION = "0.1.1"
2
+ VERSION = "0.1.2"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cmds
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - nrser
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-04-03 00:00:00.000000000 Z
11
+ date: 2017-04-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: nrser