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", |
Greg Clayton | 63094e0 | 2010-06-23 01:19:29 +0000 | [diff] [blame] | 28 | "Allows the user to remove/delete a user-defined command abbreviation.", |
| 29 | "unalias <alias-name-to-be-removed>") |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 30 | { |
| 31 | } |
| 32 | |
| 33 | CommandObjectUnalias::~CommandObjectUnalias() |
| 34 | { |
| 35 | } |
| 36 | |
| 37 | |
| 38 | bool |
Greg Clayton | 63094e0 | 2010-06-23 01:19:29 +0000 | [diff] [blame] | 39 | CommandObjectUnalias::Execute |
| 40 | ( |
| 41 | CommandInterpreter &interpreter, |
| 42 | Args& args, |
| 43 | CommandReturnObject &result |
| 44 | ) |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 45 | { |
| 46 | CommandObject::CommandMap::iterator pos; |
| 47 | CommandObject *cmd_obj; |
| 48 | |
| 49 | if (args.GetArgumentCount() != 0) |
| 50 | { |
| 51 | const char *command_name = args.GetArgumentAtIndex(0); |
Greg Clayton | 63094e0 | 2010-06-23 01:19:29 +0000 | [diff] [blame] | 52 | cmd_obj = interpreter.GetCommandObject(command_name); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 53 | if (cmd_obj) |
| 54 | { |
Greg Clayton | 63094e0 | 2010-06-23 01:19:29 +0000 | [diff] [blame] | 55 | if (interpreter.CommandExists (command_name)) |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 56 | { |
| 57 | result.AppendErrorWithFormat ("'%s' is a permanent debugger command and cannot be removed.\n", |
| 58 | command_name); |
| 59 | result.SetStatus (eReturnStatusFailed); |
| 60 | } |
| 61 | else |
| 62 | { |
| 63 | |
Greg Clayton | 63094e0 | 2010-06-23 01:19:29 +0000 | [diff] [blame] | 64 | if (interpreter.RemoveAlias (command_name) == false) |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 65 | { |
Greg Clayton | 63094e0 | 2010-06-23 01:19:29 +0000 | [diff] [blame] | 66 | if (interpreter.AliasExists (command_name)) |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 67 | result.AppendErrorWithFormat ("Error occurred while attempting to unalias '%s'.\n", command_name); |
| 68 | else |
| 69 | result.AppendErrorWithFormat ("'%s' is not an existing alias.\n", command_name); |
| 70 | result.SetStatus (eReturnStatusFailed); |
| 71 | } |
| 72 | else |
| 73 | result.SetStatus (eReturnStatusSuccessFinishNoResult); |
| 74 | } |
| 75 | } |
| 76 | else |
| 77 | { |
| 78 | result.AppendErrorWithFormat ("'%s' is not a known command.\nTry 'help' to see a current list of commands.\n", |
| 79 | command_name); |
| 80 | result.SetStatus (eReturnStatusFailed); |
| 81 | } |
| 82 | } |
| 83 | else |
| 84 | { |
| 85 | result.AppendError ("must call 'unalias' with a valid alias"); |
| 86 | result.SetStatus (eReturnStatusFailed); |
| 87 | } |
| 88 | |
| 89 | return result.Succeeded(); |
| 90 | } |
| 91 | |