Class: Mode::Sdk::Cli

Inherits:
Object
  • Object
show all
Defined in:
lib/mode/sdk/cli.rb

Overview

Provides command line interface functionality for importing data

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Mode::Sdk::Cli

Construct a new Cli instance

Options Hash (options):

  • :replace (true, false)

    whether to allow the table to be replaced, if it exists

  • :table_name (String)

    the name of the table (defaults to normalized file name)

  • :upload_token (String)

    the token of a previously created Mode upload

  • :token (String)

    Mode API token

  • :secret (String)

    Mode API secret

  • :clean (true, false)

    whether to clean table data on import


31
32
33
# File 'lib/mode/sdk/cli.rb', line 31

def initialize(options = {})
  @options = options
end

Instance Attribute Details

#optionsHash (readonly)

hash of options


11
12
13
# File 'lib/mode/sdk/cli.rb', line 11

def options
  @options
end

Class Method Details

.env_get(key, prompt = nil) ⇒ String

Get value from environment variable or stdin prompt


238
239
240
241
242
243
# File 'lib/mode/sdk/cli.rb', line 238

def env_get(key, prompt = nil)
  return ENV[key] if ENV[key]

  $stdout.print "#{prompt}: " if prompt
  $stdin.gets.chomp
end

Instance Method Details

#import!Object

Authenticate and import data


37
38
39
40
41
42
43
44
# File 'lib/mode/sdk/cli.rb', line 37

def import!
  authenticate!
  validate_options!

  import.poll do |repr|
    handle_import_state(repr)
  end
end