1cfca06d7SDimitry Andric //===-- OptionGroupBoolean.cpp --------------------------------------------===//
2f034231aSEd Maste //
35f29bb8aSDimitry Andric // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
45f29bb8aSDimitry Andric // See https://llvm.org/LICENSE.txt for license information.
55f29bb8aSDimitry Andric // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6f034231aSEd Maste //
7f034231aSEd Maste //===----------------------------------------------------------------------===//
8f034231aSEd Maste
9f034231aSEd Maste #include "lldb/Interpreter/OptionGroupBoolean.h"
10f034231aSEd Maste
1174a628f7SDimitry Andric #include "lldb/Host/OptionParser.h"
12f034231aSEd Maste
13f034231aSEd Maste using namespace lldb;
14f034231aSEd Maste using namespace lldb_private;
15f034231aSEd Maste
OptionGroupBoolean(uint32_t usage_mask,bool required,const char * long_option,int short_option,const char * usage_text,bool default_value,bool no_argument_toggle_default)1614f1b3e8SDimitry Andric OptionGroupBoolean::OptionGroupBoolean(uint32_t usage_mask, bool required,
17f034231aSEd Maste const char *long_option,
1814f1b3e8SDimitry Andric int short_option, const char *usage_text,
19f034231aSEd Maste bool default_value,
2014f1b3e8SDimitry Andric bool no_argument_toggle_default)
2114f1b3e8SDimitry Andric : m_value(default_value, default_value) {
22f034231aSEd Maste m_option_definition.usage_mask = usage_mask;
23f034231aSEd Maste m_option_definition.required = required;
24f034231aSEd Maste m_option_definition.long_option = long_option;
25f034231aSEd Maste m_option_definition.short_option = short_option;
260cac4ca3SEd Maste m_option_definition.validator = nullptr;
2714f1b3e8SDimitry Andric m_option_definition.option_has_arg = no_argument_toggle_default
2814f1b3e8SDimitry Andric ? OptionParser::eNoArgument
2914f1b3e8SDimitry Andric : OptionParser::eRequiredArgument;
3094994d37SDimitry Andric m_option_definition.enum_values = {};
31f034231aSEd Maste m_option_definition.completion_type = 0;
32f034231aSEd Maste m_option_definition.argument_type = eArgTypeBoolean;
33f034231aSEd Maste m_option_definition.usage_text = usage_text;
34f034231aSEd Maste }
35f034231aSEd Maste
SetOptionValue(uint32_t option_idx,llvm::StringRef option_value,ExecutionContext * execution_context)36b76161e4SDimitry Andric Status OptionGroupBoolean::SetOptionValue(uint32_t option_idx,
3714f1b3e8SDimitry Andric llvm::StringRef option_value,
3814f1b3e8SDimitry Andric ExecutionContext *execution_context) {
39b76161e4SDimitry Andric Status error;
4014f1b3e8SDimitry Andric if (m_option_definition.option_has_arg == OptionParser::eNoArgument) {
41f73363f1SDimitry Andric // Not argument, toggle the default value and mark the option as having
42f73363f1SDimitry Andric // been set
43f034231aSEd Maste m_value.SetCurrentValue(!m_value.GetDefaultValue());
44f034231aSEd Maste m_value.SetOptionWasSet();
4514f1b3e8SDimitry Andric } else {
4614f1b3e8SDimitry Andric error = m_value.SetValueFromString(option_value);
47f034231aSEd Maste }
48f034231aSEd Maste return error;
49f034231aSEd Maste }
50f034231aSEd Maste
OptionParsingStarting(ExecutionContext * execution_context)5114f1b3e8SDimitry Andric void OptionGroupBoolean::OptionParsingStarting(
5214f1b3e8SDimitry Andric ExecutionContext *execution_context) {
53f034231aSEd Maste m_value.Clear();
54f034231aSEd Maste }
55