Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame^] | 1 | //===-- CommandObjectUnalias.cpp --------------------------------*- C++ -*-===// |
| 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
| 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
| 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | |
| 10 | #include "CommandObjectUnalias.h" |
| 11 | |
| 12 | // C Includes |
| 13 | // C++ Includes |
| 14 | // Other libraries and framework includes |
| 15 | // Project includes |
| 16 | #include "lldb/Interpreter/CommandInterpreter.h" |
| 17 | #include "lldb/Interpreter/CommandReturnObject.h" |
| 18 | |
| 19 | using namespace lldb; |
| 20 | using namespace lldb_private; |
| 21 | |
| 22 | //------------------------------------------------------------------------- |
| 23 | // CommandObjectUnalias |
| 24 | //------------------------------------------------------------------------- |
| 25 | |
| 26 | CommandObjectUnalias::CommandObjectUnalias () : |
| 27 | CommandObject ("unalias", |
| 28 | "Allows the user to remove/delete a user-defined command abbreviation.", |
| 29 | "unalias <alias-name-to-be-removed>") |
| 30 | { |
| 31 | } |
| 32 | |
| 33 | CommandObjectUnalias::~CommandObjectUnalias() |
| 34 | { |
| 35 | } |
| 36 | |
| 37 | |
| 38 | bool |
| 39 | CommandObjectUnalias::Execute (Args& args, CommandContext *context, CommandInterpreter *interpreter, |
| 40 | CommandReturnObject &result) |
| 41 | { |
| 42 | CommandObject::CommandMap::iterator pos; |
| 43 | CommandObject *cmd_obj; |
| 44 | |
| 45 | if (args.GetArgumentCount() != 0) |
| 46 | { |
| 47 | const char *command_name = args.GetArgumentAtIndex(0); |
| 48 | cmd_obj = interpreter->GetCommandObject(command_name); |
| 49 | if (cmd_obj) |
| 50 | { |
| 51 | if (interpreter->CommandExists (command_name)) |
| 52 | { |
| 53 | result.AppendErrorWithFormat ("'%s' is a permanent debugger command and cannot be removed.\n", |
| 54 | command_name); |
| 55 | result.SetStatus (eReturnStatusFailed); |
| 56 | } |
| 57 | else |
| 58 | { |
| 59 | |
| 60 | if (interpreter->RemoveAlias (command_name) == false) |
| 61 | { |
| 62 | if (interpreter->AliasExists (command_name)) |
| 63 | result.AppendErrorWithFormat ("Error occurred while attempting to unalias '%s'.\n", command_name); |
| 64 | else |
| 65 | result.AppendErrorWithFormat ("'%s' is not an existing alias.\n", command_name); |
| 66 | result.SetStatus (eReturnStatusFailed); |
| 67 | } |
| 68 | else |
| 69 | result.SetStatus (eReturnStatusSuccessFinishNoResult); |
| 70 | } |
| 71 | } |
| 72 | else |
| 73 | { |
| 74 | result.AppendErrorWithFormat ("'%s' is not a known command.\nTry 'help' to see a current list of commands.\n", |
| 75 | command_name); |
| 76 | result.SetStatus (eReturnStatusFailed); |
| 77 | } |
| 78 | } |
| 79 | else |
| 80 | { |
| 81 | result.AppendError ("must call 'unalias' with a valid alias"); |
| 82 | result.SetStatus (eReturnStatusFailed); |
| 83 | } |
| 84 | |
| 85 | return result.Succeeded(); |
| 86 | } |
| 87 | |