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
@@ -293,7 +293,7 @@ class Zillabyte::Command::Query < Zillabyte::Command::Base
293
293
  query = options[:query] || shift_argument
294
294
  error("query cannot be empty", type) if query.nil?
295
295
 
296
- type = options [:output_type]
296
+ type = options[:output_type]
297
297
 
298
298
  user_s3_access_key = options[:s3_access_key] || shift_argument
299
299
  user_s3_secret = options[:s3_secret] || shift_argument
@@ -1,6 +1,4 @@
1
1
  require "zillabyte/cli/base"
2
- require 'readline'
3
- require("shellwords")
4
2
  # REPL console for zillabyte commands
5
3
  #
6
4
  class Zillabyte::Command::Repl < Zillabyte::Command::Base
@@ -13,7 +11,10 @@ class Zillabyte::Command::Repl < Zillabyte::Command::Base
13
11
  # --history HISTORY # HIDDEN hack to allow history for readline
14
12
  #
15
13
  def index
14
+ require("readline")
15
+ require("shellwords")
16
16
  if !options[:quiet]
17
+ Zillabyte::Command.load("version")
17
18
  Zillabyte::Command.run("version")
18
19
  display "Type q,exit or Ctrl+D to quit\n\n"
19
20
  end
@@ -47,6 +48,7 @@ class Zillabyte::Command::Repl < Zillabyte::Command::Base
47
48
  buf = ""
48
49
  begin
49
50
  pid = fork() do
51
+ Zillabyte::Command.load(command)
50
52
  Zillabyte::Command.run(command, args)
51
53
  end
52
54
  ensure
@@ -1,20 +1,31 @@
1
- require 'zillabyte/helpers'
2
- require "optparse"
3
-
4
1
  module Zillabyte
5
2
  module Command
6
3
  class CommandFailed < RuntimeError; end
7
4
 
8
- extend Zillabyte::Helpers
9
-
10
- def self.load
11
- Dir[File.join(File.dirname(__FILE__), "cli", "*.rb")].each do |file|
12
- require file
5
+ # command should be non-nil
6
+ def self.load(command)
7
+ # To speed up load times, we try to load only the minimal required
8
+ # libraries if the fully qualified name is given (i.e.
9
+ # command:subcommand)
10
+ base_dir = File.join(File.dirname(__FILE__), "cli")
11
+ command_file = "#{command[/^([^:]*):?/, 1]}.rb"
12
+ # fnmatch? check is for safety (to ensure the command matches only a
13
+ # single file).
14
+ if File.fnmatch?("*.rb", command_file, File::FNM_PATHNAME)
15
+ begin
16
+ require(File.join(base_dir, command_file))
17
+ return
18
+ rescue LoadError
19
+ # Command wasn't a direct match, so fall through to the normal load.
20
+ end
13
21
  end
14
- Dir[File.join(File.dirname(__FILE__), "cli", "helpers", "*.rb")].each do |file|
15
- require file
22
+ # Normal load (we don't know what command we're going to run, so we
23
+ # speculatively load everything).
24
+ Dir[File.join(base_dir, "*.rb")].each do |file|
25
+ require(file)
16
26
  end
17
- unregister_commands_made_private_after_the_fact
27
+ ensure
28
+ unregister_commands_made_private_after_the_fact
18
29
  end
19
30
 
20
31
  def self.commands
@@ -118,11 +129,13 @@ module Zillabyte
118
129
 
119
130
  if args.include?('-h') || args.include?('--help')
120
131
  args.unshift(cmd) unless cmd =~ /^-.*/
132
+ self.load("help")
121
133
  cmd = 'help'
122
134
  command = parse(cmd)
123
135
  end
124
136
 
125
137
  if cmd == '--version' or cmd == '-version'
138
+ self.load("version")
126
139
  cmd = 'version'
127
140
  command = parse(cmd)
128
141
  end
@@ -132,7 +145,7 @@ module Zillabyte
132
145
 
133
146
  opts = {}
134
147
  invalid_options = []
135
-
148
+ require("optparse")
136
149
  parser = OptionParser.new do |parser|
137
150
  # remove OptionParsers Officious['version'] to avoid conflicts
138
151
  # see: https://github.com/ruby/ruby/blob/trunk/lib/optparse.rb#L814
@@ -177,6 +190,7 @@ module Zillabyte
177
190
 
178
191
  @anonymous_command = [ARGV.first, *@anonymized_args].join(' ')
179
192
  begin
