zillabyte-cli 0.1.4 → 0.1.5

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.
Files changed (43) hide show
  1. checksums.yaml +8 -8
  2. data/bin/zb +1 -15
  3. data/bin/zillabyte +1 -15
  4. data/lib/zillabyte-cli.rb +0 -3
  5. data/lib/zillabyte-cli/version.rb +1 -1
  6. data/lib/zillabyte/api.rb +14 -34
  7. data/lib/zillabyte/api/apps.rb +3 -4
  8. data/lib/zillabyte/api/base.rb +2 -2
  9. data/lib/zillabyte/api/components.rb +1 -3
  10. data/lib/zillabyte/api/data.rb +2 -1
  11. data/lib/zillabyte/api/flows.rb +9 -4
  12. data/lib/zillabyte/api/keys.rb +2 -1
  13. data/lib/zillabyte/api/logs.rb +1 -2
  14. data/lib/zillabyte/api/metrics.rb +3 -2
  15. data/lib/zillabyte/api/queries.rb +2 -0
  16. data/lib/zillabyte/api/semantic_tags.rb +1 -0
  17. data/lib/zillabyte/api/sources.rb +2 -0
  18. data/lib/zillabyte/api/zillalogs.rb +1 -0
  19. data/lib/zillabyte/auth.rb +8 -12
  20. data/lib/zillabyte/cli.rb +7 -24
  21. data/lib/zillabyte/cli/apps.rb +7 -12
  22. data/lib/zillabyte/cli/base.rb +3 -3
  23. data/lib/zillabyte/cli/components.rb +6 -3
  24. data/lib/zillabyte/cli/config.rb +3 -3
  25. data/lib/zillabyte/cli/data.rb +6 -8
  26. data/lib/zillabyte/cli/flows.rb +17 -16
  27. data/lib/zillabyte/cli/help.rb +5 -2
  28. data/lib/zillabyte/cli/helpers/table_output_builder.rb +3 -3
  29. data/lib/zillabyte/cli/keys.rb +0 -5
  30. data/lib/zillabyte/cli/log_formatter.rb +2 -0
  31. data/lib/zillabyte/cli/nuke.rb +0 -3
  32. data/lib/zillabyte/cli/query.rb +1 -1
  33. data/lib/zillabyte/cli/repl.rb +4 -2
  34. data/lib/zillabyte/command.rb +29 -12
  35. data/lib/zillabyte/common/tar.rb +8 -7
  36. data/lib/zillabyte/helpers.rb +4 -2
  37. data/lib/zillabyte/runner/app_runner.rb +4 -4
  38. data/lib/zillabyte/runner/component_operation.rb +2 -5
  39. data/lib/zillabyte/runner/component_runner.rb +3 -3
  40. data/lib/zillabyte/runner/multilang_operation.rb +8 -6
  41. data/zillabyte-cli.gemspec +3 -7
  42. metadata +2 -45
  43. data/lib/zillabyte/api/locks.rb +0 -4
data/lib/zillabyte/cli.rb CHANGED
@@ -1,31 +1,15 @@
1
- load('zillabyte/helpers.rb') # reload helpers after possible inject_loadpath
2
- # load('zillabyte/updater.rb') # reload updater after possible inject_loadpath
3
-
4
- require 'zillabyte/cli/config'
5
- require "zillabyte/auth"
6
- require "zillabyte/command"
7
- require 'terminal-table'
8
- require 'chronic'
9
- require 'ascii_charts'
10
-
11
- # workaround for rescue/reraise to define errors in command.rb failing in 1.8.6
12
- if RUBY_VERSION =~ /^1.8.6/
13
- # require('zillabyte-api')
14
- require('rest_client')
15
- end
16
-
17
- module Zillabyte::CLI
18
-
19
- extend Zillabyte::Helpers
1
+ module Zillabyte; module CLI
20
2
 
21
3
  def self.start(*args)
22
4
  begin
23
- command = args.shift.strip rescue "help"
24
- Zillabyte::Command.load
5
+ command = args.shift().strip() rescue "help"
6
+ require("zillabyte/command")
7
+ Zillabyte::Command.load(command)
25
8
  Zillabyte::Command.run(command, args)
26
9
  rescue Interrupt
27
10
  `stty icanon echo`
28
- error("Command cancelled.")
11
+ require("zillabyte/helpers")
12
+ Zillabyte::Helpers.error("Command cancelled.")
29
13
  rescue => error
30
14
  raise
31
15
  #display(error)
@@ -33,5 +17,4 @@ module Zillabyte::CLI
33
17
  end
34
18
  end
35
19
 
