184c39663SGreg Clayton //===-- OptionGroupOutputFile.cpp -------------------------------*- C++ -*-===// 284c39663SGreg Clayton // 3*2946cd70SChandler Carruth // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4*2946cd70SChandler Carruth // See https://llvm.org/LICENSE.txt for license information. 5*2946cd70SChandler Carruth // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 684c39663SGreg Clayton // 784c39663SGreg Clayton //===----------------------------------------------------------------------===// 884c39663SGreg Clayton 94bee32e5SJohnny Chen #include "lldb/Interpreter/OptionGroupOutputFile.h" 1084c39663SGreg Clayton 113eb2b44dSZachary Turner #include "lldb/Host/OptionParser.h" 1284c39663SGreg Clayton 1384c39663SGreg Clayton using namespace lldb; 1484c39663SGreg Clayton using namespace lldb_private; 1584c39663SGreg Clayton 16b9c1b51eSKate Stone OptionGroupOutputFile::OptionGroupOutputFile() 17b9c1b51eSKate Stone : m_file(), m_append(false, false) {} 1884c39663SGreg Clayton 19b9c1b51eSKate Stone OptionGroupOutputFile::~OptionGroupOutputFile() {} 2084c39663SGreg Clayton 2144edda0aSSaleem Abdulrasool static const uint32_t SHORT_OPTION_APND = 0x61706e64; // 'apnd' 2244edda0aSSaleem Abdulrasool 238fe53c49STatyana Krasnukha static constexpr OptionDefinition g_option_table[] = { 24b9c1b51eSKate Stone {LLDB_OPT_SET_1, false, "outfile", 'o', OptionParser::eRequiredArgument, 258fe53c49STatyana Krasnukha nullptr, {}, 0, eArgTypeFilename, 26b9c1b51eSKate Stone "Specify a path for capturing command output."}, 2744edda0aSSaleem Abdulrasool {LLDB_OPT_SET_1, false, "append-outfile", SHORT_OPTION_APND, 288fe53c49STatyana Krasnukha OptionParser::eNoArgument, nullptr, {}, 0, eArgTypeNone, 2958ef391fSBruce Mitchener "Append to the file specified with '--outfile <path>'."}, 3084c39663SGreg Clayton }; 3184c39663SGreg Clayton 321f0f5b5bSZachary Turner llvm::ArrayRef<OptionDefinition> OptionGroupOutputFile::GetDefinitions() { 3370602439SZachary Turner return llvm::makeArrayRef(g_option_table); 3484c39663SGreg Clayton } 3584c39663SGreg Clayton 3697206d57SZachary Turner Status 3797206d57SZachary Turner OptionGroupOutputFile::SetOptionValue(uint32_t option_idx, 3897206d57SZachary Turner llvm::StringRef option_arg, 39b9c1b51eSKate Stone ExecutionContext *execution_context) { 4097206d57SZachary Turner Status error; 413bcdfc0eSGreg Clayton const int short_option = g_option_table[option_idx].short_option; 4284c39663SGreg Clayton 43b9c1b51eSKate Stone switch (short_option) { 4484c39663SGreg Clayton case 'o': 45c95f7e2aSPavel Labath error = m_file.SetValueFromString(option_arg); 4684c39663SGreg Clayton break; 4784c39663SGreg Clayton 4844edda0aSSaleem Abdulrasool case SHORT_OPTION_APND: 4984c39663SGreg Clayton m_append.SetCurrentValue(true); 5084c39663SGreg Clayton break; 5184c39663SGreg Clayton 5284c39663SGreg Clayton default: 5386edbf41SGreg Clayton error.SetErrorStringWithFormat("unrecognized option '%c'", short_option); 5484c39663SGreg Clayton break; 5584c39663SGreg Clayton } 5684c39663SGreg Clayton 5784c39663SGreg Clayton return error; 5884c39663SGreg Clayton } 5984c39663SGreg Clayton 60b9c1b51eSKate Stone void OptionGroupOutputFile::OptionParsingStarting( 61b9c1b51eSKate Stone ExecutionContext *execution_context) { 6284c39663SGreg Clayton m_file.Clear(); 6384c39663SGreg Clayton m_append.Clear(); 6484c39663SGreg Clayton } 65