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



42
43
44
45
46
# File 'lib/cheatly/cli.rb', line 42

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

#edit(handle) ⇒ Object



49
50
51
52
53
# File 'lib/cheatly/cli.rb', line 49

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

#helpObject



56
57
58
# File 'lib/cheatly/cli.rb', line 56

def help
  show('help')
end

#listObject



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

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

#show(handle) ⇒ Object



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

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

#versionObject



61
62
63
# File 'lib/cheatly/cli.rb', line 61

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