diff options
author | Enrico Granata <egranata@apple.com> | 2016-03-14 22:17:04 +0000 |
---|---|---|
committer | Enrico Granata <egranata@apple.com> | 2016-03-14 22:17:04 +0000 |
commit | bef55ac8f54fc62369af35483ab69f8d0676050d (patch) | |
tree | d24412b18a03908157a952f88e036903cb5db705 /lldb/source/Interpreter/CommandAlias.cpp | |
parent | 2414c5d46be6de849cdba1b048f3e7096cb578f1 (diff) | |
download | bcm5719-llvm-bef55ac8f54fc62369af35483ab69f8d0676050d.tar.gz bcm5719-llvm-bef55ac8f54fc62369af35483ab69f8d0676050d.zip |
Lots of progress on the CommandAlias refactoring
This cleans things up such CommandAlias essentially can work as its own object; the aliases still live in a separate map, but are now just full-fledged CommandObjectSPs
This patch also cleans up help generation for aliases, allows aliases to vend their own help, and adds a tweak such that "dash-dash aliases", such as po, don't show the list of options for their underlying command, since those can't be provided anyway
I plan to fix up a few more things here, and then add a test case and proclaim victory
llvm-svn: 263499
Diffstat (limited to 'lldb/source/Interpreter/CommandAlias.cpp')
-rw-r--r-- | lldb/source/Interpreter/CommandAlias.cpp | 111 |
1 files changed, 110 insertions, 1 deletions
diff --git a/lldb/source/Interpreter/CommandAlias.cpp b/lldb/source/Interpreter/CommandAlias.cpp index ffdb3e92ad5..eba5cb5d17a 100644 --- a/lldb/source/Interpreter/CommandAlias.cpp +++ b/lldb/source/Interpreter/CommandAlias.cpp @@ -85,11 +85,18 @@ CommandAlias::CommandAlias (CommandInterpreter &interpreter, syntax, flags), m_underlying_command_sp(), -m_option_args_sp(new OptionArgVector) +m_option_args_sp(new OptionArgVector), +m_is_dashdash_alias(eLazyBoolCalculate) { if (ProcessAliasOptionsArgs(cmd_sp, options_args, m_option_args_sp)) { m_underlying_command_sp = cmd_sp; + for (int i = 0; + auto cmd_entry = m_underlying_command_sp->GetArgumentEntryAtIndex(i); + i++) + { + m_arguments.push_back(*cmd_entry); + } if (!help || !help[0]) { StreamString sstr; @@ -111,6 +118,64 @@ CommandAlias::WantsRawCommandString() } bool +CommandAlias::WantsCompletion() +{ + if (IsValid()) + return m_underlying_command_sp->WantsCompletion(); + return false; +} + +int +CommandAlias::HandleCompletion (Args &input, + int &cursor_index, + int &cursor_char_position, + int match_start_point, + int max_return_elements, + bool &word_complete, + StringList &matches) +{ + if (IsValid()) + return m_underlying_command_sp->HandleCompletion(input, + cursor_index, + cursor_char_position, + match_start_point, + max_return_elements, + word_complete, + matches); + return -1; +} + +int +CommandAlias::HandleArgumentCompletion (Args &input, + int &cursor_index, + int &cursor_char_position, + OptionElementVector &opt_element_vector, + int match_start_point, + int max_return_elements, + bool &word_complete, + StringList &matches) +{ + if (IsValid()) + return m_underlying_command_sp->HandleArgumentCompletion(input, + cursor_index, + cursor_char_position, + opt_element_vector, + match_start_point, + max_return_elements, + word_complete, + matches); + return -1; +} + +Options* +CommandAlias::GetOptions() +{ + if (IsValid()) + return m_underlying_command_sp->GetOptions(); + return nullptr; +} + +bool CommandAlias::Execute(const char *args_string, CommandReturnObject &result) { llvm_unreachable("CommandAlias::Execute is not to be called"); @@ -149,3 +214,47 @@ CommandAlias::GetAliasExpansion (StreamString &help_string) help_string.Printf ("'"); } + +bool +CommandAlias::IsDashDashCommand () +{ + if (m_is_dashdash_alias == eLazyBoolCalculate) + { + m_is_dashdash_alias = eLazyBoolNo; + if (IsValid()) + { + for (const OptionArgPair& opt_arg : *GetOptionArguments()) + { + if (opt_arg.first == "<argument>" && + opt_arg.second.second == " --") + { + m_is_dashdash_alias = eLazyBoolYes; + break; + } + } + } + } + return (m_is_dashdash_alias == eLazyBoolYes); +} + +// allow CommandAlias objects to provide their own help, but fallback to the info +// for the underlying command if no customization has been provided +const char* +CommandAlias::GetHelp () +{ + if (!m_cmd_help_short.empty()) + return m_cmd_help_short.c_str(); + if (IsValid()) + return m_underlying_command_sp->GetHelp(); + return nullptr; +} + +const char* +CommandAlias::GetHelpLong () +{ + if (!m_cmd_help_long.empty()) + return m_cmd_help_long.c_str(); + if (IsValid()) + return m_underlying_command_sp->GetHelpLong(); + return nullptr; +} |