zillabyte-cli 0.0.9

Sign up to get free protection for your applications and to get access to all the features.
Files changed (53) hide show
  1. checksums.yaml +15 -0
  2. data/Gemfile +4 -0
  3. data/LICENSE +20 -0
  4. data/README.md +29 -0
  5. data/bin/zillabyte +18 -0
  6. data/lib/zillabyte/api/base.rb +11 -0
  7. data/lib/zillabyte/api/data.rb +126 -0
  8. data/lib/zillabyte/api/flows.rb +239 -0
  9. data/lib/zillabyte/api/locks.rb +4 -0
  10. data/lib/zillabyte/api/logs.rb +32 -0
  11. data/lib/zillabyte/api/metrics.rb +48 -0
  12. data/lib/zillabyte/api/queries.rb +58 -0
  13. data/lib/zillabyte/api/semantic_tags.rb +24 -0
  14. data/lib/zillabyte/api/settings.rb +8 -0
  15. data/lib/zillabyte/api/sources.rb +28 -0
  16. data/lib/zillabyte/api/zillalogs.rb +66 -0
  17. data/lib/zillabyte/api.rb +170 -0
  18. data/lib/zillabyte/auth.rb +155 -0
  19. data/lib/zillabyte/cli/auth.rb +33 -0
  20. data/lib/zillabyte/cli/base.rb +161 -0
  21. data/lib/zillabyte/cli/config.rb +63 -0
  22. data/lib/zillabyte/cli/counters.rb +61 -0
  23. data/lib/zillabyte/cli/flows.rb +702 -0
  24. data/lib/zillabyte/cli/help.rb +137 -0
  25. data/lib/zillabyte/cli/helpers/data_schema_builder.rb +3 -0
  26. data/lib/zillabyte/cli/host.rb +21 -0
  27. data/lib/zillabyte/cli/logs.rb +118 -0
  28. data/lib/zillabyte/cli/query.rb +172 -0
  29. data/lib/zillabyte/cli/relations.rb +326 -0
  30. data/lib/zillabyte/cli/sources.rb +37 -0
  31. data/lib/zillabyte/cli/templates/js/simple_function.js +33 -0
  32. data/lib/zillabyte/cli/templates/js/zillabyte.conf.yaml +2 -0
  33. data/lib/zillabyte/cli/templates/python/requirements.txt +7 -0
  34. data/lib/zillabyte/cli/templates/python/simple_function.py +27 -0
  35. data/lib/zillabyte/cli/templates/python/zillabyte.conf.yaml +4 -0
  36. data/lib/zillabyte/cli/templates/ruby/Gemfile +3 -0
  37. data/lib/zillabyte/cli/templates/ruby/simple_function.rb +36 -0
  38. data/lib/zillabyte/cli/templates/ruby/zillabyte.conf.yaml +2 -0
  39. data/lib/zillabyte/cli/version.rb +11 -0
  40. data/lib/zillabyte/cli/zillalogs.rb +86 -0
  41. data/lib/zillabyte/cli.rb +37 -0
  42. data/lib/zillabyte/command.rb +254 -0
  43. data/lib/zillabyte/common/progress.rb +17 -0
  44. data/lib/zillabyte/common/tar.rb +102 -0
  45. data/lib/zillabyte/common.rb +13 -0
  46. data/lib/zillabyte/helpers.rb +49 -0
  47. data/lib/zillabyte/queries.rb +39 -0
  48. data/lib/zillabyte-cli/version.rb +5 -0
  49. data/lib/zillabyte-cli.rb +5 -0
  50. data/zillabyte-cli.gemspec +42 -0
  51. data/zillabyte_emails.csv +1 -0
  52. data/zillaconf.json +3 -0
  53. metadata +278 -0
