class Gogdb::Cli

Public Class Methods

new(*args) click to toggle source
Calls superclass method
# File lib/gogdb/cli.rb, line 4
def initialize(*args)
  check_config
  super
end

Public Instance Methods

fetch() click to toggle source
# File lib/gogdb/cli.rb, line 23
def fetch
  @e = Gogdb::Engine.new(options)
  @e.fetch(options)
end
setup() click to toggle source
# File lib/gogdb/cli.rb, line 29
def setup
  db_path = ask("Enter path you want to save database (default #{ENV['HOME']}/.gogdb):")

  db_path = "#{ENV['HOME']}/.gogdb" if db_path.empty?

  @config = {
    "path" => db_path
  }

  # Stop execution if user does not want to overwrite.
  if File.exist?("config.yml")
    exit unless yes? "Config file already exists. Overwrite?(y/n)", :red
  end
  
  File.open("config.yml", "w") { |file|
    file.write(@config.to_yaml)
  }

  say "Config written successfully.", :green
end
version() click to toggle source
# File lib/gogdb/cli.rb, line 13
def version
  puts Gogdb::VERSION
end

Private Instance Methods

check_config() click to toggle source

Checks if config file exists. If not, runs setup automatically.

# File lib/gogdb/cli.rb, line 53
def check_config
  unless File.exist?("config.yml")
    say "It appears that you don't have config in place. You need to enter following details to make Gogdb work;", :yellow
    setup
  end
end