193
+ require("fileutils")
180
194
  usage_directory = "#{home_directory}/.zillabyte/usage"
181
195
  FileUtils.mkdir_p(usage_directory)
182
196
  usage_file = usage_directory << "/#{Zillabyte::CLI::VERSION}"
@@ -210,6 +224,9 @@ module Zillabyte
210
224
  end
211
225
 
212
226
  def self.run(cmd, arguments=[])
227
+ require("excon/errors")
228
+ require("zillabyte/helpers")
229
+ extend(Zillabyte::Helpers)
213
230
  begin
214
231
  object, method = prepare_run(cmd, arguments.dup)
215
232
  object.send(method)
@@ -1,11 +1,6 @@
1
1
  # https://gist.github.com/sinisterchipmunk/1335041
2
2
 
3
- require 'rubygems'
4
- require 'rubygems/package'
5
- require 'zlib'
6
- require 'fileutils'
7
-
8
- module Zillabyte::Common
3
+ module Zillabyte; module Common
9
4
  class Tar
10
5
 
11
6
  # Creates a tar file in memory recursively
@@ -17,6 +12,8 @@ module Zillabyte::Common
17
12
  # Returns a StringIO whose underlying String
18
13
  # is the contents of the tar file.
19
14
  def self.tar(path, ignore_files = [])
15
+ require("stringio")
16
+ require("rubygems/package")
20
17
  tarfile = StringIO.new("")
21
18
  ignore_regexp = if ignore_files.empty?()
22
19
  []
@@ -59,6 +56,8 @@ module Zillabyte::Common
59
56
  # returning a new StringIO representing the
60
57
  # compressed file.
61
58
  def self.gzip(tarfile)
59
+ require("stringio")
60
+ require("zlib")
62
61
  gz = StringIO.new("")
63
62
  z = Zlib::GzipWriter.new(gz)
64
63
  z.write tarfile.string
@@ -81,6 +80,8 @@ module Zillabyte::Common
81
80
  # untars the given IO into the specified
82
81
  # directory
83
82
  def self.untar(io, destination)
83
+ require("fileutils")
84
+ require("rubygems/package")
84
85
  Gem::Package::TarReader.new io do |tar|
85
86
  tar.each do |tarfile|
86
87
  destination_file = File.join destination, tarfile.full_name
@@ -99,4 +100,4 @@ module Zillabyte::Common
99
100
  end
100
101
  end
101
102
 
102
- end
103
+ end; end
@@ -1,5 +1,4 @@
1
- # require "vendor/zillabyte/okjson"
2
- require "json"
1
+ require("json")
3
2
 
4
3
  module Zillabyte
5
4
  module Helpers
@@ -117,6 +116,7 @@ module Zillabyte
117
116
  def add_git_remote(name, remote = "zillabyte")
118
117
 
119
118
  remotes = {}
119
+ require("zillabyte/auth")
120
120
  remotes[remote] = Zillabyte::Auth.git_host
121
121
 
122
122
  if ENV["ZILLABYTE_EXTRA_GIT_REMOTES"]
@@ -148,6 +148,7 @@ module Zillabyte
148
148
 
149
149
 
150
150
  def get_flow_name(dir = Dir.pwd)
151
+ require("zillabyte/api/flows")
151
152
  meta = Zillabyte::API::Flows.get_rich_meta_info_from_script(dir)
152
153
  return meta["name"] if meta
153
154
  return nil
@@ -155,6 +156,7 @@ module Zillabyte
155
156
 
156
157
 
157
158
  def handle_downloading_manifest(file, res, type = nil)
159
+ require("open-uri")
158
160
  if res["manifest"]
159
161
  res["manifest"].each_with_index do |uri, index|
160
162
 
@@ -1,8 +1,4 @@
1
- require "zillabyte/cli/base"
2
- require "zillabyte/runner"
3
1
  require "zillabyte/runner/multilang_operation"
4
- require 'thread'
5
-
6
2
 
7
3
  # HIDDEN:
8
4
  class Zillabyte::Runner::AppRunner < Zillabyte::Command::Base
@@ -175,6 +171,7 @@ class Zillabyte::Runner::AppRunner < Zillabyte::Command::Base
175
171
 
176
172
 
177
173
  def cdisplay(name, message)
174
+ require("colorize")
178
175
  color = @colors[name] || :default
179
176
  if message == ""
180
177
  display ""
@@ -196,6 +193,7 @@ class Zillabyte::Runner::AppRunner < Zillabyte::Command::Base
196
193
 
