/////////////////////////////////////////////////////////////////////////// Categorize FILTER, MODIFICATION and MISCELLANEOUS args, based on CMD DNA.
| 825 | //////////////////////////////////////////////////////////////////////////////// |
| 826 | // Categorize FILTER, MODIFICATION and MISCELLANEOUS args, based on CMD DNA. |
| 827 | void CLI2::categorizeArgs() { |
| 828 | // Context is only applied for commands that request it. |
| 829 | std::string command = getCommand(); |
| 830 | Command* cmd = Context::getContext().commands[command]; |
| 831 | |
| 832 | // Determine if the command uses Context. CmdCustom and CmdTimesheet need to |
| 833 | // be handled separately, as they override the parent Command::use_context |
| 834 | // method, and this is a pointer to Command class. |
| 835 | // |
| 836 | // All Command classes overriding uses_context () getter need to be specified |
| 837 | // here. |
| 838 | bool uses_context; |
| 839 | if (dynamic_cast<CmdCustom*>(cmd)) |
| 840 | uses_context = (dynamic_cast<CmdCustom*>(cmd))->uses_context(); |
| 841 | else if (dynamic_cast<CmdTimesheet*>(cmd)) |
| 842 | uses_context = (dynamic_cast<CmdTimesheet*>(cmd))->uses_context(); |
| 843 | else if (cmd) |
| 844 | uses_context = cmd->uses_context(); |
| 845 | |
| 846 | // Apply the context, if applicable |
| 847 | if (cmd && uses_context) addContext(cmd->accepts_filter(), cmd->accepts_modifications()); |
| 848 | |
| 849 | bool changes = false; |
| 850 | bool afterCommand = false; |
| 851 | for (auto& a : _args) { |
| 852 | if (a._lextype == Lexer::Type::separator) continue; |
| 853 | |
| 854 | // Record that the command has been found, it affects behavior. |
| 855 | if (a.hasTag("CMD")) { |
| 856 | afterCommand = true; |
| 857 | } |
| 858 | |
| 859 | // Skip admin args. |
| 860 | else if (a.hasTag("BINARY") || a.hasTag("RC") || a.hasTag("CONFIG")) { |
| 861 | // NOP. |
| 862 | } |
| 863 | |
| 864 | // All combinations, with all 8 cases handled below.: |
| 865 | // |
| 866 | // -- -- -- Error: found an arg, but none expected |
| 867 | // -- -- Mi task [Mi] <cmd> [Mi] |
| 868 | // -- Mo -- task [Mo] <cmd> [Mo] |
| 869 | // -- Mo Mi Internally inconsistent |
| 870 | // Fi -- -- task [Fi] <cmd> [Fi] |
| 871 | // Fi -- Mi task [Fi] <cmd> [Mi] |
| 872 | // Fi Mo -- task [Fi] <cmd> [Mo] |
| 873 | // Fi Mo Mi Internally inconsistent |
| 874 | // |
| 875 | else if (cmd && !cmd->accepts_filter() && !cmd->accepts_modifications() && |
| 876 | !cmd->accepts_miscellaneous()) { |
| 877 | // No commands were expected --> error. |
| 878 | throw format("The '{1}' command does not allow '{2}'.", command, a.attribute("raw")); |
| 879 | } else if (cmd && !cmd->accepts_filter() && !cmd->accepts_modifications() && |
| 880 | cmd->accepts_miscellaneous()) { |
| 881 | a.tag("MISCELLANEOUS"); |
| 882 | changes = true; |
| 883 | } else if (cmd && !cmd->accepts_filter() && cmd->accepts_modifications() && |
| 884 | !cmd->accepts_miscellaneous()) { |
nothing calls this directly
no test coverage detected