magellan-cli 0.5.4 → 0.5.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/lib/magellan/cli/base.rb +6 -0
- data/lib/magellan/cli/messaging/mqtt.rb +8 -1
- data/lib/magellan/cli/version.rb +1 -1
- data/spec/magellan/cli/messaging/mqtt_spec.rb +29 -13
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 03189f4a29db6e906722930292cd0a8c04a0f427
|
4
|
+
data.tar.gz: d04ed9c6aed9d01a96952406d351284a76f92628
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6072a300a3dead9f8c23f3a9ca6f42476ffedad62957d5c9fd29f6f3993b3136e0a60f599c4b7fe76daf2040db7522f1318ab985a87581613c17bda914eff299
|
7
|
+
data.tar.gz: 673aa8ed35d8ef3912ef4ef1b316c92ffe425cf956a25e083affdc8dc1fffa979e3141bf589c789107644a1be7ff360860bb8348d477372cdd14ff8c3d0d3edc
|
data/Gemfile.lock
CHANGED
data/lib/magellan/cli/base.rb
CHANGED
@@ -8,11 +8,18 @@ module Magellan
|
|
8
8
|
desc "pub TOPIC PAYLOAD", I18n.t(:pub, scope: [:messaging, :mqtt])
|
9
9
|
def pub(topic, payload)
|
10
10
|
core.publish(topic, try_reading_file(payload).dup)
|
11
|
+
log_success "\e[32mOK\e[0m"
|
12
|
+
rescue => e
|
13
|
+
show_error_and_exit1(e)
|
11
14
|
end
|
12
15
|
|
13
16
|
desc "get [TOPIC]", I18n.t(:get, scope: [:messaging, :mqtt])
|
14
17
|
def get(topic = nil)
|
15
|
-
core.get_message(topic)
|
18
|
+
topic, payload = *core.get_message(topic)
|
19
|
+
$stderr.puts topic
|
20
|
+
$stdout.puts payload.ascii_only? ? payload : payload.inspect
|
21
|
+
rescue => e
|
22
|
+
show_error_and_exit1(e)
|
16
23
|
end
|
17
24
|
|
18
25
|
end
|
data/lib/magellan/cli/version.rb
CHANGED
@@ -14,30 +14,46 @@ describe Magellan::Cli::Messaging::Mqtt do
|
|
14
14
|
|
15
15
|
describe :pub do
|
16
16
|
it do
|
17
|
-
expect(core).to receive(:publish).with("foo.bar", "payload")
|
17
|
+
expect(core).to receive(:publish).with("foo.bar", "payload").and_return(nil)
|
18
|
+
cmd.pub("foo.bar", "payload")
|
19
|
+
end
|
20
|
+
|
21
|
+
it "show error" do
|
22
|
+
msg = "Something wrong!"
|
23
|
+
expect(core).to receive(:publish).with("foo.bar", "payload").and_raise(msg)
|
24
|
+
expect(cmd).to receive(:exit).with(1)
|
25
|
+
expect($stderr).to receive(:puts).with("\e[31m[RuntimeError] #{msg}\e[0m")
|
18
26
|
cmd.pub("foo.bar", "payload")
|
19
27
|
end
|
20
28
|
end
|
21
29
|
|
22
30
|
describe :get do
|
23
31
|
it "without argument" do
|
24
|
-
expect(core).to receive(:get_message)
|
32
|
+
expect(core).to receive(:get_message).and_return(["topic", "payload"])
|
33
|
+
expect($stderr).to receive(:puts).with("topic")
|
34
|
+
expect($stdout).to receive(:puts).with("payload")
|
25
35
|
cmd.get
|
26
36
|
end
|
27
37
|
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
38
|
+
[
|
39
|
+
["with nil" , nil ],
|
40
|
+
["with blank string", "" ],
|
41
|
+
["with topic" , "topic"],
|
42
|
+
].each do |subject, arg|
|
43
|
+
it subject do
|
44
|
+
expect(core).to receive(:get_message).with(arg).and_return(["topic", "payload"])
|
45
|
+
expect($stderr).to receive(:puts).with("topic")
|
46
|
+
expect($stdout).to receive(:puts).with("payload")
|
47
|
+
cmd.get(arg)
|
48
|
+
end
|
36
49
|
end
|
37
50
|
|
38
|
-
it "
|
39
|
-
|
40
|
-
|
51
|
+
it "show error" do
|
52
|
+
msg = "Something wrong!"
|
53
|
+
expect(core).to receive(:get_message).with("topic").and_raise(msg)
|
54
|
+
expect(cmd).to receive(:exit).with(1)
|
55
|
+
expect($stderr).to receive(:puts).with("\e[31m[RuntimeError] #{msg}\e[0m")
|
56
|
+
cmd.get("topic")
|
41
57
|
end
|
42
58
|
end
|
43
59
|
end
|