bin/az in az-1.0.1 vs bin/az in az-2.0.0
- old
+ new
@@ -1,23 +1,26 @@
#!/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>"
@@ -34,10 +37,12 @@
#{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]}
@@ -46,19 +51,33 @@
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
- puts Az.az(data, argv[:to])
+ 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