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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 6822ae7470f8d854e23be149d385edff69982f52
4
- data.tar.gz: f9e5d1b59d98afcb59c092975b8425951001c0ee
3
+ metadata.gz: 03189f4a29db6e906722930292cd0a8c04a0f427
4
+ data.tar.gz: d04ed9c6aed9d01a96952406d351284a76f92628
5
5
  SHA512:
6
- metadata.gz: 4a0831855a1eb4cf2b6838e588a515885309d303cf9bb254ebf35abdcaca15ab7ca159ff15188cc7cce825e3e8f4be0b38c79087de44ffead7f7bd41d2456944
7
- data.tar.gz: 9b8adb3ab02f677517c895ce2798e190f138f86108de78f8b3b5977264e331ee3a5d3a76d4d8b5b2873cfcad51291645ff08f2c75223b7a0cbd4c70861917c82
6
+ metadata.gz: 6072a300a3dead9f8c23f3a9ca6f42476ffedad62957d5c9fd29f6f3993b3136e0a60f599c4b7fe76daf2040db7522f1318ab985a87581613c17bda914eff299
7
+ data.tar.gz: 673aa8ed35d8ef3912ef4ef1b316c92ffe425cf956a25e083affdc8dc1fffa979e3141bf589c789107644a1be7ff360860bb8348d477372cdd14ff8c3d0d3edc
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- magellan-cli (0.5.4)
4
+ magellan-cli (0.5.5)
5
5
  activesupport (~> 4.1.4)
6
6
  groovenauts-thor
7
7
  httpclient (~> 2.5)
@@ -47,6 +47,12 @@ module Magellan
47
47
  log_verbose(caller.join("\n "))
48
48
  raise Cli::Error, msg
49
49
  end
50
+
51
+ def show_error_and_exit1(e)
52
+ log_error "[#{e.class}] #{e.message}"
53
+ log_verbose(" " << e.backtrace.join("\n "))
54
+ exit(1)
55
+ end
50
56
  end
51
57
 
52
58
  class << self
@@ -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
@@ -1,5 +1,5 @@
1
1
  module Magellan
2
2
  module Cli
3
- VERSION = "0.5.4"
3
+ VERSION = "0.5.5"
4
4
  end
5
5
  end
@@ -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
- it "with nil" do
29
- expect(core).to receive(:get_message).with(nil)
30
- cmd.get(nil)
31
- end
32
-
33
- it "with blank string" do
34
- expect(core).to receive(:get_message).with("")
35
- cmd.get("")
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 "with topic" do
39
- expect(core).to receive(:get_message).with("foo.bar")
40
- cmd.get("foo.bar")
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
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: magellan-cli
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.4
4
+ version: 0.5.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - akm2000