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



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

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

#edit(handle) ⇒ Object



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

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

#helpObject



58
59
60
# File 'lib/cheatly/cli.rb', line 58

def help
  show('help')
end

#listObject



34
35
36
37
38
39
40
41
# File 'lib/cheatly/cli.rb', line 34

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

#show(handle) ⇒ Object



21
22
23
24
25
26
27
28
29
30
31
# File 'lib/cheatly/cli.rb', line 21

def show(handle)
  sheet = model.find(handle)
  unless sheet
    puts "Sheet not found, run 'cheatly list' to see the availables."
    return
  end
  page unless options[:nopaginate]
  renderer = Renderer.new
  md = Redcarpet::Markdown.new(renderer, no_intra_emphasis: true)
  puts md.render(sheet.to_s)
end

#versionObject



63
64
65
# File 'lib/cheatly/cli.rb', line 63

def version
  puts "Cheatly version #{Cheatly::VERSION}"
end