197
194
 
198
195
  def query_agnostic(query)
196
+ require("zillabyte/api")
199
197
  @session.api.query.agnostic(query)
200
198
  end
201
199
 
@@ -205,6 +203,8 @@ class Zillabyte::Runner::AppRunner < Zillabyte::Command::Base
205
203
 
206
204
 
207
205
  def describe_app(meta)
206
+ require("colorize")
207
+ require("indentation")
208
208
  colors ||= [:green, :yellow, :magenta, :cyan, :white, :blue, :light_yellow, :light_blue, :red, :light_magenta, :light_cyan]
209
209
  rjust = 20
210
210
  display "#{'app name'.rjust(rjust)}: #{meta['name']}"
@@ -1,9 +1,4 @@
1
- require 'json'
2
- require 'mkfifo'
3
- require "zillabyte/runner"
4
1
  require "zillabyte/runner/multilang_operation"
5
- require "zillabyte/runner/component_runner"
6
- require 'zillabyte/api/components'
7
2
 
8
3
 
9
4
 
@@ -213,6 +208,7 @@ class Zillabyte::Runner::ComponentOperation
213
208
 
214
209
  # Start communication with API
215
210
  api = @__tester.session.api
211
+ require("zillabyte/api/components")
216
212
  caller = Zillabyte::API::Components.new(api)
217
213
  component_id = @__node["id"]
218
214
  output_format = @__node["output_format"]
@@ -567,6 +563,7 @@ class Zillabyte::Runner::ComponentOperation
567
563
  cmd = "cd \"#{@__dir}\"; PYTHONPATH=~/zb1/multilang/python/Zillabyte python \"#{full_script}\" #{arg} #{stderr_opt}"
568
564
  end
569
565
  when "js"
566
+ require("zillabyte/api/settings")
570
567
  cmd = "cd \"#{@__dir}\"; NODE_PATH=~/zb1/multilang/js/src/lib #{Zillabyte::API::NODEJS_BIN} \"#{full_script}\" #{arg} #{stderr_opt}"
571
568
  else
572
569
  cdisplay("no language specified")
@@ -1,8 +1,5 @@
1
- require "zillabyte/cli/base"
2
- require "zillabyte/runner"
3
1
  require "zillabyte/runner/multilang_operation"
4
2
  require "zillabyte/runner/component_operation"
5
- require 'thread'
6
3
 
7
4
  # HIDDEN:
8
5
  class Zillabyte::Runner::ComponentRunner < Zillabyte::Command::Base
@@ -189,6 +186,7 @@ class Zillabyte::Runner::ComponentRunner < Zillabyte::Command::Base
189
186
 
190
187
 
191
188
  def cdisplay(name, message)
189
+ require("colorize")
192
190
  color = @colors[name] || :default
193
191
  if message == ""
194
192
  display ""
@@ -203,6 +201,8 @@ class Zillabyte::Runner::ComponentRunner < Zillabyte::Command::Base
203
201
  end
204
202
 
205
203
  def describe_component(meta)
204
+ require("colorize")
205
+ require("indentation")
206
206
  colors ||= [:green, :yellow, :magenta, :cyan, :white, :blue, :light_yellow, :light_blue, :red, :light_magenta, :light_cyan]
207
207
  rjust = 20
208
208
 
@@ -1,10 +1,6 @@
1
- require 'json'
2
- require 'mkfifo'
3
- require "zillabyte/runner/component_operation"
4
-
5
1
 
6
2
  # Emulate a multilang operation
7
- class Zillabyte::Runner::MultilangOperation
3
+ module Zillabyte; module Runner; class MultilangOperation
8
4
 
9
5
  HANDSHAKE_MESSAGE = "{\"pidDir\": \"/tmp\"}\n"
10
6
  DONE_MESSAGE = "{\"command\": \"done\"}\n"
@@ -16,7 +12,11 @@ class Zillabyte::Runner::MultilangOperation
16
12
  ENDMARKER = "\nend\n"
17
13
 
18
14
  def self.run(node, dir, consumee, consumer_pipes, tester, meta, options = {})
15
+ require("mkfifo")
16
+ require("zillabyte/runner/component_operation")
19
17
 
18
+ require("pty")
19
+ require("open3")
20
20
  @__node = node
21
21
  @__name = node["name"]
22
22
  @__type = node["type"]
@@ -875,7 +875,9 @@ class Zillabyte::Runner::MultilangOperation
875
875
  end
876
876
 
877
877
  # Build table
