1cfca06d7SDimitry Andric //===-- OptionGroupOutputFile.cpp -----------------------------------------===//
2f034231aSEd Maste //
35f29bb8aSDimitry Andric // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
45f29bb8aSDimitry Andric // See https://llvm.org/LICENSE.txt for license information.
55f29bb8aSDimitry Andric // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6f034231aSEd Maste //
7f034231aSEd Maste //===----------------------------------------------------------------------===//
8f034231aSEd Maste
9f034231aSEd Maste #include "lldb/Interpreter/OptionGroupOutputFile.h"
10f034231aSEd Maste
1174a628f7SDimitry Andric #include "lldb/Host/OptionParser.h"
12f034231aSEd Maste
13f034231aSEd Maste using namespace lldb;
14f034231aSEd Maste using namespace lldb_private;
15f034231aSEd Maste
OptionGroupOutputFile()16344a3780SDimitry Andric OptionGroupOutputFile::OptionGroupOutputFile() : m_append(false, false) {}
17f034231aSEd Maste
180cac4ca3SEd Maste static const uint32_t SHORT_OPTION_APND = 0x61706e64; // 'apnd'
190cac4ca3SEd Maste
2094994d37SDimitry Andric static constexpr OptionDefinition g_option_table[] = {
2114f1b3e8SDimitry Andric {LLDB_OPT_SET_1, false, "outfile", 'o', OptionParser::eRequiredArgument,
2294994d37SDimitry Andric nullptr, {}, 0, eArgTypeFilename,
2314f1b3e8SDimitry Andric "Specify a path for capturing command output."},
240cac4ca3SEd Maste {LLDB_OPT_SET_1, false, "append-outfile", SHORT_OPTION_APND,
2594994d37SDimitry Andric OptionParser::eNoArgument, nullptr, {}, 0, eArgTypeNone,
265e95aa85SEd Maste "Append to the file specified with '--outfile <path>'."},
27f034231aSEd Maste };
28f034231aSEd Maste
GetDefinitions()2914f1b3e8SDimitry Andric llvm::ArrayRef<OptionDefinition> OptionGroupOutputFile::GetDefinitions() {
30e3b55780SDimitry Andric return llvm::ArrayRef(g_option_table);
31f034231aSEd Maste }
32f034231aSEd Maste
33b76161e4SDimitry Andric Status
SetOptionValue(uint32_t option_idx,llvm::StringRef option_arg,ExecutionContext * execution_context)34b76161e4SDimitry Andric OptionGroupOutputFile::SetOptionValue(uint32_t option_idx,
35b76161e4SDimitry Andric llvm::StringRef option_arg,
3614f1b3e8SDimitry Andric ExecutionContext *execution_context) {
37b76161e4SDimitry Andric Status error;
38f034231aSEd Maste const int short_option = g_option_table[option_idx].short_option;
39f034231aSEd Maste
4014f1b3e8SDimitry Andric switch (short_option) {
41f034231aSEd Maste case 'o':
425e95aa85SEd Maste error = m_file.SetValueFromString(option_arg);
43f034231aSEd Maste break;
44f034231aSEd Maste
450cac4ca3SEd Maste case SHORT_OPTION_APND:
46f034231aSEd Maste m_append.SetCurrentValue(true);
47f034231aSEd Maste break;
48f034231aSEd Maste
49f034231aSEd Maste default:
50ead24645SDimitry Andric llvm_unreachable("Unimplemented option");
51f034231aSEd Maste }
52f034231aSEd Maste
53f034231aSEd Maste return error;
54f034231aSEd Maste }
55f034231aSEd Maste
OptionParsingStarting(ExecutionContext * execution_context)5614f1b3e8SDimitry Andric void OptionGroupOutputFile::OptionParsingStarting(
5714f1b3e8SDimitry Andric ExecutionContext *execution_context) {
58f034231aSEd Maste m_file.Clear();
59f034231aSEd Maste m_append.Clear();
60f034231aSEd Maste }
61