3 * Copyright (c) 2021 Project CHIP Authors
6 * Licensed under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
10 * http://www.apache.org/licenses/LICENSE-2.0
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
21 #include <core/CHIPError.h>
22 #include <support/CHIPArgParser.hpp>
25 using namespace chip::ArgParser;
28 LinuxDeviceOptions gDeviceOptions;
30 // Follow the code style of command line arguments in case we need to add more options in the future.
33 kDeviceOption_BleDevice = 0x1000,
36 OptionDef sDeviceOptionDefs[] = { { "ble-device", kArgumentRequired, kDeviceOption_BleDevice }, {} };
38 const char * sDeviceOptionHelp = " --ble-device <number>\n"
39 " The device number for CHIPoBLE, without 'hci' prefix, can be found by hciconfig.\n"
42 bool HandleOption(const char * aProgram, OptionSet * aOptions, int aIdentifier, const char * aName, const char * aValue)
49 case kDeviceOption_BleDevice:
50 if (!ParseInt(aValue, LinuxDeviceOptions::GetInstance().mBleDevice))
52 PrintArgError("%s: invalid value specified for ble device number: %s\n", aProgram, aValue);
58 PrintArgError("%s: INTERNAL ERROR: Unhandled option: %s\n", aProgram, aName);
66 OptionSet sDeviceOptions = { HandleOption, sDeviceOptionDefs, "GENERAL OPTIONS", sDeviceOptionHelp };
68 OptionSet * sLinuxDeviceOptionSets[] = { &sDeviceOptions, nullptr };
71 CHIP_ERROR ParseArguments(int argc, char * argv[])
73 if (!ParseArgs(argv[0], argc, argv, sLinuxDeviceOptionSets))
75 return CHIP_ERROR_INVALID_ARGUMENT;
80 LinuxDeviceOptions & LinuxDeviceOptions::GetInstance()
82 return gDeviceOptions;