1 //===-- 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 
10 #include "lldb/Interpreter/OptionGroupOutputFile.h"
11 
12 // C Includes
13 // C++ Includes
14 // Other libraries and framework includes
15 // Project includes
16 
17 using namespace lldb;
18 using namespace lldb_private;
19 
20 OptionGroupOutputFile::OptionGroupOutputFile() :
21     m_file (),
22     m_append (false, false)
23 {
24 }
25 
26 OptionGroupOutputFile::~OptionGroupOutputFile ()
27 {
28 }
29 
30 static OptionDefinition
31 g_option_table[] =
32 {
33 { LLDB_OPT_SET_1 , false, "outfile", 'o', required_argument, NULL, 0, eArgTypePath , "Specify a path for capturing command output."},
34 { LLDB_OPT_SET_1 , false, "append-outfile" , 'A', no_argument, NULL, 0, eArgTypeNone , "Append to the the file specified with '--outfile <path>'."},
35 };
36 
37 const uint32_t k_num_file_options = sizeof(g_option_table)/sizeof(OptionDefinition);
38 
39 uint32_t
40 OptionGroupOutputFile::GetNumDefinitions ()
41 {
42     return k_num_file_options;
43 }
44 
45 const OptionDefinition *
46 OptionGroupOutputFile::GetDefinitions ()
47 {
48     return g_option_table;
49 }
50 
51 Error
52 OptionGroupOutputFile::SetOptionValue (CommandInterpreter &interpreter,
53                                          uint32_t option_idx,
54                                          const char *option_arg)
55 {
56     Error error;
57     char short_option = (char) g_option_table[option_idx].short_option;
58 
59     switch (short_option)
60     {
61         case 'o':
62             error = m_file.SetValueFromCString (option_arg);
63             break;
64 
65         case 'A':
66             m_append.SetCurrentValue(true);
67             break;
68 
69         default:
70             error.SetErrorStringWithFormat ("Unrecognized option '%c'.\n", short_option);
71             break;
72     }
73 
74     return error;
75 }
76 
77 void
78 OptionGroupOutputFile::OptionParsingStarting (CommandInterpreter &interpreter)
79 {
80     m_file.Clear();
81     m_append.Clear();
82 }
83