class SlackBigEmoji::CLI
Attributes
options[RW]
Public Class Methods
new(args)
click to toggle source
# File lib/slack_big_emoji/cli.rb, line 7 def initialize(args) @options = parse(args) end
Public Instance Methods
emoji_grid(file_name)
click to toggle source
# File lib/slack_big_emoji/cli.rb, line 55 def emoji_grid(file_name) 25.times do |i| puts "" if i % 5 == 0 && i != 0 print ":#{file_name}#{("%02d" % i)}:" end puts # madrs end
log(*msg)
click to toggle source
# File lib/slack_big_emoji/cli.rb, line 63 def log(*msg) unless @options[:silent] if msg.size == 1 puts msg else printf "%-20s %s\n", msg.first, msg.last end end end
parse(args)
click to toggle source
# File lib/slack_big_emoji/cli.rb, line 11 def parse(args) options = {} opts = OptionParser.new do |opts| opts.banner = "Usage: slack-big-emoji [options] FILE" opts.version = SlackBigEmoji::VERSION opts.on( '-f', '--file-name=NAME', 'Output filename.' ) do |val| options[:output_filename] = val end opts.on( '-o', '--output-dir=NAME', 'Output directory.' ) do |val| options[:output_dir] = val end options[:silent] = false opts.on( '-s', '--silent', 'Silent or quiet mode.' ) do options[:silent] = true end options[:convert_only] = false opts.on( '-c', '--convert-only', 'Convert image but do not upload.' ) do options[:convert_only] = true end opts.on_tail( '-h', '--help', 'Show this message' ) do puts opts exit end end opts.parse! # removes switches destructively, but not non-options file = args.first # ARGV args only - no options # validates input to be one image file, no gif support (yet) abort "Error: Missing input file" unless file abort "Just specify one file" if args.count > 1 abort "Use a valid image file (png, jpeg or jpg)" if (file =~ /.\.(png|jpeg|jpg)$/).nil? options[:file] = file options end