1//===-- OptionGroupOutputFile.cpp -------------------------------*- C++ -*-===//
2//
3//                     The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9
10#include "lldb/Interpreter/OptionGroupOutputFile.h"
11
12// C Includes
13// C++ Includes
14// Other libraries and framework includes
15// Project includes
16#include "lldb/Utility/Utils.h"
17
18using namespace lldb;
19using namespace lldb_private;
20
21OptionGroupOutputFile::OptionGroupOutputFile() :
22    m_file (),
23    m_append (false, false)
24{
25}
26
27OptionGroupOutputFile::~OptionGroupOutputFile ()
28{
29}
30
31static const uint32_t SHORT_OPTION_APND = 0x61706e64;   // 'apnd'
32
33static OptionDefinition
34g_option_table[] =
35{
36    { LLDB_OPT_SET_1 , false, "outfile", 'o', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeFilename , "Specify a path for capturing command output."},
37    { LLDB_OPT_SET_1 , false, "append-outfile" , SHORT_OPTION_APND,
38      OptionParser::eNoArgument, nullptr, nullptr, 0, eArgTypeNone ,
39      "Append to the file specified with '--outfile <path>'."},
40};
41
42uint32_t
43OptionGroupOutputFile::GetNumDefinitions ()
44{
45    return llvm::array_lengthof(g_option_table);
46}
47
48const OptionDefinition *
49OptionGroupOutputFile::GetDefinitions ()
50{
51    return g_option_table;
52}
53
54Error
55OptionGroupOutputFile::SetOptionValue (CommandInterpreter &interpreter,
56                                       uint32_t option_idx,
57                                       const char *option_arg)
58{
59    Error error;
60    const int short_option = g_option_table[option_idx].short_option;
61
62    switch (short_option)
63    {
64        case 'o':
65            error = m_file.SetValueFromString (option_arg);
66            break;
67
68        case SHORT_OPTION_APND:
69            m_append.SetCurrentValue(true);
70            break;
71
72        default:
73            error.SetErrorStringWithFormat ("unrecognized option '%c'", short_option);
74            break;
75    }
76
77    return error;
78}
79
80void
81OptionGroupOutputFile::OptionParsingStarting (CommandInterpreter &interpreter)
82{
83    m_file.Clear();
84    m_append.Clear();
85}
86