1*0b57cec5SDimitry Andric //===-- OptionGroupOutputFile.cpp -----------------------------------------===//
2*0b57cec5SDimitry Andric //
3*0b57cec5SDimitry Andric // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4*0b57cec5SDimitry Andric // See https://llvm.org/LICENSE.txt for license information.
5*0b57cec5SDimitry Andric // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6*0b57cec5SDimitry Andric //
7*0b57cec5SDimitry Andric //===----------------------------------------------------------------------===//
8*0b57cec5SDimitry Andric 
9*0b57cec5SDimitry Andric #include "lldb/Interpreter/OptionGroupOutputFile.h"
10*0b57cec5SDimitry Andric 
11*0b57cec5SDimitry Andric #include "lldb/Host/OptionParser.h"
12*0b57cec5SDimitry Andric 
13*0b57cec5SDimitry Andric using namespace lldb;
14*0b57cec5SDimitry Andric using namespace lldb_private;
15*0b57cec5SDimitry Andric 
OptionGroupOutputFile()16*0b57cec5SDimitry Andric OptionGroupOutputFile::OptionGroupOutputFile() : m_append(false, false) {}
17*0b57cec5SDimitry Andric 
18*0b57cec5SDimitry Andric static const uint32_t SHORT_OPTION_APND = 0x61706e64; // 'apnd'
19*0b57cec5SDimitry Andric 
20*0b57cec5SDimitry Andric static constexpr OptionDefinition g_option_table[] = {
21*0b57cec5SDimitry Andric     {LLDB_OPT_SET_1, false, "outfile", 'o', OptionParser::eRequiredArgument,
22*0b57cec5SDimitry Andric      nullptr, {}, 0, eArgTypeFilename,
23*0b57cec5SDimitry Andric      "Specify a path for capturing command output."},
24*0b57cec5SDimitry Andric     {LLDB_OPT_SET_1, false, "append-outfile", SHORT_OPTION_APND,
25*0b57cec5SDimitry Andric      OptionParser::eNoArgument, nullptr, {}, 0, eArgTypeNone,
26*0b57cec5SDimitry Andric      "Append to the file specified with '--outfile <path>'."},
27*0b57cec5SDimitry Andric };
28*0b57cec5SDimitry Andric 
GetDefinitions()29*0b57cec5SDimitry Andric llvm::ArrayRef<OptionDefinition> OptionGroupOutputFile::GetDefinitions() {
30*0b57cec5SDimitry Andric   return llvm::ArrayRef(g_option_table);
31*0b57cec5SDimitry Andric }
32*0b57cec5SDimitry Andric 
33*0b57cec5SDimitry Andric Status
SetOptionValue(uint32_t option_idx,llvm::StringRef option_arg,ExecutionContext * execution_context)34*0b57cec5SDimitry Andric OptionGroupOutputFile::SetOptionValue(uint32_t option_idx,
35*0b57cec5SDimitry Andric                                       llvm::StringRef option_arg,
36*0b57cec5SDimitry Andric                                       ExecutionContext *execution_context) {
37*0b57cec5SDimitry Andric   Status error;
38*0b57cec5SDimitry Andric   const int short_option = g_option_table[option_idx].short_option;
39*0b57cec5SDimitry Andric 
40*0b57cec5SDimitry Andric   switch (short_option) {
41*0b57cec5SDimitry Andric   case 'o':
42*0b57cec5SDimitry Andric     error = m_file.SetValueFromString(option_arg);
43*0b57cec5SDimitry Andric     break;
44*0b57cec5SDimitry Andric 
45*0b57cec5SDimitry Andric   case SHORT_OPTION_APND:
46*0b57cec5SDimitry Andric     m_append.SetCurrentValue(true);
47*0b57cec5SDimitry Andric     break;
48*0b57cec5SDimitry Andric 
49*0b57cec5SDimitry Andric   default:
50*0b57cec5SDimitry Andric     llvm_unreachable("Unimplemented option");
51*0b57cec5SDimitry Andric   }
52*0b57cec5SDimitry Andric 
53*0b57cec5SDimitry Andric   return error;
54*0b57cec5SDimitry Andric }
55*0b57cec5SDimitry Andric 
OptionParsingStarting(ExecutionContext * execution_context)56*0b57cec5SDimitry Andric void OptionGroupOutputFile::OptionParsingStarting(
57*0b57cec5SDimitry Andric     ExecutionContext *execution_context) {
58*0b57cec5SDimitry Andric   m_file.Clear();
59*0b57cec5SDimitry Andric   m_append.Clear();
60*0b57cec5SDimitry Andric }
61*0b57cec5SDimitry Andric