1 //===-- OptionGroupOutputFile.cpp -------------------------------*- C++ -*-===//
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
7 //===----------------------------------------------------------------------===//
9 #include "lldb/Interpreter/OptionGroupOutputFile.h"
11 #include "lldb/Host/OptionParser.h"
14 using namespace lldb_private;
16 OptionGroupOutputFile::OptionGroupOutputFile()
17 : m_file(), m_append(false, false) {}
19 OptionGroupOutputFile::~OptionGroupOutputFile() {}
21 static const uint32_t SHORT_OPTION_APND = 0x61706e64; // 'apnd'
23 static constexpr OptionDefinition g_option_table[] = {
24 {LLDB_OPT_SET_1, false, "outfile", 'o', OptionParser::eRequiredArgument,
25 nullptr, {}, 0, eArgTypeFilename,
26 "Specify a path for capturing command output."},
27 {LLDB_OPT_SET_1, false, "append-outfile", SHORT_OPTION_APND,
28 OptionParser::eNoArgument, nullptr, {}, 0, eArgTypeNone,
29 "Append to the file specified with '--outfile <path>'."},
32 llvm::ArrayRef<OptionDefinition> OptionGroupOutputFile::GetDefinitions() {
33 return llvm::makeArrayRef(g_option_table);
37 OptionGroupOutputFile::SetOptionValue(uint32_t option_idx,
38 llvm::StringRef option_arg,
39 ExecutionContext *execution_context) {
41 const int short_option = g_option_table[option_idx].short_option;
43 switch (short_option) {
45 error = m_file.SetValueFromString(option_arg);
48 case SHORT_OPTION_APND:
49 m_append.SetCurrentValue(true);
53 error.SetErrorStringWithFormat("unrecognized option '%c'", short_option);
60 void OptionGroupOutputFile::OptionParsingStarting(
61 ExecutionContext *execution_context) {