Sha256: d238d1a490007d2b15ea1ce4e3617e1d46662f8c30d1c62991a57166055f4146

Contents?: true

Size: 1.52 KB

Versions: 4

Compression:

Stored size: 1.52 KB

Contents

#!/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]} <https://github.com/janlelis/az>"
  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

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
az-2.1.0 bin/az
az-2.0.2 bin/az
az-2.0.1 bin/az
az-2.0.0 bin/az