Class: Squill::CLIClient

Inherits:
Thor
  • Object
show all
Includes:
Thor::Actions
Defined in:
lib/squill/cli.rb

Instance Method Summary collapse

Instance Method Details

#add(name, file = nil) ⇒ Object



31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/squill/cli.rb', line 31

def add(name, file=nil)
  squill_file = Squill::SquillFile.new(name)
  if squill_file.exists_as_squill_file? && !options[:replace]
    puts "\na squill by this name already exists. use the the --replace option to replace it.\n"
    return
  end
  squill_file.description = options[:desc].nil? ? ask("Briefly describe #{name}: ") : options[:desc]
  if file.nil?
    squill_file.set_sql
  else
    squill_file.set_sql_from_file(file)
  end
  squill_file.save
  puts "\nsaved squill #{name}.\n"
end

#delete(name) ⇒ Object



92
93
94
95
96
97
98
99
100
101
102
# File 'lib/squill/cli.rb', line 92

def delete(name)
  squill_file = Squill::SquillFile.new(name)
  if squill_file.exists_as_squill_file?
    if yes?("are you sure you want to delete #{name}?")
      squill_file.delete
      puts "\nsquill #{name} deleted.\n"
    end
  else
    puts "\ncould not find squill named #{name} to delete.\n"
  end
end

#listObject



113
114
115
116
117
118
119
120
# File 'lib/squill/cli.rb', line 113

def list
  searcher = Squill::SquillFileSearcher.new
  results = searcher.list
  results.each { |result|
    puts "#{result.name} - #{result.description}"
  }
  puts "\nlisted #{results.length} squills.\n"
end


57
58
59
60
61
62
# File 'lib/squill/cli.rb', line 57

def print(name)
  squill_file = Squill::SquillFile.new(name)
  if squill_file.exists_as_squill_file?
    puts squill_file.sql
  end
end

#search(search_string) ⇒ Object



74
75
76
77
78
79
80
81
# File 'lib/squill/cli.rb', line 74

def search(search_string)
  searcher = Squill::SquillFileSearcher.new
  results = searcher.search(search_string)
  results.each { |result|
    puts "#{result[:name_highlight]} - #{result[:description_highlight]}"
  }
  puts "\nfound #{results.length} squills.\n"
end