|
20 | 20 |
|
21 | 21 | #include <cstring>
|
22 | 22 |
|
| 23 | +#include <app_control.h> |
| 24 | + |
23 | 25 | #include <platform/CHIPDeviceBuildConfig.h>
|
24 | 26 |
|
25 | 27 | namespace {
|
@@ -65,35 +67,50 @@ static constexpr Option sOptions[] = {
|
65 | 67 | #endif
|
66 | 68 | };
|
67 | 69 |
|
68 |
| -}; // namespace |
69 |
| - |
70 |
| -void OptionsProxy::Parse(const char * argv0, app_control_h app_control) |
| 70 | +bool ParseAppExtraData(app_control_h app_control, const char * key, void * userData) |
71 | 71 | {
|
72 |
| - // Insert argv[0] commonly used as a process name |
73 |
| - if (argv0 != nullptr) |
74 |
| - { |
75 |
| - mArgs.push_back(argv0); |
76 |
| - } |
| 72 | + auto * args = static_cast<std::vector<std::string> *>(userData); |
77 | 73 |
|
78 | 74 | for (const auto & option : sOptions)
|
79 | 75 | {
|
| 76 | + if (strcmp(key, option.name) != 0) |
| 77 | + { |
| 78 | + continue; |
| 79 | + } |
| 80 | + |
80 | 81 | char * value = nullptr;
|
81 | 82 | if (app_control_get_extra_data(app_control, option.name, &value) == APP_CONTROL_ERROR_NONE && value != nullptr)
|
82 | 83 | {
|
83 | 84 | if (!option.isBoolean)
|
84 | 85 | {
|
85 |
| - mArgs.push_back(std::string("--") + option.name); |
86 |
| - mArgs.push_back(value); |
| 86 | + args->push_back(std::string("--") + option.name); |
| 87 | + args->push_back(value); |
87 | 88 | }
|
88 | 89 | else if (strcmp(value, "true") == 0)
|
89 | 90 | {
|
90 |
| - mArgs.push_back(std::string("--") + option.name); |
| 91 | + args->push_back(std::string("--") + option.name); |
91 | 92 | }
|
92 | 93 | // Release memory allocated by app_control_get_extra_data()
|
93 | 94 | free(value);
|
94 | 95 | }
|
95 | 96 | }
|
96 | 97 |
|
| 98 | + // Continue iterating over all extra data |
| 99 | + return true; |
| 100 | +} |
| 101 | + |
| 102 | +}; // namespace |
| 103 | + |
| 104 | +void OptionsProxy::Parse(const char * argv0, app_control_h app_control) |
| 105 | +{ |
| 106 | + // Insert argv[0] commonly used as a process name |
| 107 | + if (argv0 != nullptr) |
| 108 | + { |
| 109 | + mArgs.push_back(argv0); |
| 110 | + } |
| 111 | + |
| 112 | + app_control_foreach_extra_data(app_control, ParseAppExtraData, &mArgs); |
| 113 | + |
97 | 114 | // Convert vector of strings into NULL-terminated vector of char pointers
|
98 | 115 | mArgv.reserve(mArgs.size() + 1);
|
99 | 116 | for (auto & arg : mArgs)
|
|
0 commit comments