<commit_before>require "pager"
require "optparse"
require "redcarpet"
require "thor"

require "cheatly/version"
require "cheatly/sheet"
require "cheatly/adapter/file"
require "cheatly/adapter/github"
require "cheatly/renderer"

module Cheatly
  class CLI < Thor
    include Pager

    class_option :local, type: :boolean, aliases: "-l", desc: "Run using local file system"

    desc "show SHEET_NAME", "show a cheat sheet"
    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

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

    desc "create SHEET_NAME", "create a new sheet cheat"
    def create(handle)
      sheet = Sheet.with_file_adapter.new(handle)
      sheet.body = write_to_tempfile(handle)
      sheet.save
    end

    desc "edit SHEET_NAME", "edit an existent sheet cheat"
    def edit(handle)
      sheet = Sheet.with_file_adapter.find(handle)
      sheet.body = write_to_tempfile(handle, sheet.body)
      sheet.save
    end

    desc "help", "help"
    def help
      show('help')
    end

    private

      def model
        if options[:local]
          Sheet.with_file_adapter
        else
          Sheet
        end
      end

      def write_to_tempfile(title, body = nil)
        tempfile = Tempfile.new(title + '.yml')
        tempfile.write(body) if body
        tempfile.close
        system "#{editor} #{tempfile.path}"
        tempfile.open
        body = tempfile.read
        tempfile.close
        body
      end

      def editor
        ENV['VISUAL'] || ENV['EDITOR'] || "nano"
      end
  end
end
<commit_msg>add version command<commit_after>require "pager"
require "optparse"
require "redcarpet"
require "thor"

require "cheatly/version"
require "cheatly/sheet"
require "cheatly/adapter/file"
require "cheatly/adapter/github"
require "cheatly/renderer"

module Cheatly
  class CLI < Thor
    include Pager

    class_option :local, type: :boolean, aliases: "-l", desc: "Run using local file system"

    desc "show SHEET_NAME", "show a cheat sheet"
    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

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

    desc "create SHEET_NAME", "create a new sheet cheat"
    def create(handle)
      sheet = Sheet.with_file_adapter.new(handle)
      sheet.body = write_to_tempfile(handle)
      sheet.save
    end

    desc "edit SHEET_NAME", "edit an existent sheet cheat"
    def edit(handle)
      sheet = Sheet.with_file_adapter.find(handle)
      sheet.body = write_to_tempfile(handle, sheet.body)
      sheet.save
    end

    desc "help", "help"
    def help
      show('help')
    end

    desc "version", "Prints cheatly's version"
    def version
      puts "Cheatly version #{Cheatly::VERSION}"
    end
    map %w(-v --version) => :version

    private

      def model
        if options[:local]
          Sheet.with_file_adapter
        else
          Sheet
        end
      end

      def write_to_tempfile(title, body = nil)
        tempfile = Tempfile.new(title + '.yml')
        tempfile.write(body) if body
        tempfile.close
        system "#{editor} #{tempfile.path}"
        tempfile.open
        body = tempfile.read
        tempfile.close
        body
      end

      def editor
        ENV['VISUAL'] || ENV['EDITOR'] || "nano"
      end
  end
end

{'fraction_non_alphanumeric': 0.0945489628557646, 'fraction_numerical': 0.0, 'mean_word_length': 2.296502384737679, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 4, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6156234', 'n_tokens_mistral': 1339, 'n_tokens_neox': 1284, 'n_words': 368}