Class: Zillabyte::Command::Components

Inherits:
Flows
  • Object
show all
Defined in:
lib/zillabyte/cli/components.rb

Overview

manage custom components

Constant Summary

Constants inherited from Flows

Flows::MAX_POLL_SECONDS, Flows::POLL_SLEEP

Constants inherited from Base

Base::META_COLUMNS

Instance Attribute Summary

Attributes inherited from Base

#args, #options

Instance Method Summary collapse

Methods inherited from Flows

#details, #errors, #kill, #local, #on_exit, #pause, #resume, #scale

Methods inherited from Base

#api, #initialize, namespace

Methods included from Helpers

#app, #ask, #command, #create_git_remote, #display, #error, #extract_app_from_git_config, #extract_app_in_dir, #format_with_bang, #friendly_dir, #get_flow_ui_link, #get_info, #get_rich_info, #git, #handle_downloading_manifest, #has_git?, #longest, #read_multiline, #truncate_message, #version_okay?, #with_tty

Constructor Details

This class inherits a constructor from Zillabyte::Command::Base

Instance Method Details

#authorizeObject

components:authorize [ID] [SCOPE]

changes permission of the flow

–id ID # The dataset id –public # Makes the flow public (default) –private # Makes the flow private



198
199
# File 'lib/zillabyte/cli/components.rb', line 198

def authorize
end

#deleteObject

components:delete ID

Deletes a component. If the rpc is currently running, this command will kill it.

-f, –force # Don’t ask for confirmation –output_type OUTPUT_TYPE # Specify an output type i.e. json #HIDDEN



122
123
124
# File 'lib/zillabyte/cli/components.rb', line 122

def delete
  super
end

#indexObject

components

List custom components.

–output_type OUTPUT_TYPE # Specify an output type i.e. json #HIDDEN



13
14
15
# File 'lib/zillabyte/cli/components.rb', line 13

def index
  self.list
end

#infoObject

components:info [DIR]

Outputs the info for the component in the dir.

–pretty # Pretty prints the info output –dir DIR # Component directory –output_type OUTPUT_TYPE # Specify an output type i.e. json #HIDDEN



135
136
137
# File 'lib/zillabyte/cli/components.rb', line 135

def info
  super
end

#initObject

components:init [NAME]

Initializes a new component.

–lang LANG # Specify which language to use (ruby, python) [default: ‘ruby’] –dir DIR # Target directory of the app –remote REMOTE # The git remote name [default: ‘zillabyte’]

Examples:

$ zillabyte components:init domain_extractor –lang ruby



30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# File 'lib/zillabyte/cli/components.rb', line 30

def init
  
  name = options[:name] || shift_argument
  error("name required") if name.nil?
    
  lang = options[:lang] || options[:language] || "ruby"
  dir = options[:dir] || Dir.pwd
  remote = options[:remote] || "zillabyte"
  
  dir = File.expand_path(dir) unless dir.nil?
  type = options[:output_type]

  languages = ["ruby","python", "js"]

  error("Unsupported language #{lang}. Zillabyte currently supports #{languages.join(', ')}.", type) if not languages.include? lang

  display "initializing empty #{lang} component in #{friendly_dir(dir)}" if type.nil?
  erb_binding = binding
  require("fileutils")
  FileUtils.mkdir_p dir
  require("erb")
  
  Dir[File.join(File.expand_path("../templates/components/#{lang}", __FILE__), "*")].each do |source_file|
    
    next if File.directory?(source_file)
    erb = ERB.new(File.read(source_file))
    erb.filename = source_file
    
    dest_file = File.join(dir, File.basename(source_file).gsub(/\.erb$/, ""))
    File.open(dest_file, 'w') {|file| file.write(erb.result(erb_binding))}
    
  end
  
  # Add the git remote... 
  # add_git_remote(name, remote)
  
end

#listObject

components

List custom components.

–output_type OUTPUT_TYPE # Specify an output type i.e. json #HIDDEN



77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
# File 'lib/zillabyte/cli/components.rb', line 77

def list
  type = options[:output_type]
  
  headings = ["id", "name", "state", "inputs", "outputs"]
  rows = api.component.list.map do |row|
    if headings.size == 0
      headings = row.keys 
      headings.delete("rel_dir")
    end
    
    v = row.values_at *headings
    v
  end

  display "components:\n" if type.nil?
  require("zillabyte/cli/helpers/table_output_builder")
  display TableOutputBuilder.build_table(headings, rows, type)
  display "Total number of components: " + rows.length.to_s if type.nil?
end

#live_runObject

components:live_run [OPERATION_NAME] [PIPE_NAME] [DIR]

Runs a local component with live data.

–config CONFIG_FILE # Use the given config file –dir DIR # Component directory –output_type OUTPUT_TYPE # Specify an output type i.e. json HIDDEN

HIDDEN:



185
186
187
# File 'lib/zillabyte/cli/components.rb', line 185

def live_run
  super
end

#logsObject

components:logs ID [OPERATION_NAME]

Streams logs for the component from our cluster.

–operation OPERATION_NAME # Specify the operation to show logs for -v, –verbose LEVEL # Sets the verbosity (error, info, debug) [default: info] –output_type OUTPUT_TYPE # Specify an output type i.e. json #HIDDEN



172
173
174
# File 'lib/zillabyte/cli/components.rb', line 172

def logs
  super
end

#prepObject

components:prep [DIR]

Performs any necessary initialization for the component.

–dir DIR # Component directory –output_type OUTPUT_TYPE # Specify an output type i.e. json HIDDEN



160
161
162
# File 'lib/zillabyte/cli/components.rb', line 160

def prep
  super
end

#pullObject

components:pull ID DIR

Pulls a component source to a directory.

–force # Pulls even if the directory exists –dir DIR # Component directory –output_type OUTPUT_TYPE # Specify an output type i.e. json #HIDDEN

Examples:

$ zillabyte components:pull 27 .



110
111
112
# File 'lib/zillabyte/cli/components.rb', line 110

def pull
  super
end

#pushObject

components:push [DIR]

Uploads a component.

–config CONFIG_FILE # Use the given config file –dir DIR # Component directory –public # Make the flow public

Examples:

$ zillabyte components:push .



213
214
215
# File 'lib/zillabyte/cli/components.rb', line 213

def push
  super 
end

#testObject

components:test

Tests a local component with sample data.

–config CONFIG_FILE # Use the given config file –input INPUT_FILE # Uses a CSV for component input –output OUTPUT_FILE # Write output to a CSV –dir DIR # Component directory



149
150
151
# File 'lib/zillabyte/cli/components.rb', line 149

def test
  super
end