878
+ require("terminal-table")
878
879
  table = Terminal::Table.new :title => @__name
880
+ require("csv")
879
881
  csv_str = CSV.generate do |csv|
880
882
  header_written = false;
881
883
  messages.each do |obj|
@@ -1137,4 +1139,4 @@ class Zillabyte::Runner::MultilangOperation
1137
1139
  end
1138
1140
 
1139
1141
 
1140
- end
1142
+ end; end; end
@@ -21,22 +21,18 @@ Gem::Specification.new do |spec|
21
21
  spec.require_paths = ["lib"]
22
22
 
23
23
  spec.add_development_dependency "rake"
24
- #spec.add_development_dependency "pry"
25
-
24
+
26
25
  spec.add_dependency "netrc", "~> 0.7.7"
27
26
  spec.add_dependency "rest-client", "~> 1.6.1"
28
-
27
+
29
28
  spec.add_dependency "excon", "~> 0.31"
30
29
  spec.add_dependency "terminal-table", "~> 1.4"
31
30
  spec.add_dependency "activesupport", "~> 3.2.11"
32
31
  spec.add_dependency "multi_json", "~> 1.0"
33
-
32
+
34
33
  spec.add_dependency "bundler", "~> 1.3"
35
34
  spec.add_dependency "colorize", "~> 0.6"
36
- spec.add_dependency "chronic", "~> 0.10"
37
- spec.add_dependency "ascii_charts", "~> 0.9.1"
38
35
  spec.add_dependency "indentation", "~> 0.1"
39
- spec.add_dependency "time_difference"
40
36
  spec.add_dependency "mkfifo"
41
37
 
42
38
  spec.post_install_message = """
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: zillabyte-cli
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.4
4
+ version: 0.1.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - zillabyte
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-07-16 00:00:00.000000000 Z
11
+ date: 2014-07-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake
@@ -136,34 +136,6 @@ dependencies:
136
136
  - - ~>
137
137
  - !ruby/object:Gem::Version
138
138
  version: '0.6'
139
- - !ruby/object:Gem::Dependency
140
- name: chronic
141
- requirement: !ruby/object:Gem::Requirement
142
- requirements:
143
- - - ~>
144
- - !ruby/object:Gem::Version
145
- version: '0.10'
146
- type: :runtime
147
- prerelease: false
148
- version_requirements: !ruby/object:Gem::Requirement
149
- requirements:
150
- - - ~>
151
- - !ruby/object:Gem::Version
152
- version: '0.10'
153
- - !ruby/object:Gem::Dependency
154
- name: ascii_charts
155
- requirement: !ruby/object:Gem::Requirement
156
- requirements:
157
- - - ~>
158
- - !ruby/object:Gem::Version
159
- version: 0.9.1
160
- type: :runtime
161
- prerelease: false
162
- version_requirements: !ruby/object:Gem::Requirement
163
- requirements:
164
- - - ~>
165
- - !ruby/object:Gem::Version
166
- version: 0.9.1
167
139
  - !ruby/object:Gem::Dependency
168
140
  name: indentation
169
141
  requirement: !ruby/object:Gem::Requirement
@@ -178,20 +150,6 @@ dependencies:
178
150
  - - ~>
179
151
  - !ruby/object:Gem::Version
180
152
  version: '0.1'
181
- - !ruby/object:Gem::Dependency
182
- name: time_difference
183
- requirement: !ruby/object:Gem::Requirement
184
- requirements:
185
- - - ! '>='
186
- - !ruby/object:Gem::Version
187
- version: '0'
188
- type: :runtime
189
- prerelease: false
190
- version_requirements: !ruby/object:Gem::Requirement
191
- requirements:
192
- - - ! '>='
193
- - !ruby/object:Gem::Version
194
- version: '0'
195
153
  - !ruby/object:Gem::Dependency
196
154
  name: mkfifo
197
155
  requirement: !ruby/object:Gem::Requirement
@@ -223,7 +181,6 @@ files:
223
181
  - lib/zillabyte/api/data.rb
224
182
  - lib/zillabyte/api/flows.rb
225
183
  - lib/zillabyte/api/keys.rb
226
- - lib/zillabyte/api/locks.rb
227
184
  - lib/zillabyte/api/logs.rb
228
185
  - lib/zillabyte/api/metrics.rb
229
186
  - lib/zillabyte/api/queries.rb
@@ -1,4 +0,0 @@
1
- module Zillabyte
2
- module Lock
3
- end
4
- end