td 0.9.5 → 0.9.6
Sign up to get free protection for your applications and to get access to all the features.
- data/ChangeLog +6 -0
- data/bin/td +4 -1
- data/lib/td/command/list.rb +13 -6
- data/lib/td/command/runner.rb +114 -0
- data/lib/td/version.rb +1 -1
- metadata +5 -5
- data/lib/td/command/td.rb +0 -94
data/ChangeLog
CHANGED
data/bin/td
CHANGED
data/lib/td/command/list.rb
CHANGED
@@ -40,12 +40,13 @@ module List
|
|
40
40
|
self.banner = banner
|
41
41
|
|
42
42
|
@message = nil
|
43
|
+
@argv = nil
|
43
44
|
end
|
44
45
|
|
45
|
-
attr_accessor :message
|
46
|
+
attr_accessor :message, :argv
|
46
47
|
|
47
48
|
def message
|
48
|
-
@message ||
|
49
|
+
@message || to_s
|
49
50
|
end
|
50
51
|
|
51
52
|
def banner
|
@@ -62,9 +63,9 @@ module List
|
|
62
63
|
"%-40s # %s" % [@usage_args, @description]
|
63
64
|
end
|
64
65
|
|
65
|
-
def cmd_parse(argv
|
66
|
+
def cmd_parse(argv=@argv||ARGV)
|
66
67
|
parse!(argv)
|
67
|
-
if argv.length < @req_args.length || (!@varlen && argv.length > @
|
68
|
+
if argv.length < @req_args.length || (!@varlen && argv.length > @argv.length)
|
68
69
|
cmd_usage nil
|
69
70
|
end
|
70
71
|
if argv.length <= 1
|
@@ -89,11 +90,17 @@ module List
|
|
89
90
|
name.split(':', 2).first
|
90
91
|
end
|
91
92
|
|
92
|
-
def on(*
|
93
|
+
def on(*argv)
|
93
94
|
@has_options = true
|
94
95
|
super
|
95
96
|
end
|
96
97
|
|
98
|
+
def with_args(argv)
|
99
|
+
d = dup
|
100
|
+
d.argv = argv
|
101
|
+
d
|
102
|
+
end
|
103
|
+
|
97
104
|
attr_reader :name
|
98
105
|
attr_reader :description
|
99
106
|
end
|
@@ -123,7 +130,7 @@ module List
|
|
123
130
|
require "td/command/#{group}"
|
124
131
|
cmd = name.gsub(':', '_')
|
125
132
|
m = Object.new.extend(Command).method(cmd)
|
126
|
-
return Proc.new { m.call(op) }
|
133
|
+
return Proc.new {|args| m.call(op.with_args(args)) }
|
127
134
|
end
|
128
135
|
nil
|
129
136
|
end
|
@@ -0,0 +1,114 @@
|
|
1
|
+
|
2
|
+
module TreasureData
|
3
|
+
module Command
|
4
|
+
|
5
|
+
|
6
|
+
class Runner
|
7
|
+
def initialize
|
8
|
+
@config_path = nil
|
9
|
+
@apikey = nil
|
10
|
+
@prog_name = nil
|
11
|
+
end
|
12
|
+
|
13
|
+
attr_accessor :apikey, :config_path, :prog_name
|
14
|
+
|
15
|
+
def run(argv=ARGV)
|
16
|
+
require 'td/version'
|
17
|
+
require 'optparse'
|
18
|
+
|
19
|
+
$prog = @prog_name || File.basename($0)
|
20
|
+
|
21
|
+
op = OptionParser.new
|
22
|
+
op.version = TreasureData::VERSION
|
23
|
+
op.banner = <<EOF
|
24
|
+
usage: #{$prog} [options] COMMAND [args]
|
25
|
+
|
26
|
+
options:
|
27
|
+
EOF
|
28
|
+
|
29
|
+
op.summary_indent = " "
|
30
|
+
|
31
|
+
(class<<self;self;end).module_eval do
|
32
|
+
define_method(:usage) do |errmsg|
|
33
|
+
require 'td/command/list'
|
34
|
+
puts op.to_s
|
35
|
+
puts ""
|
36
|
+
puts "commands:"
|
37
|
+
TreasureData::Command::List.show_help(op.summary_indent)
|
38
|
+
puts ""
|
39
|
+
puts "Type '#{$prog} help COMMAND' for more information on a specific command."
|
40
|
+
if errmsg
|
41
|
+
puts "error: #{errmsg}"
|
42
|
+
exit 1
|
43
|
+
else
|
44
|
+
exit 0
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
config_path = @config_path
|
50
|
+
apikey = @apikey
|
51
|
+
$verbose = false
|
52
|
+
#$debug = false
|
53
|
+
|
54
|
+
op.on('-c', '--config PATH', "path to config file (~/.td/td.conf)") {|s|
|
55
|
+
config_path = s
|
56
|
+
}
|
57
|
+
|
58
|
+
op.on('-k', '--apikey KEY', "use this API key instead of reading the config file") {|s|
|
59
|
+
apikey = s
|
60
|
+
}
|
61
|
+
|
62
|
+
op.on('-v', '--verbose', "verbose mode", TrueClass) {|b|
|
63
|
+
$verbose = b
|
64
|
+
}
|
65
|
+
|
66
|
+
#op.on('-d', '--debug', "debug mode", TrueClass) {|b|
|
67
|
+
# $debug = b
|
68
|
+
#}
|
69
|
+
|
70
|
+
begin
|
71
|
+
op.order!(argv)
|
72
|
+
usage nil if argv.empty?
|
73
|
+
cmd = argv.shift
|
74
|
+
|
75
|
+
require 'td/config'
|
76
|
+
if config_path
|
77
|
+
TreasureData::Config.path = config_path
|
78
|
+
end
|
79
|
+
if apikey
|
80
|
+
TreasureData::Config.apikey = apikey
|
81
|
+
end
|
82
|
+
rescue
|
83
|
+
usage $!.to_s
|
84
|
+
end
|
85
|
+
|
86
|
+
require 'td/command/list'
|
87
|
+
|
88
|
+
method = TreasureData::Command::List.get_method(cmd)
|
89
|
+
unless method
|
90
|
+
$stderr.puts "'#{cmd}' is not a td command. Run '#{$prog}' to show the list."
|
91
|
+
TreasureData::Command::List.show_guess(cmd)
|
92
|
+
exit 1
|
93
|
+
end
|
94
|
+
|
95
|
+
begin
|
96
|
+
method.call(argv)
|
97
|
+
rescue TreasureData::ConfigError
|
98
|
+
$stderr.puts "TreasureData account is not configured yet."
|
99
|
+
$stderr.puts "Run '#{$prog} account' first."
|
100
|
+
rescue
|
101
|
+
$stderr.puts "error #{$!.class}: backtrace:"
|
102
|
+
$!.backtrace.each {|b|
|
103
|
+
$stderr.puts " #{b}"
|
104
|
+
}
|
105
|
+
puts ""
|
106
|
+
puts $!
|
107
|
+
end
|
108
|
+
end
|
109
|
+
end
|
110
|
+
|
111
|
+
|
112
|
+
end
|
113
|
+
end
|
114
|
+
|
data/lib/td/version.rb
CHANGED
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: td
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 55
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 9
|
9
|
-
-
|
10
|
-
version: 0.9.
|
9
|
+
- 6
|
10
|
+
version: 0.9.6
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Sadayuki Furuhashi
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2011-09-
|
18
|
+
date: 2011-09-20 00:00:00 +09:00
|
19
19
|
default_executable: td
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|
@@ -118,11 +118,11 @@ files:
|
|
118
118
|
- lib/td/command/job.rb
|
119
119
|
- lib/td/command/list.rb
|
120
120
|
- lib/td/command/query.rb
|
121
|
+
- lib/td/command/runner.rb
|
121
122
|
- lib/td/command/sched.rb
|
122
123
|
- lib/td/command/schema.rb
|
123
124
|
- lib/td/command/server.rb
|
124
125
|
- lib/td/command/table.rb
|
125
|
-
- lib/td/command/td.rb
|
126
126
|
- lib/td/config.rb
|
127
127
|
- lib/td/version.rb
|
128
128
|
- ChangeLog
|
data/lib/td/command/td.rb
DELETED
@@ -1,94 +0,0 @@
|
|
1
|
-
|
2
|
-
require 'optparse'
|
3
|
-
require 'td/version'
|
4
|
-
|
5
|
-
$prog = File.basename($0)
|
6
|
-
|
7
|
-
op = OptionParser.new
|
8
|
-
op.version = TreasureData::VERSION
|
9
|
-
op.banner = <<EOF
|
10
|
-
usage: #{$prog} [options] COMMAND [args]
|
11
|
-
|
12
|
-
options:
|
13
|
-
EOF
|
14
|
-
|
15
|
-
op.summary_indent = " "
|
16
|
-
|
17
|
-
(class<<self;self;end).module_eval do
|
18
|
-
define_method(:usage) do |errmsg|
|
19
|
-
require 'td/command/list'
|
20
|
-
puts op.to_s
|
21
|
-
puts ""
|
22
|
-
puts "commands:"
|
23
|
-
TreasureData::Command::List.show_help(op.summary_indent)
|
24
|
-
puts ""
|
25
|
-
puts "Type 'td help COMMAND' for more information on a specific command."
|
26
|
-
if errmsg
|
27
|
-
puts "error: #{errmsg}"
|
28
|
-
exit 1
|
29
|
-
else
|
30
|
-
exit 0
|
31
|
-
end
|
32
|
-
end
|
33
|
-
end
|
34
|
-
|
35
|
-
config_path = nil
|
36
|
-
apikey = nil
|
37
|
-
$verbose = false
|
38
|
-
#$debug = false
|
39
|
-
|
40
|
-
op.on('-c', '--config PATH', "path to config file (~/.td/td.conf)") {|s|
|
41
|
-
config_path = s
|
42
|
-
}
|
43
|
-
|
44
|
-
op.on('-k', '--apikey KEY', "use this API key instead of reading the config file") {|s|
|
45
|
-
apikey = s
|
46
|
-
}
|
47
|
-
|
48
|
-
op.on('-v', '--verbose', "verbose mode", TrueClass) {|b|
|
49
|
-
$verbose = b
|
50
|
-
}
|
51
|
-
|
52
|
-
#op.on('-d', '--debug', "debug mode", TrueClass) {|b|
|
53
|
-
# $debug = b
|
54
|
-
#}
|
55
|
-
|
56
|
-
begin
|
57
|
-
op.order!(ARGV)
|
58
|
-
usage nil if ARGV.empty?
|
59
|
-
cmd = ARGV.shift
|
60
|
-
|
61
|
-
require 'td/config'
|
62
|
-
if config_path
|
63
|
-
TreasureData::Config.path = config_path
|
64
|
-
end
|
65
|
-
if apikey
|
66
|
-
TreasureData::Config.apikey = apikey
|
67
|
-
end
|
68
|
-
rescue
|
69
|
-
usage $!.to_s
|
70
|
-
end
|
71
|
-
|
72
|
-
require 'td/command/list'
|
73
|
-
|
74
|
-
method = TreasureData::Command::List.get_method(cmd)
|
75
|
-
unless method
|
76
|
-
$stderr.puts "'#{cmd}' is not a td command. Run '#{$prog}' to show the list."
|
77
|
-
TreasureData::Command::List.show_guess(cmd)
|
78
|
-
exit 1
|
79
|
-
end
|
80
|
-
|
81
|
-
begin
|
82
|
-
method.call
|
83
|
-
rescue TreasureData::ConfigError
|
84
|
-
$stderr.puts "TreasureData account is not configured yet."
|
85
|
-
$stderr.puts "Run '#{$prog} account' first."
|
86
|
-
rescue
|
87
|
-
$stderr.puts "error #{$!.class}: backtrace:"
|
88
|
-
$!.backtrace.each {|b|
|
89
|
-
$stderr.puts " #{b}"
|
90
|
-
}
|
91
|
-
puts ""
|
92
|
-
puts $!
|
93
|
-
end
|
94
|
-
|