-
Notifications
You must be signed in to change notification settings - Fork 0
/
sdns.cr
72 lines (62 loc) · 1.52 KB
/
sdns.cr
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
require "commander"
require "config_file"
require "dns_list"
require "terminal_table"
require "version"
config_file = Sdns::ConfigFile.new
config_file.write
dns_list = Sdns::DnsList.new
cli = Commander::Command.new do |cmd|
cmd.use = "sdns"
cmd.long = "Utility for switching DNS server sets from the command line."
cmd.commands.add do |cmd|
cmd.use = "current"
cmd.short = "Displays the current DNS settings."
cmd.long = cmd.short
cmd.run do |opts, args|
dns_list.current
end
end
cmd.commands.add do |cmd|
cmd.use = "default"
cmd.short = "Reset to the default DNS servers."
cmd.long = cmd.short
cmd.run do |opts, args|
dns_list.default
end
end
cmd.commands.add do |cmd|
cmd.use = "flush"
cmd.short = "Flush the DNS cache."
cmd.long = cmd.short
cmd.run do |opts, args|
dns_list.flush
end
end
cmd.commands.add do |cmd|
cmd.use = "list"
cmd.short = "List the available DNS sets."
cmd.long = cmd.short
cmd.run do |opts, args|
dns_list.list
end
end
cmd.commands.add do |cmd|
cmd.use = "switch <id>"
cmd.short = "Switch to the specified DNS set."
cmd.long = cmd.short
cmd.run do |opts, args|
raise "Must provide a key value" if args.empty?
dns_list.switch(args[0])
end
end
cmd.commands.add do |cmd|
cmd.use = "--version"
cmd.short = "Displays the version."
cmd.long = cmd.short
cmd.run do |opts, args|
puts Sdns::VERSION
end
end
end
Commander.run(cli, ARGV)