blob: aa01bf54964f0d92d2c5d853f7142248bf70dff2 [file] [log] [blame]
Greg Clayton57b3c6b2011-04-27 22:04:39 +00001//===-- OptionGroupOutputFile.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
Johnny Chena0f34692011-05-13 20:21:08 +000010#include "lldb/Interpreter/OptionGroupOutputFile.h"
Greg Clayton57b3c6b2011-04-27 22:04:39 +000011
12// C Includes
13// C++ Includes
14// Other libraries and framework includes
15// Project includes
Johnny Chen4003f572011-09-10 00:48:33 +000016#include "lldb/Utility/Utils.h"
Greg Clayton57b3c6b2011-04-27 22:04:39 +000017
18using namespace lldb;
19using namespace lldb_private;
20
21OptionGroupOutputFile::OptionGroupOutputFile() :
22 m_file (),
23 m_append (false, false)
24{
25}
26
27OptionGroupOutputFile::~OptionGroupOutputFile ()
28{
29}
30
31static OptionDefinition
32g_option_table[] =
33{
Sean Callanan9a91ef62012-10-24 01:12:14 +000034 { LLDB_OPT_SET_1 , false, "outfile", 'o', required_argument, NULL, 0, eArgTypeFilename , "Specify a path for capturing command output."},
Greg Clayton6475c422012-12-04 00:32:51 +000035 { LLDB_OPT_SET_1 , false, "append-outfile" , 'apnd', no_argument, NULL, 0, eArgTypeNone , "Append to the the file specified with '--outfile <path>'."},
Greg Clayton57b3c6b2011-04-27 22:04:39 +000036};
37
Greg Clayton57b3c6b2011-04-27 22:04:39 +000038uint32_t
39OptionGroupOutputFile::GetNumDefinitions ()
40{
Johnny Chen08af5982012-05-15 23:21:36 +000041 return llvm::array_lengthof(g_option_table);
Greg Clayton57b3c6b2011-04-27 22:04:39 +000042}
43
44const OptionDefinition *
45OptionGroupOutputFile::GetDefinitions ()
46{
47 return g_option_table;
48}
49
50Error
51OptionGroupOutputFile::SetOptionValue (CommandInterpreter &interpreter,
Greg Clayton6475c422012-12-04 00:32:51 +000052 uint32_t option_idx,
53 const char *option_arg)
Greg Clayton57b3c6b2011-04-27 22:04:39 +000054{
55 Error error;
Greg Clayton6475c422012-12-04 00:32:51 +000056 const int short_option = g_option_table[option_idx].short_option;
Greg Clayton57b3c6b2011-04-27 22:04:39 +000057
58 switch (short_option)
59 {
60 case 'o':
61 error = m_file.SetValueFromCString (option_arg);
62 break;
63
Greg Clayton6475c422012-12-04 00:32:51 +000064 case 'apnd':
Greg Clayton57b3c6b2011-04-27 22:04:39 +000065 m_append.SetCurrentValue(true);
66 break;
67
68 default:
Greg Clayton9c236732011-10-26 00:56:27 +000069 error.SetErrorStringWithFormat ("unrecognized option '%c'", short_option);
Greg Clayton57b3c6b2011-04-27 22:04:39 +000070 break;
71 }
72
73 return error;
74}
75
76void
77OptionGroupOutputFile::OptionParsingStarting (CommandInterpreter &interpreter)
78{
79 m_file.Clear();
80 m_append.Clear();
81}