36
- end
37
-
20
+ end; end
@@ -1,14 +1,5 @@
1
- require "zillabyte/cli/flows"
2
- require "zillabyte/cli/config"
3
- require "zillabyte/runner/app_runner"
4
- require "zillabyte/common"
5
- require "pty"
6
- require 'indentation'
7
- require 'open3'
8
- require 'securerandom'
9
- require 'colorize'
10
- require 'time_difference'
11
- require 'net/http'
1
+ require("zillabyte/cli/flows")
2
+ require("zillabyte/cli/helpers/table_output_builder")
12
3
 
13
4
  # manage custom apps
14
5
  #
@@ -296,8 +287,10 @@ class Zillabyte::Command::Apps < Zillabyte::Command::Flows
296
287
 
297
288
  display "initializing empty #{lang} app in #{dir}" if type.nil?
298
289
  erb_binding = binding
290
+ require("fileutils")
299
291
  FileUtils.mkdir_p dir
300
-
292
+
293
+ require("erb")
301
294
  Dir[File.join(File.expand_path("../templates/apps/#{lang}", __FILE__), "*")].each do |source_file|
302
295
 
303
296
  next if File.directory?(source_file)
@@ -496,6 +489,8 @@ class Zillabyte::Command::Apps < Zillabyte::Command::Flows
496
489
  private
497
490
 
498
491
  def describe_app(meta, colors = {})
492
+ require("colorize")
493
+ require("indentation")
499
494
  @colors ||= [:green, :yellow, :magenta, :cyan, :light_black, :light_green, :light_yellow, :light_blue, :light_magenta, :light_cyan]
500
495
  rjust = 20
501
496
  display "#{'app name'.rjust(rjust)}: #{meta['name']}"
@@ -1,6 +1,4 @@
1
- require "fileutils"
2
- require "zillabyte/api"
3
- require "zillabyte/command"
1
+ require("zillabyte/helpers")
4
2
 
5
3
  class Zillabyte::Command::Base
6
4
  include Zillabyte::Helpers
@@ -20,6 +18,8 @@ class Zillabyte::Command::Base
20
18
  end
21
19
 
22
20
  def api
21
+ require("zillabyte/api")
22
+ require("zillabyte/auth")
23
23
  @__api ||= Zillabyte::API.new(:api_key => Zillabyte::Auth.api_key, :session => self)
24
24
  end
25
25
 
@@ -1,7 +1,4 @@
1
- require 'yaml'
2
1
  require "zillabyte/cli/flows"
3
- require "zillabyte/cli/config"
4
- require "zillabyte/common"
5
2
 
6
3
  # manage custom components
7
4
  #
@@ -48,7 +45,9 @@ class Zillabyte::Command::Components < Zillabyte::Command::Flows
48
45
 
49
46
  display "initializing empty #{lang} component in #{dir}" if type.nil?
50
47
  erb_binding = binding
48
+ require("fileutils")
51
49
  FileUtils.mkdir_p dir
50
+ require("erb")
52
51
 
53
52
  Dir[File.join(File.expand_path("../templates/components/#{lang}", __FILE__), "*")].each do |source_file|
54
53
 
@@ -88,6 +87,7 @@ class Zillabyte::Command::Components < Zillabyte::Command::Flows
88
87
  end
89
88
 
90
89
  display "components:\n" if type.nil?
90
+ require("zillabyte/cli/helpers/table_output_builder")
91
91
  display TableOutputBuilder.build_table(headings, rows, type)
92
92
  display "Total number of components: " + rows.length.to_s if type.nil?
93
93
  end
@@ -235,6 +235,7 @@ class Zillabyte::Command::Components < Zillabyte::Command::Flows
235
235
  dir = options[:directory] || Dir.pwd
236
236
  dir = File.expand_path(dir)
237
237
 
238
+ require("zillabyte/api/flows")
238
239
  hash = Zillabyte::API::Flows.get_rich_meta_info_from_script(dir, session, options)
239
240
  name = hash['name']
240
241
 
@@ -247,6 +248,7 @@ class Zillabyte::Command::Components < Zillabyte::Command::Flows
247
248
 
248
249
  # Push the component...
249
250
  session.display("packaging directory... ") if session && type.nil?
251
+ reqire("zillabyte/common/tar")
250
252
  tar = Zillabyte::Common::Tar.tar(dir)
251
253
 
252
254
  # Create the component
@@ -262,6 +264,7 @@ class Zillabyte::Command::Components < Zillabyte::Command::Flows
262
264
 
263
265
  # Push the tar...
264
266
  if(res['uri'])
267
+ require("net/http")
265
268
  uri = URI(res['uri'])
