#!/usr/bin/env ruby # frozen_string_literal: true $LOAD_PATH.unshift(File.expand_path("../lib", __dir__)) require "mdcat" require "tty-markdown" BANNER = %{ _ _ _ __ __| |__ __ _| |_ | ' \/ _` / _/ _` | _| |_|_|_\__,_\__\__,_|\__| version (#{Mdcat::VERSION}) } def help puts %( #{BANNER} USAGE mdcat COMMANDS mdcat -h, help show this help message EXAMPLES `mdcat README.md` for printing to stdout `mdcat README.md | less` for paging long documents ) end # commands if ARGV[0] == "-h" || ARGV[0] == "help" help and exit(0) end # validations file_path = ARGV[0] help and exit(1) if file_path.nil? file = File.expand_path(file_path) unless File.exist?(file) help puts "File not found: #{file}" exit 1 end # proessing file and output puts TTY::Markdown.parse_file(file)