180814287SRaphael Isemann //===-- OptionGroupOutputFile.cpp -----------------------------------------===//
284c39663SGreg Clayton //
32946cd70SChandler Carruth // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
42946cd70SChandler Carruth // See https://llvm.org/LICENSE.txt for license information.
52946cd70SChandler 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 
OptionGroupOutputFile()16*8cdcd41eSTatyana Krasnukha OptionGroupOutputFile::OptionGroupOutputFile() : m_append(false, false) {}
1784c39663SGreg Clayton 
1844edda0aSSaleem Abdulrasool static const uint32_t SHORT_OPTION_APND = 0x61706e64; // 'apnd'
1944edda0aSSaleem Abdulrasool 
208fe53c49STatyana Krasnukha static constexpr OptionDefinition g_option_table[] = {
21b9c1b51eSKate Stone     {LLDB_OPT_SET_1, false, "outfile", 'o', OptionParser::eRequiredArgument,
228fe53c49STatyana Krasnukha      nullptr, {}, 0, eArgTypeFilename,
23b9c1b51eSKate Stone      "Specify a path for capturing command output."},
2444edda0aSSaleem Abdulrasool     {LLDB_OPT_SET_1, false, "append-outfile", SHORT_OPTION_APND,
258fe53c49STatyana Krasnukha      OptionParser::eNoArgument, nullptr, {}, 0, eArgTypeNone,
2658ef391fSBruce Mitchener      "Append to the file specified with '--outfile <path>'."},
2784c39663SGreg Clayton };
2884c39663SGreg Clayton 
GetDefinitions()291f0f5b5bSZachary Turner llvm::ArrayRef<OptionDefinition> OptionGroupOutputFile::GetDefinitions() {
3070602439SZachary Turner   return llvm::makeArrayRef(g_option_table);
3184c39663SGreg Clayton }
3284c39663SGreg Clayton 
3397206d57SZachary Turner Status
SetOptionValue(uint32_t option_idx,llvm::StringRef option_arg,ExecutionContext * execution_context)3497206d57SZachary Turner OptionGroupOutputFile::SetOptionValue(uint32_t option_idx,
3597206d57SZachary Turner                                       llvm::StringRef option_arg,
36b9c1b51eSKate Stone                                       ExecutionContext *execution_context) {
3797206d57SZachary Turner   Status error;
383bcdfc0eSGreg Clayton   const int short_option = g_option_table[option_idx].short_option;
3984c39663SGreg Clayton 
40b9c1b51eSKate Stone   switch (short_option) {
4184c39663SGreg Clayton   case 'o':
42c95f7e2aSPavel Labath     error = m_file.SetValueFromString(option_arg);
4384c39663SGreg Clayton     break;
4484c39663SGreg Clayton 
4544edda0aSSaleem Abdulrasool   case SHORT_OPTION_APND:
4684c39663SGreg Clayton     m_append.SetCurrentValue(true);
4784c39663SGreg Clayton     break;
4884c39663SGreg Clayton 
4984c39663SGreg Clayton   default:
5036162014SRaphael Isemann     llvm_unreachable("Unimplemented option");
5184c39663SGreg Clayton   }
5284c39663SGreg Clayton 
5384c39663SGreg Clayton   return error;
5484c39663SGreg Clayton }
5584c39663SGreg Clayton 
OptionParsingStarting(ExecutionContext * execution_context)56b9c1b51eSKate Stone void OptionGroupOutputFile::OptionParsingStarting(
57b9c1b51eSKate Stone     ExecutionContext *execution_context) {
5884c39663SGreg Clayton   m_file.Clear();
5984c39663SGreg Clayton   m_append.Clear();
6084c39663SGreg Clayton }
61