Class: Geostats::Commands::Init

Inherits:
Base
  • Object
show all
Defined in:
lib/geostats/commands/init.rb

Instance Method Summary collapse

Methods inherited from Base

#initialize, #invoke

Constructor Details

This class inherits a constructor from Geostats::Commands::Base

Instance Method Details

#beforeObject



20
21
22
# File 'lib/geostats/commands/init.rb', line 20

def before
  connect_database(@directory)
end

#parse_argsObject

Raises:



11
12
13
14
15
16
17
18
# File 'lib/geostats/commands/init.rb', line 11

def parse_args
  raise UsageError unless @args.length == 2 or @args.length == 3

  @username, @password, @directory = @args
  @directory ||= File.expand_path("~/.geostats")

  FileUtils.mkdir_p(@directory) unless File.exists?(@directory)
end

#runObject



24
25
26
27
28
# File 'lib/geostats/commands/init.rb', line 24

def run
  Migrate.new.invoke
  Setting.set(:username, @username)
  Setting.set(:password, @password)
end

#usageObject



7
8
9
# File 'lib/geostats/commands/init.rb', line 7

def usage
  STDERR.puts "Usage: geostats init <username> <password> [<directory>]"
end