184c39663SGreg Clayton //===-- OptionGroupOutputFile.cpp -------------------------------*- C++ -*-===//
284c39663SGreg Clayton //
384c39663SGreg Clayton //                     The LLVM Compiler Infrastructure
484c39663SGreg Clayton //
584c39663SGreg Clayton // This file is distributed under the University of Illinois Open Source
684c39663SGreg Clayton // License. See LICENSE.TXT for details.
784c39663SGreg Clayton //
884c39663SGreg Clayton //===----------------------------------------------------------------------===//
984c39663SGreg Clayton 
104bee32e5SJohnny Chen #include "lldb/Interpreter/OptionGroupOutputFile.h"
1184c39663SGreg Clayton 
1284c39663SGreg Clayton // C Includes
1384c39663SGreg Clayton // C++ Includes
1484c39663SGreg Clayton // Other libraries and framework includes
1584c39663SGreg Clayton // Project includes
16*3eb2b44dSZachary Turner #include "lldb/Host/OptionParser.h"
1784c39663SGreg Clayton 
1884c39663SGreg Clayton using namespace lldb;
1984c39663SGreg Clayton using namespace lldb_private;
2084c39663SGreg Clayton 
21b9c1b51eSKate Stone OptionGroupOutputFile::OptionGroupOutputFile()
22b9c1b51eSKate Stone     : m_file(), m_append(false, false) {}
2384c39663SGreg Clayton 
24b9c1b51eSKate Stone OptionGroupOutputFile::~OptionGroupOutputFile() {}
2584c39663SGreg Clayton 
2644edda0aSSaleem Abdulrasool static const uint32_t SHORT_OPTION_APND = 0x61706e64; // 'apnd'
2744edda0aSSaleem Abdulrasool 
28b9c1b51eSKate Stone static OptionDefinition g_option_table[] = {
29b9c1b51eSKate Stone     {LLDB_OPT_SET_1, false, "outfile", 'o', OptionParser::eRequiredArgument,
30b9c1b51eSKate Stone      nullptr, nullptr, 0, eArgTypeFilename,
31b9c1b51eSKate Stone      "Specify a path for capturing command output."},
3244edda0aSSaleem Abdulrasool     {LLDB_OPT_SET_1, false, "append-outfile", SHORT_OPTION_APND,
33d37221dcSZachary Turner      OptionParser::eNoArgument, nullptr, nullptr, 0, eArgTypeNone,
3458ef391fSBruce Mitchener      "Append to the file specified with '--outfile <path>'."},
3584c39663SGreg Clayton };
3684c39663SGreg Clayton 
371f0f5b5bSZachary Turner llvm::ArrayRef<OptionDefinition> OptionGroupOutputFile::GetDefinitions() {
3870602439SZachary Turner   return llvm::makeArrayRef(g_option_table);
3984c39663SGreg Clayton }
4084c39663SGreg Clayton 
41b9c1b51eSKate Stone Error OptionGroupOutputFile::SetOptionValue(
428cef4b0bSZachary Turner     uint32_t option_idx, llvm::StringRef option_arg,
43b9c1b51eSKate Stone     ExecutionContext *execution_context) {
4484c39663SGreg Clayton   Error error;
453bcdfc0eSGreg Clayton   const int short_option = g_option_table[option_idx].short_option;
4684c39663SGreg Clayton 
47b9c1b51eSKate Stone   switch (short_option) {
4884c39663SGreg Clayton   case 'o':
49c95f7e2aSPavel Labath     error = m_file.SetValueFromString(option_arg);
5084c39663SGreg Clayton     break;
5184c39663SGreg Clayton 
5244edda0aSSaleem Abdulrasool   case SHORT_OPTION_APND:
5384c39663SGreg Clayton     m_append.SetCurrentValue(true);
5484c39663SGreg Clayton     break;
5584c39663SGreg Clayton 
5684c39663SGreg Clayton   default:
5786edbf41SGreg Clayton     error.SetErrorStringWithFormat("unrecognized option '%c'", short_option);
5884c39663SGreg Clayton     break;
5984c39663SGreg Clayton   }
6084c39663SGreg Clayton 
6184c39663SGreg Clayton   return error;
6284c39663SGreg Clayton }
6384c39663SGreg Clayton 
64b9c1b51eSKate Stone void OptionGroupOutputFile::OptionParsingStarting(
65b9c1b51eSKate Stone     ExecutionContext *execution_context) {
6684c39663SGreg Clayton   m_file.Clear();
6784c39663SGreg Clayton   m_append.Clear();
6884c39663SGreg Clayton }
69