blob: 253414c43058172d523e8664111308b4a0125a09 [file] [log] [blame]
Chris Lattner24943d22010-06-08 16:52:24 +00001//===-- 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
19using namespace lldb;
20using namespace lldb_private;
21
22//-------------------------------------------------------------------------
23// CommandObjectUnalias
24//-------------------------------------------------------------------------
25
26CommandObjectUnalias::CommandObjectUnalias () :
27 CommandObject ("unalias",
Greg Clayton63094e02010-06-23 01:19:29 +000028 "Allows the user to remove/delete a user-defined command abbreviation.",
29 "unalias <alias-name-to-be-removed>")
Chris Lattner24943d22010-06-08 16:52:24 +000030{
31}
32
33CommandObjectUnalias::~CommandObjectUnalias()
34{
35}
36
37
38bool
Greg Clayton63094e02010-06-23 01:19:29 +000039CommandObjectUnalias::Execute
40(
41 CommandInterpreter &interpreter,
42 Args& args,
43 CommandReturnObject &result
44)
Chris Lattner24943d22010-06-08 16:52:24 +000045{
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 Clayton63094e02010-06-23 01:19:29 +000052 cmd_obj = interpreter.GetCommandObject(command_name);
Chris Lattner24943d22010-06-08 16:52:24 +000053 if (cmd_obj)
54 {
Greg Clayton63094e02010-06-23 01:19:29 +000055 if (interpreter.CommandExists (command_name))
Chris Lattner24943d22010-06-08 16:52:24 +000056 {
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 Clayton63094e02010-06-23 01:19:29 +000064 if (interpreter.RemoveAlias (command_name) == false)
Chris Lattner24943d22010-06-08 16:52:24 +000065 {
Greg Clayton63094e02010-06-23 01:19:29 +000066 if (interpreter.AliasExists (command_name))
Chris Lattner24943d22010-06-08 16:52:24 +000067 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