266
269
  try_again = 1
267
270
  while(try_again)
@@ -1,5 +1,3 @@
1
- require 'yaml'
2
-
3
1
  module Zillabyte
4
2
 
5
3
  module CLI
@@ -14,13 +12,14 @@ module Zillabyte
14
12
 
15
13
  conf_file = nil
16
14
  if options[:config_file] and File.exists?(options[:config_file])
17
- conf_file = options[:config_file]
15
+ conf_file = options[:config_file]
18
16
  else
19
17
  conf_file = File.join(dir, options[:config_file] || DEFAULT_CONFIG_FILE)
20
18
  end
21
19
  type = options[:output_type]
22
20
 
23
21
  return nil unless File.exists?(conf_file)
22
+ require("yaml")
24
23
  hash = YAML.load_file(conf_file)
25
24
 
26
25
  # set other fields on the configuraiton
@@ -29,6 +28,7 @@ module Zillabyte
29
28
  # The top_dir and rel_home_dir allows us to package up dependencies that
30
29
  # belong to sibling directories (e.g. the collectors directory)
31
30
  top_dir = File.expand_path(hash['top_dir'] || ".", dir)
31
+ require("pathname")
32
32
  top_path = Pathname.new(top_dir)
33
33
  rel_dir = Pathname.new(dir).relative_path_from(top_path).to_s
34
34
 
@@ -1,10 +1,4 @@
1
1
  require "zillabyte/cli/base"
2
- require "zillabyte/cli/helpers/table_output_builder"
3
- require "csv"
4
- require "open-uri"
5
- require "json"
6
- require "base64"
7
-
8
2
 
9
3
  # manage custom datasets
10
4
  #
@@ -51,6 +45,7 @@ class Zillabyte::Command::Data < Zillabyte::Command::Base
51
45
  end
52
46
 
53
47
  display "datasets\n" if type.nil? && rows.size > 0
48
+ require("zillabyte/cli/helpers/table_output_builder")
54
49
  display TableOutputBuilder.build_table(headings, rows, type)
55
50
  display "Total number of datasets: "+rows.length.to_s if type.nil?
56
51
 
@@ -195,6 +190,7 @@ class Zillabyte::Command::Data < Zillabyte::Command::Base
195
190
 
196
191
  # TODO: post to direct signed s3 (http://docs.aws.amazon.com/AWSRubySDK/latest/AWS/S3/PresignedPost.html)
197
192
  display(".", false)
193
+ require("base64")
198
194
  res = self.api.data.append(id, {:gzip_rows => Base64.encode64(gzip(rows.to_json()))})
199
195
  # res = self.api.data.append(id, {:rows => rows})
200
196
 
@@ -389,7 +385,7 @@ class Zillabyte::Command::Data < Zillabyte::Command::Base
389
385
  end
390
386
  rows << new_row
391
387
  end
392
-
388
+ require("zillabyte/cli/helpers/table_output_builder")
393
389
  display TableOutputBuilder.build_table(headings, rows, type)
394
390
  else
395
391
  if type == "json"
@@ -532,7 +528,7 @@ class Zillabyte::Command::Data < Zillabyte::Command::Base
532
528
  case filetype
533
529
  when "csv"
534
530
  begin
535
-
531
+ require("csv")
536
532
  CSV.foreach(file) do |row|
537
533
  if row.size != n_columns
538
534
  error("dataset expects #{n_columns} column(s). Found a row with #{row.size}::\n #{row}", type)
@@ -610,6 +606,8 @@ class Zillabyte::Command::Data < Zillabyte::Command::Base
610
606
 
611
607
 
612
608
  def gzip(string)
609
+ require("stringio")
610
+ require("zlib")
613
611
  wio = StringIO.new("w")
614
612
  w_gz = Zlib::GzipWriter.new(wio)
615
613
  w_gz.write(string)
@@ -1,16 +1,4 @@
1
- require "zillabyte/cli/base"
2
- require "zillabyte/cli/config"
3
- require "zillabyte/common"
4
- require "pty"
5
- require 'indentation'
6
- require 'open3'
7
- require 'securerandom'
8
- require 'colorize'
9
- require 'time_difference'
10
- require 'net/http'
11
- require "zillabyte/runner/component_runner"
12
- require "zillabyte/runner/app_runner"
13
-
1
+ require("zillabyte/cli/base")
14
2
 
15
3
  # HIDDEN: superclass for components and apps
16
4
  #
@@ -87,6 +75,7 @@ class Zillabyte::Command::Flows < Zillabyte::Command::Base
87
75
  error("target directory not empty. use --force to override", type)
