Sha256: d4832bbc88c542a22fa103f8ca2fc97059902526f4b9c8dbc5e43c228a0951e8

Contents?: true

Size: 1008 Bytes

Versions: 1

Compression:

Stored size: 1008 Bytes

Contents

#!/usr/bin/env ruby

require "rationalist"
require "unibits"

argv = Rationalist.parse(
  ARGV,
  string: '_',
  alias: {
    e: 'encoding',
    c: 'convert',
    v: 'version',
  },
  boolean: [
    'help',
    'version',
    'stats'
  ],
  default: {
    stats: true
  },
)

if argv[:version]
  puts Unibits::VERSION
  exit(0)
end

if argv[:help]
  puts <<-HELP

  #{Paint["USAGE", :underline]}

  #{Paint["unibits", :bold]} [--encoding <encoding>] [--convert <encoding>] [--no-stats] data

  Supported encodings: #{Unibits::SUPPORTED_ENCODINGS.join(', ')}
  Explanation of stats: bytes / codepoints / glyphs / expected terminal width

  More info and examples at: https://github.com/janlelis/unibits

  HELP
  exit(0)
end

if argv[:_] && argv[:_][0]
  data = argv[:_][0]
elsif !$stdin.tty?
  data = $stdin.read
else
  data = nil
end

begin
  Unibits.of(data, encoding: argv[:encoding], convert: argv[:convert], stats: argv[:stats])
rescue ArgumentError
  $stderr.puts Paint[$!.message, :red]
  exit(1)
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
unibits-1.0.0 bin/unibits