• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

STEllAR-GROUP / hpx / #882

31 Aug 2023 07:44PM UTC coverage: 41.798% (-44.7%) from 86.546%
#882

push

19442 of 46514 relevant lines covered (41.8%)

126375.38 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

56.99
/libs/core/program_options/src/cmdline.cpp
1
//  Copyright Vladimir Prus 2002-2004.
2
//
3
//  SPDX-License-Identifier: BSL-1.0
4
//  Distributed under the Boost Software License, Version 1.0. (See accompanying
5
//  file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
6

7
#include <hpx/program_options/config.hpp>
8
#include <hpx/assert.hpp>
9
#include <hpx/program_options/detail/cmdline.hpp>
10
#include <hpx/program_options/errors.hpp>
11
#include <hpx/program_options/options_description.hpp>
12
#include <hpx/program_options/positional_options.hpp>
13
#include <hpx/program_options/value_semantic.hpp>
14

15
#include <cctype>
16
#include <climits>
17
#include <cstddef>
18
#include <cstdio>
19
#include <cstring>
20
#include <functional>
21
#include <string>
22
#include <utility>
23
#include <vector>
24

25
namespace hpx::program_options {
26

27
    using namespace hpx::program_options::command_line_style;
28

29
    std::string invalid_syntax::get_template(kind_t kind)
×
30
    {
31
        // Initially, store the message in 'const char*' variable,
32
        // to avoid conversion to string in all cases.
33
        char const* msg;
34
        switch (kind)
×
35
        {
36
        case empty_adjacent_parameter:
37
            msg = "the argument for option '%canonical_option%' should follow "
38
                  "immediately after the equal sign";
39
            break;
40
        case missing_parameter:
×
41
            msg = "the required argument for option '%canonical_option%' is "
42
                  "missing";
43
            break;
×
44
        case unrecognized_line:
×
45
            msg = "the options configuration file contains an invalid line "
46
                  "'%invalid_line%'";
47
            break;
×
48
        // none of the following are currently used:
49
        case long_not_allowed:
×
50
            msg = "the un-abbreviated option '%canonical_option%' is not valid";
51
            break;
×
52
        case long_adjacent_not_allowed:
×
53
            msg =
54
                "the un-abbreviated option '%canonical_option%' does not take "
55
                "any arguments";
56
            break;
×
57
        case short_adjacent_not_allowed:
×
58
            msg = "the abbreviated option '%canonical_option%' does not take "
59
                  "any arguments";
60
            break;
×
61
        case extra_parameter:
×
62
            msg = "option '%canonical_option%' does not take any arguments";
63
            break;
×
64
        default:
×
65
            msg = "unknown command line syntax error for '%s'";
66
            break;
×
67
        }
68
        return msg;
×
69
    }
70
}    // namespace hpx::program_options
71

