Sha256: f2a085cb8d9befc9d8b55ea74d66256e9aceffd9e0ff9cbb22768cc117dd5b30
Contents?: true
Size: 1.06 KB
Versions: 1
Compression:
Stored size: 1.06 KB
Contents
require 'clamp/subcommand' module Clamp class Subcommand module Declaration def recognised_subcommands @recognised_subcommands ||= [] end def subcommand(name, description, subcommand_class = self, &block) 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 attr_writer :default_subcommand def default_subcommand(*args, &block) if args.empty? @default_subcommand else $stderr.puts "WARNING: Clamp default_subcommand syntax has changed; check the README." $stderr.puts " (from #{caller.first})" subcommand(*args, &block) self.default_subcommand = args.first end end end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
clamp-0.3.0 | lib/clamp/subcommand/declaration.rb |