# # # patch "cmd.hh" # from [7af603b7cdc6ae26cc06d89671c8cd9bf9d04b75] # to [99e998330fea396e9b24b2dc56610a07a463b606] # # patch "commands.cc" # from [a8252add69f2ed2ed88512fb21e23939deb45b46] # to [b5854467b0d421f6e9eb36c6618d94e6dcd31025] # ============================================================ --- cmd.hh 7af603b7cdc6ae26cc06d89671c8cd9bf9d04b75 +++ cmd.hh 99e998330fea396e9b24b2dc56610a07a463b606 @@ -79,8 +79,11 @@ namespace commands virtual std::string abstract(void) const; virtual std::string desc(void) const; virtual names_set subcommands(bool hidden) const; + options::options_type const & opts(void) const; bool use_workspace_options(void) const; + void preset_options(options & opts) const; + children_set & children(void); children_set const & children(void) const; bool is_leaf(void) const; @@ -100,6 +103,14 @@ namespace commands bool completion_ok = true) const; }; + class cmdpreset + { + public: + void register_for(command const * cmd); + virtual void preset(options const & opts) const = 0; + virtual ~cmdpreset(); + }; + class automate : public command { bool stdio_ok; @@ -174,6 +185,19 @@ namespace commands { \ #define CMD_REF(C) ((commands::command *)&(commands::C ## _cmd)) +#define CMD_PRESET_OPTIONS(C) \ + CMD_FWD_DECL(C) \ + namespace commands{ \ + class cmdpreset_ ## C : public cmdpreset \ + { \ + public: \ + cmdpreset_ ## C () { register_for(CMD_REF(C)); } \ + virtual void preset(options & opts) const; \ + }; \ + } \ + void commands::cmdpreset_ ## C ::preset(options & opts) const + + #define _CMD2(C, name, aliases, parent, hidden, params, abstract, desc, opts) \ namespace commands { \ class cmd_ ## C : public command \ ============================================================ --- commands.cc a8252add69f2ed2ed88512fb21e23939deb45b46 +++ commands.cc b5854467b0d421f6e9eb36c6618d94e6dcd31025 @@ -13,6 +13,7 @@ using std::map; #include "simplestring_xform.hh" using std::map; +using std::make_pair; using std::set; using std::string; using std::vector; @@ -57,6 +58,17 @@ namespace commands } } + typedef std::map presetter_map_t; + presetter_map_t * presetter_map = 0; + cmdpreset::~cmdpreset() { } + void cmdpreset::register_for(command const * cmd) + { + if (!presetter_map) + presetter_map = new presetter_map_t; + + presetter_map->insert(make_pair(cmd, this)); + } + // // Implementation of the commands::command class. // @@ -210,6 +222,15 @@ namespace commands return m_use_workspace_options; } + void + command::preset_options(options & opts) const + { + I(presetter_map); + presetter_map_t::const_iterator i = presetter_map->find(this); + if (i != presetter_map->end()) + i->second->preset(opts); + } + command::children_set & command::children(void) {