3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
|
# File 'lib/shepherd/commands/rm.rb', line 3
def init
@opts = Trollop::options do
banner <<-EOB
usage: shep [options] rm <id>
EOB
opt :quiet, "don't produce output"
opt :help, "show me and exit", :short => '-h'
end
unless id = ARGV.first
puts "[shep] error: no sheep specified."
exit 1
end
id = id.to_i
if Shepherd::Db.new.get_first_row "select * from sheeps where id = ? limit 1", id
if Shepherd::Db.new.execute "delete from sheeps where id = ?", id
puts "[shep] good: successfuly deleted sheep." unless @opts[:quiet]
else
puts "[shep] error: something went wrong." unless @opts[:quiet]
end
else
puts "[shep] error: no such sheep." unless @opts[:quiet]
end
end
|