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
167c575b3bSJohnny Chen #include "lldb/Utility/Utils.h"
1784c39663SGreg Clayton 
1884c39663SGreg Clayton using namespace lldb;
1984c39663SGreg Clayton using namespace lldb_private;
2084c39663SGreg Clayton 
2184c39663SGreg Clayton OptionGroupOutputFile::OptionGroupOutputFile() :
2284c39663SGreg Clayton     m_file (),
2384c39663SGreg Clayton     m_append (false, false)
2484c39663SGreg Clayton {
2584c39663SGreg Clayton }
2684c39663SGreg Clayton 
2784c39663SGreg Clayton OptionGroupOutputFile::~OptionGroupOutputFile ()
2884c39663SGreg Clayton {
2984c39663SGreg Clayton }
3084c39663SGreg Clayton 
3144edda0aSSaleem Abdulrasool static const uint32_t SHORT_OPTION_APND = 0x61706e64;   // 'apnd'
3244edda0aSSaleem Abdulrasool 
3384c39663SGreg Clayton static OptionDefinition
3484c39663SGreg Clayton g_option_table[] =
3584c39663SGreg Clayton {
36*d37221dcSZachary Turner     { LLDB_OPT_SET_1 , false, "outfile", 'o', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeFilename , "Specify a path for capturing command output."},
3744edda0aSSaleem Abdulrasool     { LLDB_OPT_SET_1 , false, "append-outfile" , SHORT_OPTION_APND,
38*d37221dcSZachary Turner       OptionParser::eNoArgument, nullptr, nullptr, 0, eArgTypeNone ,
3944edda0aSSaleem Abdulrasool       "Append to the the file specified with '--outfile <path>'."},
4084c39663SGreg Clayton };
4184c39663SGreg Clayton 
4284c39663SGreg Clayton uint32_t
4384c39663SGreg Clayton OptionGroupOutputFile::GetNumDefinitions ()
4484c39663SGreg Clayton {
456ebc8c45SJohnny Chen     return llvm::array_lengthof(g_option_table);
4684c39663SGreg Clayton }
4784c39663SGreg Clayton 
4884c39663SGreg Clayton const OptionDefinition *
4984c39663SGreg Clayton OptionGroupOutputFile::GetDefinitions ()
5084c39663SGreg Clayton {
5184c39663SGreg Clayton     return g_option_table;
5284c39663SGreg Clayton }
5384c39663SGreg Clayton 
5484c39663SGreg Clayton Error
5584c39663SGreg Clayton OptionGroupOutputFile::SetOptionValue (CommandInterpreter &interpreter,
5684c39663SGreg Clayton                                        uint32_t option_idx,
5784c39663SGreg Clayton                                        const char *option_arg)
5884c39663SGreg Clayton {
5984c39663SGreg Clayton     Error error;
603bcdfc0eSGreg Clayton     const int short_option = g_option_table[option_idx].short_option;
6184c39663SGreg Clayton 
6284c39663SGreg Clayton     switch (short_option)
6384c39663SGreg Clayton     {
6484c39663SGreg Clayton         case 'o':
6584c39663SGreg Clayton             error = m_file.SetValueFromCString (option_arg);
6684c39663SGreg Clayton             break;
6784c39663SGreg Clayton 
6844edda0aSSaleem Abdulrasool         case SHORT_OPTION_APND:
6984c39663SGreg Clayton             m_append.SetCurrentValue(true);
7084c39663SGreg Clayton             break;
7184c39663SGreg Clayton 
7284c39663SGreg Clayton         default:
7386edbf41SGreg Clayton             error.SetErrorStringWithFormat ("unrecognized option '%c'", short_option);
7484c39663SGreg Clayton             break;
7584c39663SGreg Clayton     }
7684c39663SGreg Clayton 
7784c39663SGreg Clayton     return error;
7884c39663SGreg Clayton }
7984c39663SGreg Clayton 
8084c39663SGreg Clayton void
8184c39663SGreg Clayton OptionGroupOutputFile::OptionParsingStarting (CommandInterpreter &interpreter)
8284c39663SGreg Clayton {
8384c39663SGreg Clayton     m_file.Clear();
8484c39663SGreg Clayton     m_append.Clear();
8584c39663SGreg Clayton }
86