Class: Cheatly::CLI

Inherits:
Thor
  • Object
show all
Includes:
Pager
Defined in:
lib/cheatly/cli.rb

Instance Method Summary collapse

Instance Method Details

#create(handle) ⇒ Object



38
39
40
41
42
# File 'lib/cheatly/cli.rb', line 38

def create(handle)
  sheet = Sheet.with_file_adapter.new(handle)
  sheet.body = write_to_tempfile(handle)
  sheet.save
end

#edit(handle) ⇒ Object



45
46
47
48
49
# File 'lib/cheatly/cli.rb', line 45

def edit(handle)
  sheet = Sheet.with_file_adapter.find(handle)
  sheet.body = write_to_tempfile(handle, sheet.body)
  sheet.save
end

#helpObject



52
53
54
# File 'lib/cheatly/cli.rb', line 52

def help
  show('help')
end

#listObject



28
29
30
31
32
33
34
35
# File 'lib/cheatly/cli.rb', line 28

def list
  sheets = model.all
  page
  puts "List of available cheat-sheets:"
  sheets.each do |sheet|
    puts "  #{sheet.title}"
  end
end

#show(handle) ⇒ Object



16
17
18
19
20
21
22
23
24
25
# File 'lib/cheatly/cli.rb', line 16

def show(handle)
  sheet = model.find(handle)
  unless sheet
    puts "Sheet not found, run 'cheatly list' to see the availables."
    return
  end
  page
  puts "#{sheet.title}:"
  puts sheet.to_s
end