lib/cl/cmd.rb in cl-1.2.3 vs lib/cl/cmd.rb in cl-1.2.4

- old
+ new

@@ -4,13 +4,10 @@ require 'cl/dsl' require 'cl/opts' require 'cl/parser' class Cl - singleton_class.send(:attr_accessor, :auto_register) # remove unless anyone needs this - singleton_class.instance_variable_set(:@auto_register, true) - # Base class for all command classes that can be run. # # Inherit your command classes from this class, use the {Cl::Cmd::Dsl} to # declare arguments, options, summary, description, examples etc., and # implement the method #run. @@ -21,13 +18,14 @@ extend Dsl class << self include Merge, Suggest, Underscore + attr_accessor :auto_register + inherited = ->(const) do - # return unless Cl.auto_register - if const.name + if const.name && Cmd.auto_register key = underscore(const.name.split('::').last) key = [registry_key, key].compact.join(':') unless abstract? const.register(key) end const.define_singleton_method(:inherited, &inherited) @@ -47,9 +45,11 @@ def suggestions(opt) suggest(opts.map(&:name), opt.sub(/^--/, '')) end end + + self.auto_register = true abstract opt '--help', 'Get help on this command'