15ffd83dbSDimitry Andric //===-- OptionGroupOutputFile.cpp -----------------------------------------===//
20b57cec5SDimitry Andric //
30b57cec5SDimitry Andric // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
40b57cec5SDimitry Andric // See https://llvm.org/LICENSE.txt for license information.
50b57cec5SDimitry Andric // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
60b57cec5SDimitry Andric //
70b57cec5SDimitry Andric //===----------------------------------------------------------------------===//
80b57cec5SDimitry Andric
90b57cec5SDimitry Andric #include "lldb/Interpreter/OptionGroupOutputFile.h"
100b57cec5SDimitry Andric
110b57cec5SDimitry Andric #include "lldb/Host/OptionParser.h"
120b57cec5SDimitry Andric
130b57cec5SDimitry Andric using namespace lldb;
140b57cec5SDimitry Andric using namespace lldb_private;
150b57cec5SDimitry Andric
OptionGroupOutputFile()16*5f7ddb14SDimitry Andric OptionGroupOutputFile::OptionGroupOutputFile() : m_append(false, false) {}
170b57cec5SDimitry Andric
180b57cec5SDimitry Andric static const uint32_t SHORT_OPTION_APND = 0x61706e64; // 'apnd'
190b57cec5SDimitry Andric
200b57cec5SDimitry Andric static constexpr OptionDefinition g_option_table[] = {
210b57cec5SDimitry Andric {LLDB_OPT_SET_1, false, "outfile", 'o', OptionParser::eRequiredArgument,
220b57cec5SDimitry Andric nullptr, {}, 0, eArgTypeFilename,
230b57cec5SDimitry Andric "Specify a path for capturing command output."},
240b57cec5SDimitry Andric {LLDB_OPT_SET_1, false, "append-outfile", SHORT_OPTION_APND,
250b57cec5SDimitry Andric OptionParser::eNoArgument, nullptr, {}, 0, eArgTypeNone,
260b57cec5SDimitry Andric "Append to the file specified with '--outfile <path>'."},
270b57cec5SDimitry Andric };
280b57cec5SDimitry Andric
GetDefinitions()290b57cec5SDimitry Andric llvm::ArrayRef<OptionDefinition> OptionGroupOutputFile::GetDefinitions() {
300b57cec5SDimitry Andric return llvm::makeArrayRef(g_option_table);
310b57cec5SDimitry Andric }
320b57cec5SDimitry Andric
330b57cec5SDimitry Andric Status
SetOptionValue(uint32_t option_idx,llvm::StringRef option_arg,ExecutionContext * execution_context)340b57cec5SDimitry Andric OptionGroupOutputFile::SetOptionValue(uint32_t option_idx,
350b57cec5SDimitry Andric llvm::StringRef option_arg,
360b57cec5SDimitry Andric ExecutionContext *execution_context) {
370b57cec5SDimitry Andric Status error;
380b57cec5SDimitry Andric const int short_option = g_option_table[option_idx].short_option;
390b57cec5SDimitry Andric
400b57cec5SDimitry Andric switch (short_option) {
410b57cec5SDimitry Andric case 'o':
420b57cec5SDimitry Andric error = m_file.SetValueFromString(option_arg);
430b57cec5SDimitry Andric break;
440b57cec5SDimitry Andric
450b57cec5SDimitry Andric case SHORT_OPTION_APND:
460b57cec5SDimitry Andric m_append.SetCurrentValue(true);
470b57cec5SDimitry Andric break;
480b57cec5SDimitry Andric
490b57cec5SDimitry Andric default:
509dba64beSDimitry Andric llvm_unreachable("Unimplemented option");
510b57cec5SDimitry Andric }
520b57cec5SDimitry Andric
530b57cec5SDimitry Andric return error;
540b57cec5SDimitry Andric }
550b57cec5SDimitry Andric
OptionParsingStarting(ExecutionContext * execution_context)560b57cec5SDimitry Andric void OptionGroupOutputFile::OptionParsingStarting(
570b57cec5SDimitry Andric ExecutionContext *execution_context) {
580b57cec5SDimitry Andric m_file.Clear();
590b57cec5SDimitry Andric m_append.Clear();
600b57cec5SDimitry Andric }
61