From 8cad6487c794ca1309a3c89f6746b3627fb0ae8d Mon Sep 17 00:00:00 2001 From: Tomas Babej Date: Sat, 21 Aug 2021 00:15:03 -0400 Subject: [PATCH] CLI2: Call uses_context from child classes, if applicable --- src/CLI2.cpp | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/src/CLI2.cpp b/src/CLI2.cpp index 5d9ce3666..2240d026e 100644 --- a/src/CLI2.cpp +++ b/src/CLI2.cpp @@ -34,6 +34,8 @@ #include #include #include +#include +#include // Overridden by rc.abbreviation.minimum. int CLI2::minimumMatchLength = 3; @@ -945,7 +947,23 @@ void CLI2::categorizeArgs () // Context is only applied for commands that request it. std::string command = getCommand (); Command* cmd = Context::getContext ().commands[command]; - if (cmd && cmd->uses_context ()) + + // Determine if the command uses Context. CmdCustom and CmdTimesheet need to + // be handled separately, as they override the parent Command::use_context + // method, and this is a pointer to Command class. + // + // All Command classes overriding uses_context () getter need to be specified + // here. + bool uses_context; + if (dynamic_cast (cmd)) + uses_context = (dynamic_cast (cmd))->uses_context (); + else if (dynamic_cast (cmd)) + uses_context = (dynamic_cast (cmd))->uses_context (); + else if (cmd) + uses_context = cmd->uses_context (); + + // Apply the context, if applicable + if (cmd && uses_context) addContext (cmd->accepts_filter (), cmd->accepts_modifications ()); bool changes = false;