apt-spy2 0.3.0 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- apt-spy2 (0.3.0)
4
+ apt-spy2 (0.4.0)
5
5
  colored (>= 1.2)
6
6
  json
7
7
  thor (>= 0.18.1)
@@ -1,5 +1,11 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
3
  require 'apt/spy2'
4
+ require 'colored'
4
5
 
5
- AptSpy2.start
6
+ begin
7
+ AptSpy2.start
8
+ rescue => the_error
9
+ puts the_error.to_s.white_on_red
10
+ exit 1
11
+ end
@@ -3,6 +3,7 @@ require 'open-uri'
3
3
  require 'colored'
4
4
  require 'fileutils'
5
5
  require 'apt/spy2/writer'
6
+ require 'json'
6
7
 
7
8
  class AptSpy2 < Thor
8
9
  package_name "apt-spy2"
@@ -38,9 +39,16 @@ class AptSpy2 < Thor
38
39
 
39
40
  desc "list", "List the currently available mirrors"
40
41
  option :country, :default => "mirrors"
42
+ option :format, :default => "shell"
41
43
  def list
44
+
42
45
  mirrors = retrieve(options[:country])
43
- puts mirrors
46
+ @writer = Apt::Spy2::Writer.new(options[:format])
47
+
48
+ @writer.set_complete(mirrors)
49
+
50
+ puts @writer.to_json if @writer.json?
51
+ puts mirrors if !@writer.json?
44
52
  end
45
53
 
46
54
  private
@@ -53,11 +61,9 @@ class AptSpy2 < Thor
53
61
  rescue OpenURI::HTTPError => the_error
54
62
  case the_error.io.status[0]
55
63
  when "404"
56
- puts "The country code '#{country}' is incorrect.".red
57
- exit 1
64
+ raise "The country code '#{country}' is incorrect."
58
65
  else
59
- puts "Status: #{the_error.io.status[0]}".red
60
- exit 1
66
+ raise "Status: #{the_error.io.status[0]}"
61
67
  end
62
68
  end
63
69
 
@@ -109,9 +115,9 @@ class AptSpy2 < Thor
109
115
  f.write(sources)
110
116
  end
111
117
  rescue
112
- puts "Failed updating #{apt_sources}!".red_on_white
113
- puts "You probably need sudo!".red
114
- exit 1
118
+ msg = "Failed updating #{apt_sources}!"
119
+ msg << "You probably need sudo!"
120
+ raise msg
115
121
  end
116
122
 
117
123
  puts "Updated '#{apt_sources}' with #{mirror}".green
@@ -1,5 +1,5 @@
1
1
  module Apt
2
2
  module Spy2
3
- VERSION = "0.3.0"
3
+ VERSION = "0.4.0"
4
4
  end
5
5
  end
@@ -14,6 +14,10 @@ module Apt
14
14
  @complete = []
15
15
  end
16
16
 
17
+ def set_complete(complete)
18
+ @complete = complete
19
+ end
20
+
17
21
  def echo(data)
18
22
  if @format == 'json'
19
23
  @complete.push(data)
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: apt-spy2
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.4.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors: