Class: Gogdb::Cli

Inherits:
Thor
  • Object
show all
Defined in:
lib/gogdb/cli.rb

Instance Method Summary collapse

Constructor Details

#initialize(*args) ⇒ Cli

Returns a new instance of Cli.



4
5
6
7
# File 'lib/gogdb/cli.rb', line 4

def initialize(*args)
  check_config
  super
end

Instance Method Details

#fetchObject



23
24
25
26
# File 'lib/gogdb/cli.rb', line 23

def fetch
  @e = Gogdb::Engine.new(options)
  @e.fetch(options)
end

#setupObject



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# 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

#versionObject



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

def version
  puts Gogdb::VERSION
end