#!/usr/bin/env ruby # frozen_string_literal: true require "rationalist" require "paint" require "clipboard" require "az" argv = Rationalist.parse( ARGV, string: '_', alias: { t: 'to', v: 'version', c: 'copy', }, boolean: [ 'fonts', 'help', 'version', 'copy' ] ) if argv[:version] puts "az #{Az::VERSION} by #{Paint["J-_-L", :bold]} " puts "Unicode version is #{Az::UNICODE_VERSION}" exit(0) end if argv[:help] puts <<-HELP #{Paint["DESCRIPTION", :underline]} Translates Latin ASCII characters to funky Unicode ones. #{Paint["USAGE", :underline]} #{Paint["az", :bold]} data --to font --to | -t | specify font to use (required) --copy | -c | copy to clipboard instead of displaying on stdout --fonts | | displays list of fonts --help | | this help page --version | -v | displays version of az #{Paint["MORE INFO", :underline]} https://github.com/janlelis/az HELP exit(0) end if argv[:fonts] puts Az.fonts.join(" ") exit(0) end if argv[:_] && argv[:_][0] data = argv[:_][0] elsif !$stdin.tty? data = $stdin.read else data = nil end begin res = Az.az( data, (argv[:to] or raise ArgumentError, "must specify font via --to option"), ) if argv[:copy] Clipboard.copy(res) puts "Converted string has been copied to the clipboard" else puts res end rescue ArgumentError $stderr.puts Paint[$!.message, :red] exit(1) end