88
76
  end
89
77
  else
78
+ require("fileutils")
90
79
  FileUtils.mkdir_p(dir)
91
80
  end
92
81
 
@@ -114,6 +103,7 @@ class Zillabyte::Command::Flows < Zillabyte::Command::Base
114
103
  # --mode MODE # Specify development or production mode for dependencies #HIDDEN
115
104
  #
116
105
  def prep()
106
+ require("zillabyte/cli/config")
117
107
  mode, bundle_extra = case options[:mode]
118
108
  when nil, "development"
119
109
  [:development, ""]
@@ -204,6 +194,7 @@ class Zillabyte::Command::Flows < Zillabyte::Command::Base
204
194
  # --output_type OUTPUT_TYPE # Specify an output type i.e. json #HIDDEN
205
195
  #
206
196
  def errors
197
+ require("colorize")
207
198
 
208
199
  # Init
209
200
  flow_id = options[:id] || shift_argument
@@ -219,6 +210,7 @@ class Zillabyte::Command::Flows < Zillabyte::Command::Base
219
210
  type = options[:output_type]
220
211
 
221
212
  # Make the request
213
+ require("cgi")
222
214
  res = api.request(
223
215
  :expects => 200,
224
216
  :method => :get,
@@ -241,6 +233,7 @@ class Zillabyte::Command::Flows < Zillabyte::Command::Base
241
233
  a[1] <=> b[1]
242
234
  end
243
235
  color_map = {}
236
+ require("zillabyte/cli/log_formatter")
244
237
  colors = LogFormatter::COLORS.clone
245
238
  rows.each do |row|
246
239
  name = row[0]
@@ -270,7 +263,7 @@ class Zillabyte::Command::Flows < Zillabyte::Command::Base
270
263
  # --output_type OUTPUT_TYPE # Specify an output type i.e. json #HIDDEN
271
264
  #
272
265
  def live_run
273
-
266
+ require("zillabyte/cli/config")
274
267
  name = options[:name] || shift_argument
275
268
  type = options[:output_type]
276
269
 
@@ -306,7 +299,6 @@ class Zillabyte::Command::Flows < Zillabyte::Command::Base
306
299
  # --output_type OUTPUT_TYPE # Specify an output type i.e. json #HIDDEN
307
300
  #
308
301
  def info
309
-
310
302
  dir = options[:directory] || shift_argument
311
303
  if dir.nil?
312
304
  dir = Dir.pwd
@@ -315,10 +307,12 @@ class Zillabyte::Command::Flows < Zillabyte::Command::Base
315
307
  end
316
308
  options[:directory] = dir
317
309
 
310
+ require("securerandom")
318
311
  info_file = "#{dir}/#{SecureRandom.uuid}"
319
312
  type = options[:output_type]
320
313
 
321
314
  cmd = command("--info --file #{info_file}", type, dir)
315
+ require("zillabyte/cli/apps")
322
316
  flow_info = Zillabyte::Command::Apps.get_info(cmd, info_file, dir, options)
323
317
 
324
318
  if type == "json"
@@ -421,7 +415,6 @@ class Zillabyte::Command::Flows < Zillabyte::Command::Base
421
415
 
422
416
  def self.get_info(cmd, info_file, dir, options = {})
423
417
  type = options[:output_type]
424
-
425
418
  response = `#{cmd}`
426
419
  if($?.exitstatus == 1)
427
420
 
@@ -482,6 +475,7 @@ class Zillabyte::Command::Flows < Zillabyte::Command::Base
482
475
  options[:directory] = dir
483
476
 
484
477
  # Get the flow_type
478
+ require("zillabyte/api/flows")
485
479
  meta = Zillabyte::API::Flows.get_rich_meta_info_from_script(dir, session, {:test => true})
486
480
  if meta.nil? || meta["nodes"].nil?
487
481
  error "this is not a valid zillabyte app directory"
@@ -499,11 +493,14 @@ class Zillabyte::Command::Flows < Zillabyte::Command::Base
499
493
 
500
494
  case meta["flow_type"]
501
495
  when "component"
496
+ require("zillabyte/runner/component_runner")
502
497
  runner = Zillabyte::Runner::ComponentRunner.new()
503
498
  when "app"
499
+ require("zillabyte/runner/app_runner")
504
500
  runner = Zillabyte::Runner::AppRunner.new()
505
501
  else
506
502
  # Default to App
503
+ require("zillabyte/runner/app_runner")
507
504
  runner = Zillabyte::Runner::AppRunner.new()
508
505
  end
509
506
 
@@ -582,6 +579,7 @@ class Zillabyte::Command::Flows < Zillabyte::Command::Base
582
579
 
583
580
 
584
581
  def command(arg="--execute_live", type = nil, dir = Dir.pwd, ignore_stderr = false)
582
+ require("zillabyte/cli/config")
585
583
  meta = Zillabyte::CLI::Config.get_config_info(dir, self, options)
586
584
 
587
585
  #meta = Zillabyte::API::Functions.get_rich_meta_info_from_script(dir, self)
@@ -616,12 +614,15 @@ class Zillabyte::Command::Flows < Zillabyte::Command::Base
616
614
 
617
615
  def read_name_from_conf(options = {})
618
616
  type = options[:output_type]
617
+ require("zillabyte/api/apps")
619
618
  hash = Zillabyte::API::Apps.get_rich_meta_info_from_script Dir.pwd, options
620
619
  error("No id given and current directory does not contain a valid Zillabyte configuration file. Please specify a flow id or run command from the directory containing the flow.",type) if hash["error"]
621
620
  hash["name"]
622
621
  end
623
622
 
624
623
  def fetch_logs(hash, operation=nil, exit_on=nil)
624
+ require("colorize")
625
+ require("pty")
625
626
  def color_for(operation_name)
626
627
  @color_map[operation_name] ||= @all_colors[ @color_map.size % @all_colors.size ]
627
628
  @color_map[operation_name]
@@ -1,4 +1,4 @@
1
- require "zillabyte/cli/base"
1
+ require("zillabyte/cli/base")
2
2
 
3
3
  # list commands and display help
4
4
  #
@@ -12,7 +12,8 @@ class Zillabyte::Command::Help < Zillabyte::Command::Base
12
12
  if command = args.shift || direct_args.shift
13
13
  if command == "aliases"
14
14
  puts "Useful aliases: "
15
- puts
15
+ puts
16
+ Zillabyte::Command.load("")
16
17
  summary_for_aliases(Zillabyte::Command.command_aliases)
17
18
  else
18
19
  help_for_command(command)
@@ -102,6 +103,7 @@ private
102
103
  end
103
104
 
104
105
  def help_for_root
106
+ Zillabyte::Command.load("")
105
107
  puts "Usage: zillabyte COMMAND [command-specific-options]"
106
108
  puts
107
109
  puts "Primary help topics, type \"zillabyte help TOPIC\" for more details:"
@@ -132,6 +134,7 @@ private
132
134
  end
133
135
 
134
136
  def help_for_command(name)
137
+ Zillabyte::Command.load(name)
135
138
  if command_alias = Zillabyte::Command.command_aliases[name]
136
139
  display("Alias: #{name} redirects to #{command_alias}")
137
140
  name = command_alias
@@ -1,5 +1,4 @@
1
- class Zillabyte::Helpers::TableOutputBuilder
2
-
1
+ module Zillabyte; module Helpers; class TableOutputBuilder
3
2
 
4
3
  def self.build_table(headings, rows, format = nil)
5
4
  if format == "json"
@@ -20,6 +19,7 @@ class Zillabyte::Helpers::TableOutputBuilder
20
19
  end
21
20
 
22
21
  def self.build_terminal_table(headings, rows)
22
+ require("terminal-table")
23
23
  Terminal::Table.new(:headings => headings, :rows => rows).to_s
24
24
  end
25
- end
25
+ end; end; end
@@ -1,10 +1,5 @@
1
1
  require "zillabyte/cli/base"
2
2
  require "zillabyte/cli/helpers/table_output_builder"
3
- require "cgi"
4
- require "csv"
5
- require "open-uri"
6
- require "json"
7
-
8
3
 
9
4
  # manage authentication keys
10
5
  #
@@ -48,6 +48,7 @@ class LogFormatter
48
48
  end
49
49
 
50
50
  def display(operation_name, operation_index, category, date, line)
51
+ require("colorize")
51
52
  puts "#{get_name(operation_name, operation_index).rjust(9).colorize(color_for(operation_name))} - #{line}"
52
53
  end
53
54
 
@@ -75,6 +76,7 @@ class LogFormatter
75
76
  class Startup < Base
76
77
 
77
78
  def display(operation_name, operation_index, category, date, line)
79
+ require("colorize")
78
80
  puts "#{get_name(operation_name, operation_index).rjust(15).colorize(color_for(operation_name))} : #{line}"
79
81
  end
80
82
 
@@ -1,7 +1,4 @@
1
1
  require "zillabyte/cli/base"
2
- require "zillabyte/cli/config"
3
- require "zillabyte/common"
4
-
5
2
 
6
3
  # HIDDEN: resets all user state
7
4
  #