hosts-cli 0.1.0 → 0.2.0

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: 85b4ffe43ac4d76a38fca773d29bf8c754c4ccc6
4
- data.tar.gz: 3164d63d30eebb53eaaafec6364dd854237c054e
3
+ metadata.gz: a23cbac5813587974e5df7986443ccada5ce1165
4
+ data.tar.gz: e6a2b11177e86671666dd0bc5904c872f54d9bce
5
5
  SHA512:
6
- metadata.gz: 80ba5915bcfd43f204627d14c04c541eca372544803018467a24bc051028509636bdaef2f24e713d53102a700ecdf34c1c3111db67b694a98fc81a10955b162e
7
- data.tar.gz: cdfb89302a6e8139e9eb767dffd117ccde75097d48c7339b7c67bcdabe584ceb46d7e320187ff5697e9275464fe602d45536a77ed494a01b4286b7b4b8802a57
6
+ metadata.gz: d49af2e3af20f56b39f91fdec1954c8c69cf6c7c196d6e5272cae4cd96194a1f80de4e2cf450223e82d21c516674a7b193c7754e96a49ecff00c48fe90673fe6
7
+ data.tar.gz: 7faf13aa6e8b50aa3252f5072c94b750c72b95de93dbddd8cd08ed6ea90f244249bbd8a4e93c510cb0c06b744909b3d9fb0e36d4618f492dcccb1e20f17f1f87
@@ -19,10 +19,14 @@ module Hosts::Lib::Commands
19
19
 
20
20
  hosts_file.add_entry(args[0], args[1])
21
21
 
22
- puts "Added entry: #{args[0]} => #{args[1]}"
23
22
 
24
23
  # Write changes to hosts file
25
- hosts_file.flush
24
+ begin
25
+ hosts_file.flush
26
+ puts "Added entry: #{args[0]} => #{args[1]}"
27
+ rescue Errno::EACCES
28
+ puts "Permission error: 'hosts add' requires 'sudo'"
29
+ end
26
30
  }
27
31
  @Add
28
32
  end
@@ -0,0 +1,16 @@
1
+ include Hosts::Lib::Core
2
+
3
+ module Hosts::Lib::Commands
4
+ options_obj = Slop::Options.new
5
+
6
+ Flush = SubCommand.new(
7
+ 'flush', # Name of the sub command
8
+ 'Flush the DNS cache',
9
+ options_obj,
10
+ false
11
+ ) { |options, args|
12
+ `dscacheutil -flushcache; sudo killall -HUP mDNSResponder &> /dev/null`
13
+ puts "Flushed DNS cache"
14
+ }
15
+ @Flush
16
+ end
@@ -25,7 +25,7 @@ module Hosts::Lib::Commands
25
25
 
26
26
  print "%-#{longest_dest_name}.#{longest_dest_name}s" % dest
27
27
  print " "
28
- puts "=> #{hostname_f}"
28
+ puts "<= #{hostname_f}"
29
29
  end
30
30
  }
31
31
  @List
@@ -28,7 +28,11 @@ module Hosts::Lib::Commands
28
28
  end
29
29
 
30
30
  # Write changes to hosts file
31
- hosts_file.flush()
31
+ begin
32
+ hosts_file.flush()
33
+ rescue Errno::EACCES
34
+ puts "Permission error: 'hosts rm' requires 'sudo'"
35
+ end
32
36
  }
33
37
  @Rm
34
38
  end
@@ -147,12 +147,12 @@ module Hosts::Lib::Core
147
147
  end
148
148
  end
149
149
 
150
+ File.open(@hosts_file_path, "w+").write(new_hosts_file_content)
151
+
150
152
  puts
151
153
  puts "new content of hosts file:"
152
154
  puts new_hosts_file_content
153
155
  puts
154
-
155
- File.open(@hosts_file_path, "w+").write(new_hosts_file_content)
156
156
  end
157
157
  end
158
158
 
@@ -13,6 +13,7 @@ end
13
13
 
14
14
  module Hosts::Lib::Commands
15
15
  autoload :Add, File.dirname(__FILE__) + "/Commands/Add.rb"
16
+ autoload :Flush, File.dirname(__FILE__) + "/Commands/Flush.rb"
16
17
  autoload :Rm, File.dirname(__FILE__) + "/Commands/Rm.rb"
17
18
  autoload :List, File.dirname(__FILE__) + "/Commands/List.rb"
18
19
  autoload :Version, File.dirname(__FILE__) + "/Commands/Version.rb"
data/lib/hosts.rb CHANGED
@@ -1,11 +1,12 @@
1
1
  require_relative 'Hosts/Lib/autoload.rb'
2
2
 
3
3
  module Hosts
4
- VERSION = "0.1.0"
4
+ VERSION = "0.2.0"
5
5
 
6
6
  def self.main
7
7
  @sub_commands = {}
8
8
  @sub_commands['add'] = Hosts::Lib::Commands::Add
9
+ @sub_commands['flush'] = Hosts::Lib::Commands::Flush
9
10
  @sub_commands['help'] = Hosts::Lib::Commands::Help
10
11
  @sub_commands['list'] = Hosts::Lib::Commands::List
11
12
  @sub_commands['rm'] = Hosts::Lib::Commands::Rm
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hosts-cli
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sigurd Berg Svela
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-05-20 00:00:00.000000000 Z
11
+ date: 2015-05-22 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: An easy CLI to edit the hosts file on unix systems
14
14
  email: sigurdbergsvela@gmail.com
@@ -18,6 +18,7 @@ extensions: []
18
18
  extra_rdoc_files: []
19
19
  files:
20
20
  - lib/Hosts/Lib/Commands/Add.rb
21
+ - lib/Hosts/Lib/Commands/Flush.rb
21
22
  - lib/Hosts/Lib/Commands/Help.rb
22
23
  - lib/Hosts/Lib/Commands/List.rb
23
24
  - lib/Hosts/Lib/Commands/Rm.rb