72
namespace hpx::program_options::detail {
73

74
    cmdline::cmdline(std::vector<std::string> const& args)
194✔
75
    {
76
        init(args);
194✔
77
    }
194✔
78

79
    cmdline::cmdline(int argc, char const* const* argv)
×
80
    {
81
        init(std::vector<std::string>(argv + 1,
×
82
            argv + static_cast<std::size_t>(argc) +
×
83
                static_cast<std::size_t>(!argc)));
84
    }
×
85

86
    void cmdline::init(std::vector<std::string> const& args)
194✔
87
    {
88
        this->m_args = args;
194✔
89
        m_style = command_line_style::default_style;
194✔
90
        m_desc = nullptr;
194✔
91
        m_positional = nullptr;
194✔
92
        m_allow_unregistered = false;
194✔
93
    }
194✔
94

95
    void cmdline::style(int style) noexcept
194✔
96
    {
97
        if (style == 0)
194✔
98
            style = default_style;
99

100
        check_style(style);
194✔
101
        this->m_style = static_cast<style_t>(style);
194✔
102
    }
194✔
103

104
    void cmdline::allow_unregistered() noexcept
193✔
105
    {
106
        this->m_allow_unregistered = true;
193✔
107
    }
193✔
108

109
    void cmdline::check_style(int style)
194✔
110
    {
111
        bool const allow_some_long =
112
            (style & allow_long) || (style & allow_long_disguise);
113

114
        char const* error = nullptr;
115
        if (allow_some_long && !(style & long_allow_adjacent) &&
194✔
116
            !(style & long_allow_next))
117
        {
118
            error =
119
                "hpx::program_options misconfiguration: choose one or other of "
120
                "'command_line_style::long_allow_next' (whitespace separated "
121
                "arguments) or 'command_line_style::long_allow_adjacent' ('=' "
122
                "separated arguments) for long options.";
123
        }
124

125
        if (!error && (style & allow_short) &&
126
            !(style & short_allow_adjacent) && !(style & short_allow_next))
194✔
127
        {
128
            error =
129
                "hpx::program_options misconfiguration: choose one or other of "
130
                "'command_line_style::short_allow_next' (whitespace separated "
131
                "arguments) or 'command_line_style::short_allow_adjacent' ('=' "
132
                "separated arguments) for short options.";
133
        }
134

135
        if (!error && (style & allow_short) &&
136
            !(style & allow_dash_for_short) && !(style & allow_slash_for_short))
194✔
137
        {
138
            error =
139
                "hpx::program_options misconfiguration: choose one or other of "
140
                "'command_line_style::allow_slash_for_short' (slashes) or "
141
                "'command_line_style::allow_dash_for_short' (dashes) for short "
142
                "options.";
143
        }
144

145
        if (error)
146
            throw invalid_command_line_style(error);
×
147

148
        // Need to check that if guessing and long disguise are enabled -f will
149
        // mean the same as -foo
150
    }
194✔
151

152
    bool cmdline::is_style_active(style_t style) const noexcept
3,134✔
153
    {
154
        return ((m_style & style) ? true : false);
3,134✔
155
    }
156

157
    void cmdline::set_options_description(
194✔
158
        options_description const& desc) noexcept
159
    {
160
        m_desc = &desc;
194✔
161
    }
194✔
162

163
    void cmdline::set_positional_options(
137✔
164
        positional_options_description const& positional) noexcept
165
    {
166
        m_positional = &positional;
137✔
167
    }
137✔
168

169
    int cmdline::get_canonical_option_prefix() const noexcept
194✔
170
    {
171
        if (m_style & allow_long)
194✔
172
            return allow_long;
173

174
        if (m_style & allow_long_disguise)
×
175
            return allow_long_disguise;
176

177
        if ((m_style & allow_short) && (m_style & allow_dash_for_short))
×
178
            return allow_dash_for_short;
179

180
        if ((m_style & allow_short) && (m_style & allow_slash_for_short))
×
181
            return allow_slash_for_short;
×
182

183
        return 0;
184
    }
185

186
    std::vector<option> cmdline::run()
194✔
187
    {
188
        // The parsing is done by having a set of 'style parsers' and trying
189
        // then in order. Each parser is passed a vector of unparsed tokens and
190
        // can consume some of them (by removing elements on front) and return a
191
        // vector of options.
192
        //
193
        // We try each style parser in turn, until some input is consumed. The
194
        // returned vector of option may contain the result of just syntactic
195
        // parsing of token, say --foo will be parsed as option with name 'foo',
196
        // and the style parser is not required to care if that option is
197
        // defined, and how many tokens the value may take. So, after vector is
198
        // returned, we validate them.
199
        HPX_ASSERT(m_desc);
200

201
        std::vector<style_parser> style_parsers;
194✔
202
        style_parsers.reserve(7);
194✔
203

204
        if (m_style_parser)
194✔
205
            style_parsers.push_back(m_style_parser);
×
206

207
        if (m_additional_parser)
194✔
208
        {
209
            style_parsers.emplace_back([this](auto&& arg) {
194✔
210
                return handle_additional_parser(
211
                    std::forward<decltype(arg)>(arg));
504✔
212
            });
213
        }
214

215
        if (m_style & allow_long)
194✔
216
        {
217
            style_parsers.emplace_back([this](auto&& arg) {
194✔
218
                return parse_long_option(std::forward<decltype(arg)>(arg));
502✔
219
            });
220
        }
221

222
        if ((m_style & allow_long_disguise))
194✔
223
        {
224
            style_parsers.emplace_back([this](auto&& arg) {
×
225
                return parse_disguised_long_option(
226
                    std::forward<decltype(arg)>(arg));
×
227
            });
228
        }
229

230
        if ((m_style & allow_short) && (m_style & allow_dash_for_short))
194✔
231
        {
232
            style_parsers.emplace_back([this](auto&& arg) {
194✔
233
                return parse_short_option(std::forward<decltype(arg)>(arg));
68✔
234
            });
235
        }
236

237
        if ((m_style & allow_short) && (m_style & allow_slash_for_short))
194✔
238
        {
239
            style_parsers.emplace_back([this](auto&& arg) {
×
240
                return parse_dos_option(std::forward<decltype(arg)>(arg));
×
241
            });
242
        }
243

244
        style_parsers.emplace_back([](auto&& arg) {
194✔
245
            return parse_terminator(std::forward<decltype(arg)>(arg));
66✔
246
        });
247

248
        std::vector<option> result;
194✔
249
        std::vector<std::string>& args = m_args;    //-V826
194✔
250
        while (!args.empty())
892✔
251
        {
252
            bool ok = false;
253
            for (std::size_t i = 0; i < style_parsers.size(); ++i)
1,206✔
254
            {
255
                std::size_t const current_size = args.size();
256
                std::vector<option> next = style_parsers[i](args);
257

258
                // Check that option names are valid, and that all values are in
259
                // place.
260
                if (!next.empty())
1,140✔
261
                {
262
                    std::vector<std::string> e;
438✔
263
                    for (std::size_t k = 0; k < next.size() - 1; ++k)
438✔
264
                    {
265
                        finish_option(next[k], e, style_parsers);
×
266
                    }
267
                    // For the last option, pass the unparsed tokens so that
268
                    // they can be added to next.back()'s values if appropriate.
269
                    finish_option(next.back(), args, style_parsers);
438✔
270
                    for (auto const& j : next)
876✔
271
                        result.push_back(j);
438✔
272
                }
438✔
273

274
                if (args.size() != current_size)
1,140✔
275
                {
276
                    ok = true;
277
                    break;
278
                }
279
            }
1,140✔
280

281
            if (!ok)
504✔
282
            {
283
                option opt;
284
                opt.value.push_back(args[0]);
66✔
285
                opt.original_tokens.push_back(args[0]);
66✔
286
                result.push_back(opt);
66✔
287
                args.erase(args.begin());
288
            }
66✔
289
        }
290

291
        /* If an key option is followed by a positional option,
292
           can can consume more tokens (e.g. it's multitoken option),
293
           give those tokens to it.  */
294
        std::vector<option> result2;
194✔
295
        for (std::size_t i = 0; i < result.size(); ++i)
698✔
296
        {
297
            result2.push_back(result[i]);
504✔
298
            option& opt = result2.back();
299

300
            if (opt.string_key.empty())
504✔
301
                continue;
66✔
302

303
            option_description const* xd;
304
            try
305
            {
306
                xd = m_desc->find_nothrow(opt.string_key,
438✔
307
                    is_style_active(allow_guessing),
438✔
308
                    is_style_active(long_case_insensitive),
438✔
309
                    is_style_active(short_case_insensitive));
438✔
310
            }
311
            catch (error_with_option_name& e)
×
312
            {
313
                // add context and rethrow
314
                e.add_context(opt.string_key, opt.original_tokens[0],
×
315
                    get_canonical_option_prefix());
316
                throw;
×
317
            }
×
318

319
            if (!xd)
438✔
320
                continue;
2✔
321

322
            std::size_t const min_tokens =
323
                static_cast<std::size_t>(xd->semantic()->min_tokens());
436✔
324
            std::size_t const max_tokens =
325
                static_cast<std::size_t>(xd->semantic()->max_tokens());
436✔
326
            if (min_tokens < max_tokens && opt.value.size() < max_tokens)
436✔
327
            {
328
                // This option may grab some more tokens. We only allow to grab
329
                // tokens that are not already recognized as key options.
330

331
                std::size_t can_take_more = max_tokens - opt.value.size();
×
332
                std::size_t j = i + 1;
×
333
                for (; can_take_more && j < result.size(); --can_take_more, ++j)
×
334
                {
335
                    option& opt2 = result[j];
336
                    if (!opt2.string_key.empty())
×
337
                        break;
338

339
                    if (opt2.position_key == INT_MAX)
×
340
                    {
341
                        // We use INT_MAX to mark positional options that
342
                        // were found after the '--' terminator and therefore
343
                        // should stay positional forever.
344
                        break;
345
                    }
346

347
                    HPX_ASSERT(opt2.value.size() == 1);
348

349
                    opt.value.push_back(opt2.value[0]);
×
350

351
                    HPX_ASSERT(opt2.original_tokens.size() == 1);
352

353
                    opt.original_tokens.push_back(opt2.original_tokens[0]);
×
354
                }
355
                i = j - 1;
×
356
            }
357
        }
358
        result.swap(result2);
359

360
        // Assign position keys to positional options.
361
        int position_key = 0;
362
        for (auto& i : result)
698✔
363
        {
364
            if (i.string_key.empty())
504✔
365
                i.position_key = position_key++;
66✔
366
        }
367

368
        if (m_positional)
194✔
369
        {
370
            unsigned position = 0;
371
            for (option& opt : result)
460✔
372
            {
373
                if (opt.position_key != -1)
323✔
374
                {
375
                    if (position >= m_positional->max_total_count())
47✔
376
                    {
377
                        throw too_many_positional_options_error();
×
378
                    }
379
                    opt.string_key = m_positional->name_for_position(position);
47✔
380
                    ++position;
47✔
381
                }
382
            }
383
        }
384

385
        // set case sensitive flag
386
        for (auto& i : result)
698✔
387
        {
388
            if (i.string_key.size() > 2 ||
504✔
389
                (i.string_key.size() > 1 && i.string_key[0] != '-'))
2✔
390
            {
391
                // it is a long option
392
                i.case_insensitive = is_style_active(long_case_insensitive);
483✔
393
            }
394
            else
395
            {
396
                // it is a short option
397
                i.case_insensitive = is_style_active(short_case_insensitive);
21✔
398
            }
399
        }
400

401
        return result;
194✔
402
    }
194✔
403

404
    void cmdline::finish_option(option& opt,
438✔
405
        std::vector<std::string>& other_tokens,
406
        std::vector<style_parser> const& style_parsers) const
407
    {
408
        if (opt.string_key.empty())
438✔
409
            return;
2✔
410

411
        // Be defensive: will have no original token if option created by
412
        // handle_additional_parser()
413
        std::string original_token_for_exceptions = opt.string_key;
414
        if (!opt.original_tokens.empty())
438✔
415
            original_token_for_exceptions = opt.original_tokens[0];
416

417
        try
418
        {
419
            // First check that the option is valid, and get its description.
420
            option_description const* xd = m_desc->find_nothrow(opt.string_key,
438✔
421
                is_style_active(allow_guessing),
438✔
422
                is_style_active(long_case_insensitive),
438✔
423
                is_style_active(short_case_insensitive));
438✔
424

425
            if (!xd)
438✔
426
            {
427
                if (m_allow_unregistered)
2✔
428
                {
429
                    opt.unregistered = true;
2✔
430
                    return;
431
                }
432
                throw unknown_option();
×
433
            }
434
            option_description const& d = *xd;
435

436
            // Canonize the name
437
            opt.string_key = d.key(opt.string_key);
436✔
438

439
            // We check that the min/max number of tokens for the option
440
            // agrees with the number of tokens we have. The 'adjacent_value'
441
            // (the value in --foo=1) counts as a separate token, and if present
442
            // must be consumed. The following tokens on the command line may be
443
            // left unconsumed.
444
            std::size_t min_tokens =
445
                static_cast<std::size_t>(d.semantic()->min_tokens());
436✔
446
            std::size_t const max_tokens =
447
                static_cast<std::size_t>(d.semantic()->max_tokens());
872✔
448

449
            std::size_t const present_tokens =
450
                opt.value.size() + other_tokens.size();
436✔
451

452
            if (present_tokens >= min_tokens)
436✔
453
            {
454
                if (!opt.value.empty() && max_tokens == 0)
436✔
455
                {
456
                    throw invalid_command_line_syntax(
×
457
                        invalid_command_line_syntax::extra_parameter);
×
458
                }
459

460
                // Grab min_tokens values from other_tokens, but only if those tokens
461
                // are not recognized as options themselves.
462
                if (opt.value.size() <= min_tokens)
436✔
463
                {
464
                    min_tokens -= opt.value.size();    //-V101
436✔
465
                }
466
                else
467
                {
468
                    min_tokens = 0;
469
                }
470

471
                // Everything is OK, move the values to the result.
472
                while (!other_tokens.empty() && min_tokens--)
436✔
473
                {
474
                    // check if extra parameter looks like a known option we use
475
                    // style parsers to check if it is syntactically an option,
476
                    // additionally we check if an option_description exists
477
                    std::vector<option> followed_option;
×
478
                    std::vector next_token(1, other_tokens[0]);
×
479
                    for (std::size_t i = 0;
×
480
                        followed_option.empty() && i < style_parsers.size();
×
481
                        ++i)
482
                    {
483
                        followed_option = style_parsers[i](next_token);
×
484
                    }
485
                    if (!followed_option.empty())
×
486
                    {
487
                        original_token_for_exceptions = other_tokens[0];
488
                        if (m_desc->find_nothrow(other_tokens[0],
×
489
                                is_style_active(allow_guessing),
×
490
                                is_style_active(long_case_insensitive),
×
491
                                is_style_active(short_case_insensitive)))
×
492
                        {
493
                            throw invalid_command_line_syntax(
×
494
                                invalid_command_line_syntax::missing_parameter);
×
495
                        }
496
                    }
497
                    opt.value.push_back(other_tokens[0]);
×
498
                    opt.original_tokens.push_back(other_tokens[0]);
×
499
                    other_tokens.erase(other_tokens.begin());
500
                }
×
501
            }
502
            else
503
            {
504
                throw invalid_command_line_syntax(
×
505
                    invalid_command_line_syntax::missing_parameter);
×
506
            }
507
        }
508
        // use only original token for unknown_option / ambiguous_option since
509
        // by definition
510
        //    they are unrecognized / unparsable
511
        catch (error_with_option_name& e)
×
512
        {
513
            // add context and rethrow
514
            e.add_context(opt.string_key, original_token_for_exceptions,
×
515
                get_canonical_option_prefix());
516
            throw;
×
517
        }
×
518
    }
519

520
    std::vector<option> cmdline::parse_long_option(
502✔
521
        std::vector<std::string>& args) const
522
    {
523
        std::vector<option> result;
502✔
524
        std::string const& tok = args[0];
525
        if (tok.size() >= 3 && tok[0] == '-' && tok[1] == '-')
502✔
526
        {
527
            std::string name, adjacent;
528

529
            std::string::size_type const p = tok.find('=');
434✔
530
            if (p != std::string::npos)
434✔
531
            {
532
                name = tok.substr(2, p - 2);
434✔
533
                adjacent = tok.substr(p + 1);
868✔
534
                if (adjacent.empty())
434✔
535
                {
536
                    throw invalid_command_line_syntax(
×
537
                        invalid_command_line_syntax::empty_adjacent_parameter,
538
                        name, name, get_canonical_option_prefix());
×
539
                }
540
            }
541
            else
542
            {
543
                name = tok.substr(2);
×
544
            }
545
            option opt;
546
            opt.string_key = HPX_MOVE(name);
434✔
547
            if (!adjacent.empty())
434✔
548
                opt.value.push_back(adjacent);
434✔
549
            opt.original_tokens.push_back(tok);
434✔
550
            result.push_back(opt);
434✔
551
            args.erase(args.begin());
552
        }
434✔
553
        return result;
502✔
554
    }
×
555

556
    std::vector<option> cmdline::parse_short_option(
68✔
557
        std::vector<std::string>& args) const
558
    {
559
        std::string const& tok = args[0];
560
        if (tok.size() >= 2 && tok[0] == '-' && tok[1] != '-')
68✔
561
        {
562
            std::vector<option> result;
2✔
563

564
            std::string name = tok.substr(0, 2);
2✔
565
            std::string adjacent = tok.substr(2);
2✔
566

567
            // Short options can be 'grouped', so that "-d -a" becomes "-da".
568
            // Loop, processing one option at a time. We exit the loop when
569
            // either we've processed all the token, or when the remainder of
570
            // token is considered to be value, not further grouped option.
571
            for (;;)
572
            {
573
                option_description const* d;
574
                try
575
                {
576
                    d = m_desc->find_nothrow(name, false, false,
2✔
577
                        is_style_active(short_case_insensitive));
2✔
578
                }
579
                catch (error_with_option_name& e)
×
580
                {
581
                    // add context and rethrow
582
                    e.add_context(name, name, get_canonical_option_prefix());
×
583
                    throw;
×
584
                }
×
585

586
                // FIXME: check for 'allow_sticky'.
587
                if (d && (m_style & allow_sticky) &&
×
588
                    d->semantic()->max_tokens() == 0 && !adjacent.empty())
2✔
589
                {
590
                    // 'adjacent' is in fact further option.
591
                    option opt;
592
                    opt.string_key = name;
593
                    result.push_back(opt);
×
594

595
                    if (adjacent.empty())    //-V547
×
596
                    {
597
                        args.erase(args.begin());
598
                        break;
599
                    }
600

601
                    name = std::string("-") + adjacent[0];
×
602
                    adjacent.erase(adjacent.begin());
603
                }
×
604
                else
605
                {
606
                    option opt;
607
                    opt.string_key = name;
608
                    opt.original_tokens.push_back(tok);
2✔
609
                    if (!adjacent.empty())
2✔
610
                        opt.value.push_back(adjacent);
2✔
611
                    result.push_back(opt);
2✔
612
                    args.erase(args.begin());
613
                    break;
614
                }
2✔
615
            }
616
            return result;
617
        }
2✔
618
        return {};
66✔
619
    }
620

621
    std::vector<option> cmdline::parse_dos_option(
×
622
        std::vector<std::string>& args) const
623
    {
624
        std::vector<option> result;
×
625
        std::string const& tok = args[0];
626
        if (tok.size() >= 2 && tok[0] == '/')
×
627
        {
628
#if defined(HPX_GCC_VERSION) && HPX_GCC_VERSION >= 110000
629
#pragma GCC diagnostic push
630
#pragma GCC diagnostic ignored "-Wrestrict"
631
#endif
632
            std::string name = "-" + tok.substr(1, 1);
×
633
#if defined(HPX_GCC_VERSION) && HPX_GCC_VERSION >= 110000
634
#pragma GCC diagnostic pop
635
#endif
636
            std::string const adjacent = tok.substr(2);
×
637

638
            option opt;
639
            opt.string_key = HPX_MOVE(name);
×
640
            if (!adjacent.empty())
×
641
                opt.value.push_back(adjacent);
×
642
            opt.original_tokens.push_back(tok);
×
643
            result.push_back(opt);
×
644
            args.erase(args.begin());
645
        }
×
646
        return result;
×
647
    }
×
648

649
    std::vector<option> cmdline::parse_disguised_long_option(
×
650
        std::vector<std::string>& args) const
651
    {
652
        std::string const& tok = args[0];
653
        if (tok.size() >= 2 &&
×
654
            ((tok[0] == '-' && tok[1] != '-') ||
×
655
                ((m_style & allow_slash_for_short) && tok[0] == '/')))
×
656
        {
657
            try
658
            {
659
                if (m_desc->find_nothrow(tok.substr(1, tok.find('=') - 1),
×
660
                        is_style_active(allow_guessing),
×
661
                        is_style_active(long_case_insensitive),
×
662
                        is_style_active(short_case_insensitive)))
×
663
                {
664
#if defined(HPX_GCC_VERSION) && HPX_GCC_VERSION >= 110000
665
#pragma GCC diagnostic push
666
#pragma GCC diagnostic ignored "-Wrestrict"
667
#endif
668
                    args[0].insert(0, "-");
×
669
#if defined(HPX_GCC_VERSION) && HPX_GCC_VERSION >= 110000
670
#pragma GCC diagnostic pop
671
#endif
672
                    if (args[0][1] == '/')
×
673
                        args[0][1] = '-';
×
674
                    return parse_long_option(args);
×
675
                }
676
            }
677
            catch (error_with_option_name& e)
×
678
            {
679
                // add context and rethrow
680
                e.add_context(tok, tok, get_canonical_option_prefix());
×
681
                throw;
×
682
            }
×
683
        }
684
        return {};
×
685
    }
686

687
    std::vector<option> cmdline::parse_terminator(
66✔
688
        std::vector<std::string>& args)
689
    {
690
        std::vector<option> result;
66✔
691
        std::string const& tok = args[0];
692
        if (tok == "--")
66✔
693
        {
694
            for (std::size_t i = 1; i < args.size(); ++i)
×
695
            {
696
                option opt;
697
                opt.value.push_back(args[i]);
×
698
                opt.original_tokens.push_back(args[i]);
×
699
                opt.position_key = INT_MAX;
×
700
                result.push_back(opt);
×
701
            }
×
702
            args.clear();
703
        }
704
        return result;
66✔
705
    }
×
706

707
    std::vector<option> cmdline::handle_additional_parser(
504✔
708
        std::vector<std::string>& args) const
709
    {
710
        std::vector<option> result;
504✔
711
        std::pair<std::string, std::string> const r =
712
            m_additional_parser(args[0]);
713
        if (!r.first.empty())
504✔
714
        {
715
            option next;
716
            next.string_key = r.first;
717
            if (!r.second.empty())
2✔
718
                next.value.push_back(r.second);
2✔
719
            result.push_back(next);
2✔
720
            args.erase(args.begin());
721
        }
2✔
722
        return result;
504✔
723
    }
×
724

725
    void cmdline::set_additional_parser(additional_parser p) noexcept
194✔
726
    {
727
        m_additional_parser = HPX_MOVE(p);
194✔
728
    }
194✔
729

730
    void cmdline::extra_style_parser(style_parser s) noexcept
×
731
    {
732
        m_style_parser = HPX_MOVE(s);
×
733
    }
×
734
}    // namespace hpx::program_options::detail
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc