Sha256: f082fa44d869214091543072796690a5dad0b9b05329872c85923132dea67ce5

Contents?: true

Size: 713 Bytes

Versions: 2

Compression:

Stored size: 713 Bytes

Contents

module I18n::Tasks::SlopCommand
  extend self

  def slop_command(name, attr, &block)
    proc {
      command name.tr('_', '-') do
        opts = attr[:opt]
        args = attr[:args]
        banner "Usage: i18n-tasks #{name} [options] #{args}" if args.present?
        desc = attr[:desc]
        description desc if desc
        if opts
          opts.each do |opt|
            on *[:short, :long, :desc, :conf].map { |k| opt[k] }.compact
          end
        end
        run { |opts, args| block.call(name, opts, args) }
      end
    }
  end

  def parse_slop_opts_args(opts, args)
    opts = opts.to_hash(true).reject { |k, v| v.nil? }
    opts.merge!(arguments: args) unless args.empty?
    opts
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
i18n-tasks-0.7.1 lib/i18n/tasks/slop_command.rb
i18n-tasks-0.7.0 lib/i18n/tasks/slop_command.rb