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(), m_append(false, false) {}
22 
23 OptionGroupOutputFile::~OptionGroupOutputFile() {}
24 
25 static const uint32_t SHORT_OPTION_APND = 0x61706e64; // 'apnd'
26 
27 static OptionDefinition g_option_table[] = {
28     {LLDB_OPT_SET_1, false, "outfile", 'o', OptionParser::eRequiredArgument,
29      nullptr, nullptr, 0, eArgTypeFilename,
30      "Specify a path for capturing command output."},
31     {LLDB_OPT_SET_1, false, "append-outfile", SHORT_OPTION_APND,
32      OptionParser::eNoArgument, nullptr, nullptr, 0, eArgTypeNone,
33      "Append to the file specified with '--outfile <path>'."},
34 };
35 
36 llvm::ArrayRef<OptionDefinition> OptionGroupOutputFile::GetDefinitions() {
37   return llvm::makeArrayRef(g_option_table);
38 }
39 
40 Error OptionGroupOutputFile::SetOptionValue(
41     uint32_t option_idx, llvm::StringRef option_arg,
42     ExecutionContext *execution_context) {
43   Error error;
44   const int short_option = g_option_table[option_idx].short_option;
45 
46   switch (short_option) {
47   case 'o':
48     error = m_file.SetValueFromString(option_arg);
49     break;
50 
51   case SHORT_OPTION_APND:
52     m_append.SetCurrentValue(true);
53     break;
54 
55   default:
56     error.SetErrorStringWithFormat("unrecognized option '%c'", short_option);
57     break;
58   }
59 
60   return error;
61 }
62 
63 void OptionGroupOutputFile::OptionParsingStarting(
64     ExecutionContext *execution_context) {
65   m_file.Clear();
66   m_append.Clear();
67 }
68