kommando 0.0.9 → 0.0.10

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: 0d3521e56231b4dc2100fce519d440157005c3f7
4
- data.tar.gz: 382b63f80f81059847e56cb51a0fcc62366ee2f0
3
+ metadata.gz: da77c3f809cd0a9d9fdf6ae89c929d6e1ab457f9
4
+ data.tar.gz: 2e4815740c38be873a97f4f64d278489e18232f3
5
5
  SHA512:
6
- metadata.gz: 1c5673c728d2a97ac292e4a03918bf8d2a65eb0a4f6f47d1c53fdbf658775de5d5f41063d8cb595483961ed001d4c59bb769c0c6943f7c26196c6cd1fbc4e229
7
- data.tar.gz: 33b3dbbce80ba81ce23c1a4777b4233540582c06958347f1605ee1064a4585cfd76afcbcf97f09b8c94aad0276b8c515428658a26e21e52370589ab9b098fe5a
6
+ metadata.gz: d5ab9ed6a24dd357a3fd86e104723034da942147d7e203f44634fdab52736c2dd59d319cb3432a9742721b975ca79abbc6d1c4c840f86547d95e7021835ce433
7
+ data.tar.gz: 8e83c297b5706403481eebab8c02a30afff4e7bced1b506ce0733c68c6d4f167584da75ca1e34cb16882ea93940526d3203d2005c8f738645a62729b64057cbf
data/CHANGELOG.md CHANGED
@@ -1,5 +1,11 @@
1
1
  # CHANGELOG
2
2
 
3
+ ## 0.0.10
4
+ ENV variable interpolation.
5
+
6
+ - FEAT: Support for ENV variables like `Kommando.new "$ echo $HELLO", { env: { HELLO: "world" } }`
7
+ - EXAMPLES: `env` added.
8
+
3
9
  ## 0.0.9
4
10
  Support for shell (bash) commands.
5
11
 
data/examples/env.rb ADDED
@@ -0,0 +1,12 @@
1
+ require "./lib/kommando"
2
+
3
+ k = Kommando.new "$ echo $KOMMANDO_ENV1 $KOMMANDO_ENV2", {
4
+ env: {
5
+ KOMMANDO_ENV1: "hello",
6
+ KOMMANDO_ENV2: "world"
7
+ }
8
+ }
9
+ k.run
10
+
11
+ raise "err" unless k.out == "hello world"
12
+ puts k.out
@@ -1,3 +1,3 @@
1
1
  class Kommando
2
- VERSION = "0.0.9"
2
+ VERSION = "0.0.10"
3
3
  end
data/lib/kommando.rb CHANGED
@@ -24,6 +24,8 @@ class Kommando
24
24
  @timeout_happened = false
25
25
  @kill_happened = false
26
26
 
27
+ @env = opts[:env] || {}
28
+
27
29
  @code = nil
28
30
  @executed = false
29
31
 
@@ -52,16 +54,45 @@ class Kommando
52
54
 
53
55
  command, *args = if @cmd.start_with? "$"
54
56
  @shell = true
55
- trash, line = @cmd.split "$"
57
+ trash, line = @cmd.split "$", 2
56
58
  line.lstrip!
57
59
  ["bash", "-c", line]
58
60
  else
59
- #command, *args = @cmd.split " "
60
61
  @cmd.split " "
61
62
  end
62
63
 
64
+ @env.each_pair do |k,v|
65
+ ENV[k.to_s] = v
66
+ end
67
+
68
+ interpolated_args = []
69
+ if @shell
70
+ interpolated_args << args.shift
71
+ shell_line = args[0]
72
+
73
+ to_be_interpolated = shell_line.scan(/\$[^\s]*/)
74
+ to_be_interpolated.each do |to_interpolate|
75
+ if ENV[to_interpolate]
76
+ shell_line.gsub!("${to_interpolate}", ENV[to_interpolate])
77
+ else
78
+ shell_line.gsub!("${to_interpolate}", "")
79
+ end
80
+ end
81
+
82
+ interpolated_args << shell_line
83
+ else
84
+ args.each do |arg|
85
+ interpolated_args << if arg.start_with? "$"
86
+ env_name = arg.split("$")[1]
87
+ ENV[env_name]
88
+ else
89
+ arg
90
+ end
91
+ end
92
+ end
93
+
63
94
  begin
64
- PTY.spawn(command, *args) do |stdout, stdin, pid|
95
+ PTY.spawn(command, *interpolated_args) do |stdout, stdin, pid|
65
96
  if @retry && stdout.eof?
66
97
  @executed = false
67
98
  return run
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: kommando
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.9
4
+ version: 0.0.10
5
5
  platform: ruby
6
6
  authors:
7
7
  - Matti Paksula
@@ -105,6 +105,7 @@ files:
105
105
  - bin/stress
106
106
  - bin/version
107
107
  - examples/async.rb
108
+ - examples/env.rb
108
109
  - examples/exit.rb
109
110
  - examples/kill.rb
110
111
  - examples/live_output.rb