jsonip 1.0.0 → 1.0.1

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: 2cc7ca00197e3a9528905c8c45fbe0e84ee2a312
4
- data.tar.gz: eb8e1ab7326aa593a57e3478980289e18d99029d
3
+ metadata.gz: 19daf7e7f93be6b4b9df32fb92c6059d7919b3cf
4
+ data.tar.gz: 1c8248df2f5e3979fe763629b30ee5fb8fd63290
5
5
  SHA512:
6
- metadata.gz: 05abbab5bddef78dff7ba92029ed340d1c5b89aad7ca602e78511dfe12b55b5faea768475054f4c41f616da51080e4f434a7f7f32b359c359bcf6d6487d3b6ce
7
- data.tar.gz: d99b143a548bf2c755e219879daab109447dca7010f7fb9ab7da782ac3797a62d573e371f075f8a0f262e89b21d6333ea27530fc7990f64c42908dbfb9c05faf
6
+ metadata.gz: c2f0a8cbbf8eb12869257a2c44d40b17b7d7806f4a1b95e7978b750d79a39a80830086265cce5136fa4303771b5c6070c60c37bc797c139b5fb150171f94cb62
7
+ data.tar.gz: 3ad5c12a70c14f6d57f105ae5e6f624de8ba8dc1b1ca68e5533ee18b024638512fd060e22e6eec46a9d3195d5ed1e42f81bc95a0f8c65722da1e3279a5581a75
data/lib/jsonip/cli.rb CHANGED
@@ -5,24 +5,49 @@ module Jsonip
5
5
  class CLI < Thor
6
6
  default_task :copy
7
7
 
8
+ class_option :quiet, type: :boolean, aliases: [ '-q', '-s', '--silent' ], desc: 'Prints minimal output. Useful for shell scripts and pipes'
9
+
10
+ desc "print", "Prints your IP, but dont copy"
11
+ def print
12
+ say print_message
13
+ end
14
+
8
15
  desc "copy", "Copy your IP to clipboard"
9
16
  def copy
10
- ip = Jsonip.get
11
- if ip.to_s.empty?
12
- say "Could not fetch your ip", :red
13
- else
14
- Clipboard.copy ip
15
- say pretty_banner(ip)
17
+ copy_to_clipboard
18
+ say copy_message unless options.quiet?
19
+ end
20
+
21
+ protected
22
+
23
+ def print_message
24
+ "".tap do |msg|
25
+ msg << yellow("Your IP is: ") unless options.quiet?
26
+ msg << formated_ip
16
27
  end
17
28
  end
18
29
 
19
- private
30
+ def copy_message
31
+ prefix = yellow("Your IP address")
32
+ sufix = yellow("was copied to clipboard")
33
+
34
+ [ prefix, formated_ip, sufix ].join(" ")
35
+ end
36
+
37
+ def yellow(text)
38
+ set_color(text, :yellow)
39
+ end
40
+
41
+ def copy_to_clipboard
42
+ Clipboard.copy json_ip
43
+ end
44
+
45
+ def formated_ip
46
+ options.quiet? ? json_ip : set_color(json_ip, :white, :bold)
47
+ end
20
48
 
21
- def pretty_banner(ip)
22
- prefix = set_color("Your IP address", :green)
23
- ip_text = set_color(ip, :red, :bold)
24
- sufix = set_color("was copied to clipboard", :green)
25
- [ prefix, ip_text, sufix ].join(" ")
49
+ def json_ip
50
+ @json_ip ||= Jsonip.get
26
51
  end
27
52
  end
28
53
  end
@@ -1,3 +1,3 @@
1
1
  module Jsonip
2
- VERSION = "1.0.0"
2
+ VERSION = "1.0.1"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jsonip
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jorge Calás Lozano