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