Sha256: 881a802f4592ebac22c5446a27c353d82c8033b1b23c3940db3ec1a7014dcb58
Contents?: true
Size: 1014 Bytes
Versions: 6
Compression:
Stored size: 1014 Bytes
Contents
require 'clamp/subcommand' module Clamp class Subcommand module Declaration def recognised_subcommands @recognised_subcommands ||= [] end def subcommand(name, description, subcommand_class = self, &block) has_subcommands! if block # generate a anonymous sub-class subcommand_class = Class.new(subcommand_class, &block) end recognised_subcommands << Subcommand.new(name, description, subcommand_class) end def has_subcommands? !recognised_subcommands.empty? end def find_subcommand(name) recognised_subcommands.find { |sc| sc.is_called?(name) } end def has_subcommands! unless @has_subcommands parameter "SUBCOMMAND", "subcommand name", :attribute_name => :subcommand_name parameter "[ARGS] ...", "subcommand arguments", :attribute_name => :subcommand_arguments @has_subcommands = true end end end end end
Version data entries
6 entries across 6 versions & 1 rubygems