1ac7ddfbfSEd Maste //===-- OptionGroupOutputFile.cpp -------------------------------*- C++ -*-===//
2ac7ddfbfSEd Maste //
3ac7ddfbfSEd Maste // The LLVM Compiler Infrastructure
4ac7ddfbfSEd Maste //
5ac7ddfbfSEd Maste // This file is distributed under the University of Illinois Open Source
6ac7ddfbfSEd Maste // License. See LICENSE.TXT for details.
7ac7ddfbfSEd Maste //
8ac7ddfbfSEd Maste //===----------------------------------------------------------------------===//
9ac7ddfbfSEd Maste
10ac7ddfbfSEd Maste #include "lldb/Interpreter/OptionGroupOutputFile.h"
11ac7ddfbfSEd Maste
12f678e45dSDimitry Andric #include "lldb/Host/OptionParser.h"
13ac7ddfbfSEd Maste
14ac7ddfbfSEd Maste using namespace lldb;
15ac7ddfbfSEd Maste using namespace lldb_private;
16ac7ddfbfSEd Maste
OptionGroupOutputFile()17435933ddSDimitry Andric OptionGroupOutputFile::OptionGroupOutputFile()
18435933ddSDimitry Andric : m_file(), m_append(false, false) {}
19ac7ddfbfSEd Maste
~OptionGroupOutputFile()20435933ddSDimitry Andric OptionGroupOutputFile::~OptionGroupOutputFile() {}
21ac7ddfbfSEd Maste
220127ef0fSEd Maste static const uint32_t SHORT_OPTION_APND = 0x61706e64; // 'apnd'
230127ef0fSEd Maste
24*b5893f02SDimitry Andric static constexpr OptionDefinition g_option_table[] = {
25435933ddSDimitry Andric {LLDB_OPT_SET_1, false, "outfile", 'o', OptionParser::eRequiredArgument,
26*b5893f02SDimitry Andric nullptr, {}, 0, eArgTypeFilename,
27435933ddSDimitry Andric "Specify a path for capturing command output."},
280127ef0fSEd Maste {LLDB_OPT_SET_1, false, "append-outfile", SHORT_OPTION_APND,
29*b5893f02SDimitry Andric OptionParser::eNoArgument, nullptr, {}, 0, eArgTypeNone,
301c3bbb01SEd Maste "Append to the file specified with '--outfile <path>'."},
31ac7ddfbfSEd Maste };
32ac7ddfbfSEd Maste
GetDefinitions()33435933ddSDimitry Andric llvm::ArrayRef<OptionDefinition> OptionGroupOutputFile::GetDefinitions() {
34435933ddSDimitry Andric return llvm::makeArrayRef(g_option_table);
35ac7ddfbfSEd Maste }
36ac7ddfbfSEd Maste
375517e702SDimitry Andric Status
SetOptionValue(uint32_t option_idx,llvm::StringRef option_arg,ExecutionContext * execution_context)385517e702SDimitry Andric OptionGroupOutputFile::SetOptionValue(uint32_t option_idx,
395517e702SDimitry Andric llvm::StringRef option_arg,
40435933ddSDimitry Andric ExecutionContext *execution_context) {
415517e702SDimitry Andric Status error;
42ac7ddfbfSEd Maste const int short_option = g_option_table[option_idx].short_option;
43ac7ddfbfSEd Maste
44435933ddSDimitry Andric switch (short_option) {
45ac7ddfbfSEd Maste case 'o':
461c3bbb01SEd Maste error = m_file.SetValueFromString(option_arg);
47ac7ddfbfSEd Maste break;
48ac7ddfbfSEd Maste
490127ef0fSEd Maste case SHORT_OPTION_APND:
50ac7ddfbfSEd Maste m_append.SetCurrentValue(true);
51ac7ddfbfSEd Maste break;
52ac7ddfbfSEd Maste
53ac7ddfbfSEd Maste default:
54ac7ddfbfSEd Maste error.SetErrorStringWithFormat("unrecognized option '%c'", short_option);
55ac7ddfbfSEd Maste break;
56ac7ddfbfSEd Maste }
57ac7ddfbfSEd Maste
58ac7ddfbfSEd Maste return error;
59ac7ddfbfSEd Maste }
60ac7ddfbfSEd Maste
OptionParsingStarting(ExecutionContext * execution_context)61435933ddSDimitry Andric void OptionGroupOutputFile::OptionParsingStarting(
62435933ddSDimitry Andric ExecutionContext *execution_context) {
63ac7ddfbfSEd Maste m_file.Clear();
64ac7ddfbfSEd Maste m_append.Clear();
65ac7ddfbfSEd Maste }
66