lib/cri/command_dsl.rb in cri-2.7.0 vs lib/cri/command_dsl.rb in cri-2.7.1

- old
+ new

@@ -1,7 +1,5 @@ -# encoding: utf-8 - module Cri # The command DSL is a class that is used for building and modifying # commands. class CommandDSL # @return [Cri::Command] The built command @@ -46,11 +44,11 @@ # # @param [String, Symbol, Array] args The new command aliases # # @return [void] def aliases(*args) - @command.aliases = args.flatten.map { |a| a.to_s } + @command.aliases = args.flatten.map(&:to_s) end # Sets the command summary. # # @param [String] arg The new command summary @@ -112,24 +110,24 @@ requiredness = params.fetch(:argument, :forbidden) multiple = params.fetch(:multiple, false) hidden = params.fetch(:hidden, false) if short.nil? && long.nil? - fail ArgumentError, 'short and long options cannot both be nil' + raise ArgumentError, 'short and long options cannot both be nil' end @command.option_definitions << { - :short => short.nil? ? nil : short.to_s, - :long => long.nil? ? nil : long.to_s, - :desc => desc, - :argument => requiredness, - :multiple => multiple, - :block => block, - :hidden => hidden, + short: short.nil? ? nil : short.to_s, + long: long.nil? ? nil : long.to_s, + desc: desc, + argument: requiredness, + multiple: multiple, + block: block, + hidden: hidden, } end - alias_method :opt, :option + alias opt option # Adds a new option with a required argument to the command. If a block is # given, it will be executed when the option is successfully parsed. # # @param [String, Symbol, nil] short The short option name @@ -146,11 +144,11 @@ # # @return [void] # # @see {#option} def required(short, long, desc, params = {}, &block) - params = params.merge(:argument => :required) + params = params.merge(argument: :required) option(short, long, desc, params, &block) end # Adds a new option with a forbidden argument to the command. If a block # is given, it will be executed when the option is successfully parsed. @@ -169,14 +167,14 @@ # # @return [void] # # @see {#option} def flag(short, long, desc, params = {}, &block) - params = params.merge(:argument => :forbidden) + params = params.merge(argument: :forbidden) option(short, long, desc, params, &block) end - alias_method :forbidden, :flag + alias forbidden flag # Adds a new option with an optional argument to the command. If a block # is given, it will be executed when the option is successfully parsed. # # @param [String, Symbol, nil] short The short option name @@ -193,11 +191,11 @@ # # @return [void] # # @see {#option} def optional(short, long, desc, params = {}, &block) - params = params.merge(:argument => :optional) + params = params.merge(argument: :optional) option(short, long, desc, params, &block) end # Sets the run block to the given block. The given block should have two # or three arguments (options, arguments, and optionally the command). @@ -211,11 +209,11 @@ # @yieldparam [Array<String>] args A list of arguments # # @return [void] def run(&block) unless [2, 3].include?(block.arity) - fail ArgumentError, - 'The block given to Cri::Command#run expects two or three args' + raise ArgumentError, + 'The block given to Cri::Command#run expects two or three args' end @command.block = block end