point-cli 0.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.
Potentially problematic release.
This version of point-cli might be problematic. Click here for more details.
- data/bin/point +3 -0
- data/lib/commands/domains.rb +41 -0
- data/lib/commands/setup.rb +30 -0
- data/lib/point_cli.rb +142 -0
- data/lib/point_cli/command.rb +59 -0
- metadata +98 -0
data/bin/point
ADDED
@@ -0,0 +1,41 @@
|
|
1
|
+
desc "Lists all domains on your account"
|
2
|
+
usage "point list [group]"
|
3
|
+
command "list" do |group|
|
4
|
+
use_hirb
|
5
|
+
domains = Point::Zone.find(:all)
|
6
|
+
table domains, :fields => [:id, :name, :ttl, :group, :updated_at], :headers => {:id => "ID", :name => "Name", :ttl => "TTL", :group => "Group", :updated_at => "Last updated"}
|
7
|
+
end
|
8
|
+
|
9
|
+
desc "Get information about the specified domain"
|
10
|
+
usage "point info [domain]"
|
11
|
+
command "info", :required_args => 1 do |domain|
|
12
|
+
zone = select_zone(domain)
|
13
|
+
|
14
|
+
divider
|
15
|
+
puts " Domain Name...: #{zone.name}"
|
16
|
+
puts " TTL...........: #{zone.ttl}"
|
17
|
+
puts " Group.........: #{zone.group.empty? ? 'none' : zone.group}"
|
18
|
+
if zone.additional_slaves
|
19
|
+
heading " Additional Slaves"
|
20
|
+
for slave in zone.additional_slaves.to_s.split("\n")
|
21
|
+
puts " * #{slave}"
|
22
|
+
end
|
23
|
+
end
|
24
|
+
heading " Dates"
|
25
|
+
|
26
|
+
puts " Created at....: #{zone.created_at}"
|
27
|
+
puts " Updated at....: #{zone.updated_at}"
|
28
|
+
puts " Last live at..: #{zone.last_updated_on_server_at}"
|
29
|
+
|
30
|
+
divider
|
31
|
+
puts "See 'cb records #{zone.name}' for a list of records on this domain."
|
32
|
+
end
|
33
|
+
|
34
|
+
desc "Return all records for this domain"
|
35
|
+
usage "point records [domain]"
|
36
|
+
command "records", :required_args => 1 do |domain|
|
37
|
+
zone = select_zone(domain)
|
38
|
+
puts "Showing records for #{zone.name}"
|
39
|
+
use_hirb
|
40
|
+
table zone.records, :fields => [:record_type, :name, :data, :aux], :headers => {:record_type => "Type", :name => "Name", :data => "Data", :aux => "Aux"}
|
41
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
desc "Setup the Point Gem for access"
|
2
|
+
usage "point setup"
|
3
|
+
command "setup" do
|
4
|
+
puts "\e[33;44mPointHQ CLI Setup Tool\e[0m"
|
5
|
+
puts "You can use this tool to automatically download and save your API key so you can easily use the"
|
6
|
+
puts "the command line interface."
|
7
|
+
|
8
|
+
unless `which curl`; $?.success?
|
9
|
+
puts "'curl' is not installed on this computer. You need to install curl to use this command line"
|
10
|
+
puts "setup tool"
|
11
|
+
Process.exit(1)
|
12
|
+
end
|
13
|
+
|
14
|
+
username = ask("E-Mail Address: ")
|
15
|
+
password = ask("Password: ") { |q| q.echo = ''}
|
16
|
+
|
17
|
+
puts "Attempting to get your API key from '#{Point.site}'..."
|
18
|
+
|
19
|
+
command = "curl -q -s -u \"#{username}:#{password}\" #{Point.site}/api_key"
|
20
|
+
if `#{command}` =~ /(\w{40})/
|
21
|
+
api_key = $1
|
22
|
+
else
|
23
|
+
puts "\e[31mAccess was denied or the server was unavailable. Please check your username & password is correct.\e[0m"
|
24
|
+
Process.exit(1)
|
25
|
+
end
|
26
|
+
|
27
|
+
config_json = {:username => username, :apitoken => api_key}.to_json
|
28
|
+
File.open($point_config_file, 'w') { |f| f.write(config_json)}
|
29
|
+
puts "\e[32mConfiguration was successfully saved to #{$point_config_file}\e[0m"
|
30
|
+
end
|
data/lib/point_cli.rb
ADDED
@@ -0,0 +1,142 @@
|
|
1
|
+
$:.unshift File.dirname(__FILE__)
|
2
|
+
|
3
|
+
require 'point'
|
4
|
+
require 'hirb'
|
5
|
+
|
6
|
+
require 'highline/import'
|
7
|
+
HighLine.track_eof = false
|
8
|
+
|
9
|
+
require 'point_cli/command'
|
10
|
+
|
11
|
+
trap("INT") { puts; exit }
|
12
|
+
|
13
|
+
## Load Configuration before we do anything else
|
14
|
+
$point_config_file = File.expand_path(File.join('~', '.point'))
|
15
|
+
if File.exist?($point_config_file)
|
16
|
+
config_hash = JSON.parse(File.read($point_config_file))
|
17
|
+
Point.username = config_hash['username']
|
18
|
+
Point.apitoken = config_hash['apitoken']
|
19
|
+
end
|
20
|
+
|
21
|
+
module PointCLI
|
22
|
+
|
23
|
+
VERSION = "0.0.1"
|
24
|
+
|
25
|
+
extend self
|
26
|
+
|
27
|
+
def run(command, args = [])
|
28
|
+
load_commands
|
29
|
+
command = 'help' if command.nil?
|
30
|
+
if @commands[command]
|
31
|
+
@options = parse_options(args)
|
32
|
+
if args.size < @commands[command][:required_args]
|
33
|
+
puts "usage: #{@commands[command][:usage]}"
|
34
|
+
else
|
35
|
+
@commands[command][:block].call(*args)
|
36
|
+
end
|
37
|
+
else
|
38
|
+
puts "Command not found. Check 'point help' for full information."
|
39
|
+
end
|
40
|
+
rescue Point::Errors::AccessDenied
|
41
|
+
puts "Access Denied. The username & API key stored for your account was invalid. Have you run 'point setup'?"
|
42
|
+
Process.exit(1)
|
43
|
+
rescue Point::Error
|
44
|
+
puts "An error occured with your point request."
|
45
|
+
Process.exit(1)
|
46
|
+
end
|
47
|
+
|
48
|
+
def command(command, options = {}, &block)
|
49
|
+
@commands = Hash.new if @commands.nil?
|
50
|
+
@commands[command] = Hash.new
|
51
|
+
@commands[command][:description] = @next_description
|
52
|
+
@commands[command][:usage] = @next_usage
|
53
|
+
@commands[command][:flags] = @next_flags
|
54
|
+
@commands[command][:required_args] = (options[:required_args] || 0)
|
55
|
+
@commands[command][:block] = Command.new(block)
|
56
|
+
@next_usage, @next_description, @next_flags = nil, nil, nil
|
57
|
+
end
|
58
|
+
|
59
|
+
def commands
|
60
|
+
@commands
|
61
|
+
end
|
62
|
+
|
63
|
+
def desc(value)
|
64
|
+
@next_description = value
|
65
|
+
end
|
66
|
+
|
67
|
+
def usage(value)
|
68
|
+
@next_usage = value
|
69
|
+
end
|
70
|
+
|
71
|
+
def flags(key, value)
|
72
|
+
@next_flags = Hash.new if @next_flags.nil?
|
73
|
+
@next_flags[key] = value
|
74
|
+
end
|
75
|
+
|
76
|
+
def load_commands
|
77
|
+
Dir[File.join(File.dirname(__FILE__), 'commands', '*.rb')].each do |path|
|
78
|
+
PointCLI.module_eval File.read(path), path
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
82
|
+
def parse_options(args)
|
83
|
+
idx = 0
|
84
|
+
args.clone.inject({}) do |memo, arg|
|
85
|
+
case arg
|
86
|
+
when /^--(.+?)=(.*)/
|
87
|
+
args.delete_at(idx)
|
88
|
+
memo.merge($1.to_sym => $2)
|
89
|
+
when /^--(.+)/
|
90
|
+
args.delete_at(idx)
|
91
|
+
memo.merge($1.to_sym => true)
|
92
|
+
when "--"
|
93
|
+
args.delete_at(idx)
|
94
|
+
return memo
|
95
|
+
else
|
96
|
+
idx += 1
|
97
|
+
memo
|
98
|
+
end
|
99
|
+
end
|
100
|
+
end
|
101
|
+
|
102
|
+
end
|
103
|
+
|
104
|
+
PointCLI.desc "Displays this help message"
|
105
|
+
PointCLI.usage "point usage [command]"
|
106
|
+
PointCLI.command "help" do |command|
|
107
|
+
if command.nil?
|
108
|
+
puts "The Point Gem allows you to easily control your DNS hosting from a simple to use"
|
109
|
+
puts "command line interface. "
|
110
|
+
puts
|
111
|
+
for key, command in PointCLI.commands.sort_by{|k,v| k}
|
112
|
+
puts " #{key.ljust(15)} #{command[:description]}"
|
113
|
+
end
|
114
|
+
puts
|
115
|
+
puts "For more information see http://www.pointhq.com/gem"
|
116
|
+
puts "See 'point help [command]' for usage information."
|
117
|
+
else
|
118
|
+
if c = PointCLI.commands[command]
|
119
|
+
puts c[:description]
|
120
|
+
if c[:usage]
|
121
|
+
puts
|
122
|
+
puts "Usage:"
|
123
|
+
puts " #{c[:usage]}"
|
124
|
+
end
|
125
|
+
if c[:flags]
|
126
|
+
puts
|
127
|
+
puts "Options:"
|
128
|
+
for key, value in c[:flags]
|
129
|
+
puts " #{key.ljust(15)} #{value}"
|
130
|
+
end
|
131
|
+
end
|
132
|
+
else
|
133
|
+
puts "Command Not Found. Check 'point help' for a full list of commands available to you."
|
134
|
+
end
|
135
|
+
end
|
136
|
+
end
|
137
|
+
|
138
|
+
PointCLI.desc "Displays the current version number"
|
139
|
+
PointCLI.command "version" do
|
140
|
+
puts "Point Library Version..: #{Point::VERSION}"
|
141
|
+
puts "Point CLI Version......: #{PointCLI::VERSION} "
|
142
|
+
end
|
@@ -0,0 +1,59 @@
|
|
1
|
+
module PointCLI
|
2
|
+
class Command
|
3
|
+
|
4
|
+
def initialize(block)
|
5
|
+
(class << self;self end).send :define_method, :command, &block
|
6
|
+
end
|
7
|
+
|
8
|
+
def call(*args)
|
9
|
+
arity = method(:command).arity
|
10
|
+
args << nil while args.size < arity
|
11
|
+
send :command, *args
|
12
|
+
end
|
13
|
+
|
14
|
+
def use_hirb
|
15
|
+
begin
|
16
|
+
require 'hirb'
|
17
|
+
extend Hirb::Console
|
18
|
+
rescue LoadError
|
19
|
+
puts "Hirb is not installed. Install hirb using '[sudo] gem install hirb' to get cool ASCII tables"
|
20
|
+
Process.exit(1)
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
def display_zone_information(zone)
|
25
|
+
puts "Zone #{zone.inspect}"
|
26
|
+
end
|
27
|
+
|
28
|
+
|
29
|
+
def select_zone(zone)
|
30
|
+
zones = Point::Zone.find(:all)
|
31
|
+
zones = zones.select{|z| z.name.match(/\A#{zone}/) }
|
32
|
+
if zones.size == 0
|
33
|
+
puts "There are no zones matching the domain you entered"
|
34
|
+
Process.exit(1)
|
35
|
+
elsif zones.size > 1
|
36
|
+
puts "There are multiple zones matching the domain you have posted. Which domain would"
|
37
|
+
puts "you like to view?"
|
38
|
+
zone_choice = choose do |menu|
|
39
|
+
for zone in zones
|
40
|
+
menu.choice(zone.name)
|
41
|
+
end
|
42
|
+
end
|
43
|
+
zones.select{|z| z.name == zone_choice}.first
|
44
|
+
else
|
45
|
+
zones.first
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
def heading(title)
|
50
|
+
puts "-" * 80
|
51
|
+
puts title
|
52
|
+
end
|
53
|
+
|
54
|
+
def divider
|
55
|
+
puts "=" * 80
|
56
|
+
end
|
57
|
+
|
58
|
+
end
|
59
|
+
end
|
metadata
ADDED
@@ -0,0 +1,98 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: point-cli
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Adam Cooke
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
|
12
|
+
date: 2009-10-29 00:00:00 +00:00
|
13
|
+
default_executable:
|
14
|
+
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
16
|
+
name: highline
|
17
|
+
type: :runtime
|
18
|
+
version_requirement:
|
19
|
+
version_requirements: !ruby/object:Gem::Requirement
|
20
|
+
requirements:
|
21
|
+
- - ">="
|
22
|
+
- !ruby/object:Gem::Version
|
23
|
+
version: 1.5.0
|
24
|
+
version:
|
25
|
+
- !ruby/object:Gem::Dependency
|
26
|
+
name: json
|
27
|
+
type: :runtime
|
28
|
+
version_requirement:
|
29
|
+
version_requirements: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 1.1.5
|
34
|
+
version:
|
35
|
+
- !ruby/object:Gem::Dependency
|
36
|
+
name: hirb
|
37
|
+
type: :runtime
|
38
|
+
version_requirement:
|
39
|
+
version_requirements: !ruby/object:Gem::Requirement
|
40
|
+
requirements:
|
41
|
+
- - ">="
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
version: 0.2.7
|
44
|
+
version:
|
45
|
+
- !ruby/object:Gem::Dependency
|
46
|
+
name: point
|
47
|
+
type: :runtime
|
48
|
+
version_requirement:
|
49
|
+
version_requirements: !ruby/object:Gem::Requirement
|
50
|
+
requirements:
|
51
|
+
- - ">="
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: 1.0.0
|
54
|
+
version:
|
55
|
+
description:
|
56
|
+
email: adam@atechmedia.com
|
57
|
+
executables:
|
58
|
+
- point
|
59
|
+
extensions: []
|
60
|
+
|
61
|
+
extra_rdoc_files: []
|
62
|
+
|
63
|
+
files:
|
64
|
+
- lib/commands/domains.rb
|
65
|
+
- lib/commands/setup.rb
|
66
|
+
- lib/point_cli/command.rb
|
67
|
+
- lib/point_cli.rb
|
68
|
+
- bin/point
|
69
|
+
has_rdoc: true
|
70
|
+
homepage: http://www.pointhq.com
|
71
|
+
licenses: []
|
72
|
+
|
73
|
+
post_install_message:
|
74
|
+
rdoc_options: []
|
75
|
+
|
76
|
+
require_paths:
|
77
|
+
- lib
|
78
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: "0"
|
83
|
+
version:
|
84
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
85
|
+
requirements:
|
86
|
+
- - ">="
|
87
|
+
- !ruby/object:Gem::Version
|
88
|
+
version: "0"
|
89
|
+
version:
|
90
|
+
requirements: []
|
91
|
+
|
92
|
+
rubyforge_project:
|
93
|
+
rubygems_version: 1.3.5
|
94
|
+
signing_key:
|
95
|
+
specification_version: 3
|
96
|
+
summary: CLI client for the PointHQ DNS Hosting System
|
97
|
+
test_files: []
|
98
|
+
|