@@ -0,0 +1,137 @@
1
+ require "zillabyte/cli/base"
2
+
3
+ # list commands and display help
4
+ #
5
+ class Zillabyte::Command::Help < Zillabyte::Command::Base
6
+
7
+ PRIMARY_NAMESPACES = %w( relations query flows logs )
8
+
9
+
10
+ def index(*direct_args)
11
+ if command = args.shift || direct_args.shift
12
+ help_for_command(command)
13
+ else
14
+ help_for_root
15
+ end
16
+ end
17
+
18
+ alias_command "-h", "help"
19
+ alias_command "--help", "help"
20
+
21
+ private
22
+
23
+ def commands_for_namespace(name)
24
+ Zillabyte::Command.commands.values.select do |command|
25
+ command[:namespace] == name && command[:command] != name
26
+ end
27
+ end
28
+
29
+ def namespaces
30
+ namespaces = Zillabyte::Command.namespaces
31
+ namespaces
32
+ end
33
+
34
+ def commands
35
+ Zillabyte::Command.commands
36
+ end
37
+
38
+ def legacy_help_for_command(command)
39
+ Zillabyte::Command::Help.groups.each do |group|
40
+ group.each do |cmd, description|
41
+ return description if cmd.split(" ").first == command
42
+ end
43
+ end
44
+ nil
45
+ end
46
+
47
+ def skip_namespace?(ns)
48
+ return true if ns[:description] =~ /DEPRECATED:/
49
+ return true if ns[:description] =~ /HIDDEN:/
50
+ false
51
+ end
52
+
53
+ def skip_command?(command)
54
+ return true if command[:help] =~ /DEPRECATED:/
55
+ return true if command[:help] =~ /^ HIDDEN:/
56
+ false
57
+ end
58
+
59
+ def primary_namespaces
60
+ PRIMARY_NAMESPACES.map { |name| namespaces[name] }.compact
61
+ end
62
+
63
+ def additional_namespaces
64
+ (namespaces.values - primary_namespaces)
65
+ end
66
+
67
+ def summary_for_namespaces(namespaces)
68
+ size = longest(namespaces.map { |n| n[:name] })
69
+ namespaces.sort_by {|namespace| namespace[:name]}.each do |namespace|
70
+ next if skip_namespace?(namespace)
71
+ name = namespace[:name]
72
+ puts " %-#{size}s # %s" % [ name, namespace[:description] ]
73
+ end
74
+ end
75
+
76
+ def help_for_root
77
+ puts "Usage: zillabyte COMMAND [command-specific-options]"
78
+ puts
79
+ puts "Primary help topics, type \"zillabyte help TOPIC\" for more details:"
80
+ puts
81
+ summary_for_namespaces(primary_namespaces)
82
+ puts
83
+ puts "Additional topics:"
84
+ puts
85
+ summary_for_namespaces(additional_namespaces)
86
+ puts
87
+ puts "For help getting started, visit http://www.developers.zillabyte.com."
88
+ puts
89
+ end
90
+
91
+ def help_for_namespace(name)
92
+ namespace_commands = commands_for_namespace(name)
93
+
94
+ unless namespace_commands.empty?
95
+ size = longest(namespace_commands.map { |c| c[:banner] })
96
+ namespace_commands.sort_by { |c| c[:banner].to_s }.each do |command|
97
+ next if skip_command?(command)
98
+ command[:summary] ||= legacy_help_for_command(command[:command])
99
+ puts " %-#{size}s # %s" % [ command[:banner], command[:summary] ]
100
+ end
101
+ end
102
+ end
103
+
104
+ def help_for_command(name)
105
+ if command_alias = Zillabyte::Command.command_aliases[name]
106
+ display("Alias: #{name} redirects to #{command_alias}")
107
+ name = command_alias
108
+ end
109
+ if command = commands[name]
110
+ puts "Usage: zillabyte #{command[:banner]}"
111
+
112
+ if command[:help].strip.length > 0
113
+ help = command[:help].split("\n").reject do |line|
114
+ line =~ /HIDDEN/
115
+ end
116
+ puts help[1..-1].join("\n")
117
+ else
118
+ puts
119
+ puts " " + legacy_help_for_command(name).to_s
120
+ end
121
+ puts
122
+ end
123
+
124
+ namespace_commands = commands_for_namespace(name).reject do |command|
125
+ command[:help] =~ /DEPRECATED/
126
+ end
127
+
128
+ if !namespace_commands.empty?
129
+ puts "Additional commands, type \"zillabyte help COMMAND\" for more details:"
130
+ puts
131
+ help_for_namespace(name)
132
+ puts
133
+ elsif command.nil?
134
+ error "#{name} is not a zillabyte command. See `zillabyte help`."
135
+ end
136
+ end
137
+ end
@@ -0,0 +1,3 @@
1
+ class Zillabyte::Helpers::DataSchemaBuilder
2
+
3
+ end
@@ -0,0 +1,21 @@
1
+ # require "zillabyte/cli/base"
2
+ #
3
+ # # manage the host that zillabyte connects
4
+ # #
5
+ # class Zillabyte::Command::Host < Zillabyte::Command::Base
6
+ #
7
+ # # host
8
+ # #
9
+ # #
10
+ # def index
11
+ # self.list
12
+ # end
13
+ #
14
+ # # host:list
15
+ # #
16
+ # # list the currently connected host
17
+ # #
18
+ # def list
19
+ # puts ENV["ZILLABYTE_API_HOST"] || "api.zillabyte.com"
20
+ # end
21
+ # end
@@ -0,0 +1,118 @@
1
+ require "zillabyte/cli/base"
2
+ require "pty"
3
+ require 'colorize'
4
+
5
+ # manage custom logs
6
+ #
7
+ class Zillabyte::Command::Logs < Zillabyte::Command::Base
8
+
9
+
10
+
11
+
12
+
13
+ # logs:show FLOW_ID [OPERATION]
14
+ #
15
+ # shows the logs
16
+ #
17
+ # -t, --tail # continuously watches for new results
18
+ # -v, --verbose LEVEL # sets the verbosity (error, info, debug) (default: info)
19
+ #
20
+ def show
21
+
22
+ flow_id = options[:flow] || shift_argument
23
+ operation_id = options[:operation] || shift_argument || '_ALL_'
24
+ tail = options[:tail]
25
+ priority = options[:verbose] || 'debug'
26
+ carry_settings = {
27
+ :priority => priority
28
+ }
29
+ api_options = {}
30
+
31
+ error "no id given" if flow_id.nil?
32
+
33
+ begin
34
+
35
+ res = self.api.logs.get(flow_id, operation_id, api_options)
36
+
37
+ carry_settings = show_log_output(res, carry_settings)
38
+ api_options[:since] = carry_settings[:since]
39
+
40
+ if (tail)
41
+ sleep(5) # HACK
42
+ end
43
+ end while(tail)
44
+
45
+ end
46
+ alias_command "log", "logs:show"
47
+ alias_command "logs", "logs:show"
48
+
49
+
50
+
51
+
52
+
53
+
54
+
55
+ private
56
+
57
+ def show_log_output(lines, settings = {})
58
+
59
+ @colors ||= [:green, :yellow, :magenta, :cyan, :light_black, :light_green, :light_yellow, :light_blue, :light_magenta, :light_cyan]
60
+
61
+ max_category_size = 0
62
+ all_lines = []
63
+
64
+ lines.each_pair do |operation, lines|
65
+ settings[operation] ||= {}
66
+ settings[operation][:color] ||= @colors.shift
67
+ lines.each do |line_h|
68
+
69
+ line = line_h['line']
70
+ priority = line_h['priority']
71
+ date = line_h['date']
72
+
73
+ all_lines << {
74
+ :line => line,
75
+ :category => operation,
76
+ :priority => priority,
77
+ :color => settings[operation][:color],
78
+ :date => date
79
+ }
80
+ max_category_size = [max_category_size, operation.size].max
81
+
82
+ if settings[:since]
83
+ settings[:since] = [date, settings[:since]].max
84
+ else
85
+ settings[:since] = date
86
+ end
87
+
88
+ end
89
+
90
+ end
91
+
92
+ all_lines.sort! do |a,b|
93
+ a[:date] <=> b[:date]
94
+ end
95
+
96
+ requested_priority = settings[:priority]
97
+
98
+ all_lines.each do |h|
99
+ color = h[:color]
100
+
101
+ case h[:priority]
102
+ when 'error'
103
+ color = :red if h[:priority] == 'error'
104
+ when 'info'
105
+ next if ['error'].member?(requested_priority)
106
+ when 'system'
107
+ when 'debug'
108
+ next if ['info', 'error'].member?(requested_priority)
109
+ end
110
+
111
+ display "#{h[:category].rjust(max_category_size)} #{h[:priority].rjust(6)} - #{h[:line]}".colorize(color)
112
+ end
113
+
114
+ settings
115
+ end
116
+
117
+
118
+ end
@@ -0,0 +1,172 @@
1
+ require "zillabyte/cli/base"
2
+
3
+ # executes queries
4
+ #
5
+ class Zillabyte::Command::Query < Zillabyte::Command::Base
6
+
7
+ # query:sxp EXPRESSION
8
+ #
9
+ # executes queries against the zillabyte corpus
10
+ #
11
+ # -o, --offset OFFSET # skips to the offset (default: 0)
12
+ # -l, --limit LIMIT # sets the result limit (default: 20)
13
+ # -t, --tail # continuously watches for new results
14
+ #
15
+ #Examples:
16
+ #
17
+ # $ zillabyte query:sxp "(uses company 'web_css')" --limit 100
18
+ #
19
+ def sxp
20
+
21
+ opts = {}
22
+ opts[:offset] = options[:offset] || 0
23
+ opts[:limit] = options[:limit] || 10
24
+ tail = options[:tail] || false
25
+ expression = options[:expression] || shift_argument
26
+ opts[:since] = options[:since]
27
+
28
+ if expression.nil?
29
+ error "no expression given"
30
+ end
31
+
32
+ seen = {}
33
+
34
+ begin
35
+
36
+ validate_arguments!
37
+ res = api.query.sxp(expression, opts)
38
+
39
+ filtered = []
40
+ headings = []
41
+ if res['rows'].first
42
+ headings = res['rows'].first.keys
43
+ rows = res['rows'].each do |obj|
44
+ new_row = headings.map do |heading|
45
+ obj[heading]
46
+ end
47
+ unless seen[new_row.to_s]
48
+ filtered << new_row
49
+ seen[new_row.to_s] = true
50
+ end
51
+ end
52
+ end
53
+
54
+ if filtered.size > 0
55
+
56
+ table = Terminal::Table.new :headings => headings, :rows => filtered
57
+ puts table.to_s
58
+ else
59
+ unless tail
60
+ display "no results"
61
+ end
62
+ end
63
+
64
+ opts[:since] = DateTime.now
65
+
66
+ end while (tail && sleep(5))
67
+
68
+ end
69
+
70
+ alias_command "sxp", "query:sxp"
71
+
72
+
73
+
74
+
75
+ # query:sql EXPRESSION
76
+ #
77
+ # executes queries against the zillabyte corpus
78
+ #
79
+ # -o, --offset OFFSET # skips to the offset (default: 0)
80
+ # -l, --limit LIMIT # sets the result limit (default: 20)
81
+ # -t, --tail # continuously watches for new results
82
+ # -s, --since SINCE # newer records since
83
+ # --no_truncation # doesn't truncate long strings
84
+ #
85
+ #Examples:
86
+ #
87
+ # $ zillabyte query:sql "select * from company" --limit 100
88
+ #
89
+ def sql
90
+
91
+ opts = {}
92
+ opts[:offset] = options[:offset] || 0
93
+ opts[:limit] = options[:limit] || 10
94
+ tail = options[:tail] || false
95
+ expression = options[:expression] || shift_argument
96
+ opts[:since] = options[:since]
97
+ seen = {}
98
+
99
+ if expression.nil?
100
+ error "no expression given"
101
+ end
102
+
103
+
104
+ begin
105
+
106
+ validate_arguments!
107
+ res = api.query.sql(expression, opts)
108
+
109
+ headings = []
110
+ filtered = []
111
+ if res['rows'].first
112
+ headings = res['rows'].first.keys
113
+ rows = res['rows'].each do |obj|
114
+
115
+ # if obj['since']
116
+ # opts[:since] = [obj['since'], opts[:since]].compact.max
117
+ # end
118
+
119
+ new_row = headings.map do |heading|
120
+ if options[:no_truncation]
121
+ obj[heading]
122
+ else
123
+ if obj[heading].to_s.size > 30
124
+ obj[heading].to_s[0..30] + "..."
125
+ else
126
+ obj[heading]
127
+ end
128
+ end
129
+ end
130
+
131
+ unless seen[new_row.to_s]
132
+ filtered << new_row
133
+ seen[new_row.to_s] = true
134
+ end
135
+ end
136
+ end
137
+
138
+
139
+ if filtered.size > 0
140
+
141
+ table = Terminal::Table.new :headings => headings, :rows => filtered
142
+ puts table.to_s
143
+ opts[:since] = Time.now.utc
144
+
145
+ else
146
+ unless tail
147
+ display "no results"
148
+ end
149
+ end
150
+
151
+
152
+ end while (tail && sleep(5))
153
+
154
+ end
155
+
156
+ alias_command "sql", "query:sql"
157
+
158
+
159
+
160
+
161
+ # rules:init
162
+ #
163
+ # initializes an empty rule
164
+ #
165
+ def init
166
+ display "TODO: init new rule"
167
+ end
168
+
169
+
170
+
171
+
172
+ end