argument_parser.hpp 16.6 KB
Newer Older
Paul's avatar
Paul committed
1
2
3
#ifndef MIGRAPHX_GUARD_RTGLIB_ARGUMENT_PARSER_HPP
#define MIGRAPHX_GUARD_RTGLIB_ARGUMENT_PARSER_HPP

Paul's avatar
Paul committed
4
5
6
#include <algorithm>
#include <functional>
#include <iostream>
Paul's avatar
Paul committed
7
#include <list>
Paul's avatar
Paul committed
8
#include <set>
Paul's avatar
Paul committed
9
#include <string>
Paul's avatar
Paul committed
10
#include <sstream>
Paul's avatar
Paul committed
11
12
#include <type_traits>
#include <unordered_map>
Paul's avatar
Paul committed
13
#include <utility>
Paul's avatar
Paul committed
14
15
#include <vector>

Paul's avatar
Paul committed
16
#include <migraphx/config.hpp>
Paul's avatar
Paul committed
17
18
#include <migraphx/requires.hpp>
#include <migraphx/type_name.hpp>
Paul's avatar
Paul committed
19
#include <migraphx/functional.hpp>
Paul's avatar
Paul committed
20
#include <migraphx/stringutils.hpp>
Paul's avatar
Paul committed
21
#include <migraphx/algorithm.hpp>
Paul's avatar
Paul committed
22
#include <migraphx/ranges.hpp>
kahmed10's avatar
kahmed10 committed
23
#include <migraphx/rank.hpp>
Paul's avatar
Paul committed
24

Paul's avatar
Paul committed
25
26
27
28
#ifndef _WIN32
#include <unistd.h>
#endif

Paul's avatar
Paul committed
29
30
31
namespace migraphx {
namespace driver {
inline namespace MIGRAPHX_INLINE_NS {
Paul's avatar
Paul committed
32

Paul's avatar
Paul committed
33
34
35
36
37
38
#ifdef MIGRAPHX_USE_CLANG_TIDY
#define MIGRAPHX_DRIVER_STATIC
#else
#define MIGRAPHX_DRIVER_STATIC static
#endif

Paul's avatar
Paul committed
39
template <class T>
Paul's avatar
Paul committed
40
41
42
43
44
using bare = std::remove_cv_t<std::remove_reference_t<T>>;

namespace detail {

template <class T>
Paul's avatar
Paul committed
45
auto is_container(int, T&& x) -> decltype(x.insert(x.end(), *x.begin()), std::true_type{});
Paul's avatar
Paul committed
46
47
48
49
50
51
52
53
54
55
56
57
58

template <class T>
std::false_type is_container(float, T&&);

} // namespace detail

template <class T>
struct is_container : decltype(detail::is_container(int(0), std::declval<T>()))
{
};

template <class T>
using is_multi_value =
Paul's avatar
Paul committed
59
    std::integral_constant<bool, (is_container<T>{} and not std::is_convertible<T, std::string>{})>;
Paul's avatar
Paul committed
60

Paul's avatar
Paul committed
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
enum class color
{
    reset      = 0,
    bold       = 1,
    underlined = 4,
    fg_red     = 31,
    fg_green   = 32,
    fg_yellow  = 33,
    fg_blue    = 34,
    fg_default = 39,
    bg_red     = 41,
    bg_green   = 42,
    bg_yellow  = 43,
    bg_blue    = 44,
    bg_default = 49
};
inline std::ostream& operator<<(std::ostream& os, const color& c)
{
#ifndef _WIN32
    static const bool use_color = isatty(STDOUT_FILENO) != 0;
    if(use_color)
        return os << "\033[" << static_cast<std::size_t>(c) << "m";
#endif
    return os;
}

Paul's avatar
Paul committed
87
88
89
90
91
92
93
inline std::string colorize(color c, const std::string& s)
{
    std::stringstream ss;
    ss << c << s << color::reset;
    return ss.str();
}

Paul's avatar
Paul committed
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
template <class T>
struct type_name
{
    static const std::string& apply() { return migraphx::get_type_name<T>(); }
};

template <>
struct type_name<std::string>
{
    static const std::string& apply()
    {
        static const std::string name = "std::string";
        return name;
    }
};

template <class T>
struct type_name<std::vector<T>>
{
    static const std::string& apply()
    {
        static const std::string name = "std::vector<" + type_name<T>::apply() + ">";
        return name;
    }
};

Paul's avatar
Paul committed
120
121
122
template <class T>
struct value_parser
{
Paul's avatar
Paul committed
123
    template <MIGRAPHX_REQUIRES(not std::is_enum<T>{} and not is_multi_value<T>{})>
Paul's avatar
Paul committed
124
125
126
127
128
129
130
    static T apply(const std::string& x)
    {
        T result;
        std::stringstream ss;
        ss.str(x);
        ss >> result;
        if(ss.fail())
Paul's avatar
Paul committed
131
            throw std::runtime_error("Failed to parse '" + x + "' as " + type_name<T>::apply());
Paul's avatar
Paul committed
132
133
134
        return result;
    }

Paul's avatar
Paul committed
135
    template <MIGRAPHX_REQUIRES(std::is_enum<T>{} and not is_multi_value<T>{})>
Paul's avatar
Paul committed
136
137
138
139
140
141
142
    static T apply(const std::string& x)
    {
        std::ptrdiff_t i;
        std::stringstream ss;
        ss.str(x);
        ss >> i;
        if(ss.fail())
Paul's avatar
Paul committed
143
            throw std::runtime_error("Failed to parse '" + x + "' as " + type_name<T>::apply());
Paul's avatar
Paul committed
144
145
        return static_cast<T>(i);
    }
Paul's avatar
Paul committed
146
147
148
149
150
151
152
153
154

    template <MIGRAPHX_REQUIRES(is_multi_value<T>{} and not std::is_enum<T>{})>
    static T apply(const std::string& x)
    {
        T result;
        using value_type = typename T::value_type;
        result.insert(result.end(), value_parser<value_type>::apply(x));
        return result;
    }
Paul's avatar
Paul committed
155
156
157
158
159
160
161
};

struct argument_parser
{
    struct argument
    {
        std::vector<std::string> flags;
Paul's avatar
Paul committed
162
        std::function<bool(argument_parser&, const std::vector<std::string>&)> action{};
Paul's avatar
Paul committed
163
164
165
        std::string type          = "";
        std::string help          = "";
        std::string metavar       = "";
Paul's avatar
Paul committed
166
        std::string default_value = "";
Paul's avatar
Paul committed
167
        unsigned nargs            = 1;
Paul's avatar
Paul committed
168
169
    };

Paul's avatar
Paul committed
170
    template <class T, MIGRAPHX_REQUIRES(is_multi_value<T>{})>
Paul's avatar
Paul committed
171
172
173
174
175
    std::string as_string_value(const T& x)
    {
        return to_string_range(x);
    }

kahmed10's avatar
kahmed10 committed
176
177
178
179
180
181
182
183
184
185
186
187
    template <class T>
    auto as_string_value(rank<1>, const T& x) -> decltype(to_string(x))
    {
        return to_string(x);
    }

    template <class T>
    std::string as_string_value(rank<0>, const T&)
    {
        throw std::runtime_error("Can't convert to string");
    }

Paul's avatar
Paul committed
188
    template <class T, MIGRAPHX_REQUIRES(not is_multi_value<T>{})>
Paul's avatar
Paul committed
189
190
    std::string as_string_value(const T& x)
    {
kahmed10's avatar
kahmed10 committed
191
        return as_string_value(rank<1>{}, x);
Paul's avatar
Paul committed
192
193
    }

Paul's avatar
Paul committed
194
    template <class T, class... Fs>
Paul's avatar
Paul committed
195
    void operator()(T& x, const std::vector<std::string>& flags, Fs... fs)
Paul's avatar
Paul committed
196
    {
Paul's avatar
Paul committed
197
        arguments.push_back({flags, [&](auto&&, const std::vector<std::string>& params) {
Paul's avatar
Paul committed
198
199
200
201
202
                                 if(params.empty())
                                     throw std::runtime_error("Flag with no value.");
                                 x = value_parser<T>::apply(params.back());
                                 return false;
                             }});
Paul's avatar
Paul committed
203

kahmed10's avatar
kahmed10 committed
204
        argument& arg = arguments.back();
205
        arg.type      = type_name<T>::apply();
Paul's avatar
Paul committed
206
        migraphx::each_args([&](auto f) { f(x, arg); }, fs...);
kahmed10's avatar
kahmed10 committed
207
208
        if(not arg.default_value.empty() and arg.nargs > 0)
            arg.default_value = as_string_value(x);
Paul's avatar
Paul committed
209
210
    }

Paul's avatar
Paul committed
211
    template <class... Fs>
Paul's avatar
Paul committed
212
    void operator()(std::nullptr_t x, std::vector<std::string> flags, Fs... fs)
Paul's avatar
Paul committed
213
    {
Paul's avatar
Paul committed
214
        arguments.push_back({std::move(flags)});
Paul's avatar
Paul committed
215
216
217

        argument& arg = arguments.back();
        arg.type      = "";
Paul's avatar
Paul committed
218
        arg.nargs     = 0;
Paul's avatar
Paul committed
219
220
221
        migraphx::each_args([&](auto f) { f(x, arg); }, fs...);
    }

Paul's avatar
Paul committed
222
    MIGRAPHX_DRIVER_STATIC auto nargs(unsigned n = 1)
Paul's avatar
Paul committed
223
    {
Paul's avatar
Paul committed
224
        return [=](auto&&, auto& arg) { arg.nargs = n; };
Paul's avatar
Paul committed
225
226
    }

Paul's avatar
Paul committed
227
    template <class F>
Paul's avatar
Paul committed
228
    MIGRAPHX_DRIVER_STATIC auto write_action(F f)
Paul's avatar
Paul committed
229
230
    {
        return [=](auto& x, auto& arg) {
Paul's avatar
Paul committed
231
            arg.action = [&, f](auto& self, const std::vector<std::string>& params) {
Paul's avatar
Paul committed
232
233
234
235
236
237
                f(self, x, params);
                return false;
            };
        };
    }

Paul's avatar
Paul committed
238
    template <class F>
Paul's avatar
Paul committed
239
    MIGRAPHX_DRIVER_STATIC auto do_action(F f)
Paul's avatar
Paul committed
240
241
    {
        return [=](auto&, auto& arg) {
Paul's avatar
Paul committed
242
            arg.nargs  = 0;
Paul's avatar
Paul committed
243
            arg.action = [&, f](auto& self, const std::vector<std::string>&) {
Paul's avatar
Paul committed
244
245
246
247
248
249
                f(self);
                return true;
            };
        };
    }

Paul's avatar
Paul committed
250
    MIGRAPHX_DRIVER_STATIC auto append()
Paul's avatar
Paul committed
251
    {
Paul's avatar
Paul committed
252
        return write_action([](auto&, auto& x, auto& params) {
Paul's avatar
Paul committed
253
            using type = typename bare<decltype(params)>::value_type;
Paul's avatar
Paul committed
254
            std::transform(params.begin(),
Paul's avatar
Paul committed
255
256
                           params.end(),
                           std::inserter(x, x.end()),
Paul's avatar
Paul committed
257
258
                           [](std::string y) { return value_parser<type>::apply(y); });
        });
Paul's avatar
Paul committed
259
260
    }

Paul's avatar
Format  
Paul committed
261
    template <class F>
Paul's avatar
Paul committed
262
263
264
    argument* find_argument(F f)
    {
        auto it = std::find_if(arguments.begin(), arguments.end(), f);
Paul's avatar
Format  
Paul committed
265
        if(it == arguments.end())
Paul's avatar
Paul committed
266
267
268
            return nullptr;
        return std::addressof(*it);
    }
Paul's avatar
Paul committed
269
270
271
272
273
    template <class F>
    bool has_argument(F f)
    {
        return find_argument(f) != nullptr;
    }
Paul's avatar
Paul committed
274

Paul's avatar
Paul committed
275
    MIGRAPHX_DRIVER_STATIC auto show_help(const std::string& msg = "")
Paul's avatar
Paul committed
276
    {
Paul's avatar
Paul committed
277
        return do_action([=](auto& self) {
Paul's avatar
Format  
Paul committed
278
279
            argument* input_argument =
                self.find_argument([](const auto& arg) { return arg.flags.empty(); });
Paul's avatar
Paul committed
280
281
            std::cout << color::fg_yellow << "USAGE:" << color::reset << std::endl;
            std::cout << "    " << self.exe_name << " <options> ";
Paul's avatar
Format  
Paul committed
282
            if(input_argument)
Paul's avatar
Paul committed
283
                std::cout << input_argument->metavar;
Paul's avatar
Paul committed
284
285
            std::cout << std::endl;
            std::cout << std::endl;
Paul's avatar
Format  
Paul committed
286
            if(self.find_argument([](const auto& arg) { return arg.nargs == 0; }))
Paul's avatar
Paul committed
287
            {
Paul's avatar
Paul committed
288
                std::cout << color::fg_yellow << "FLAGS:" << color::reset << std::endl;
Paul's avatar
Paul committed
289
                std::cout << std::endl;
Paul's avatar
Paul committed
290
                for(auto&& arg : self.arguments)
Paul's avatar
Paul committed
291
                {
Paul's avatar
Paul committed
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
                    if(arg.nargs != 0)
                        continue;
                    const int col_align = 35;
                    std::string prefix  = "    ";
                    int len             = 0;
                    std::cout << color::fg_green;
                    for(const std::string& a : arg.flags)
                    {
                        len += prefix.length() + a.length();
                        std::cout << prefix;
                        std::cout << a;
                        prefix = ", ";
                    }
                    std::cout << color::reset;
                    int spaces = col_align - len;
                    if(spaces < 0)
                    {
                        std::cout << std::endl;
                    }
                    else
                    {
                        for(int i = 0; i < spaces; i++)
                            std::cout << " ";
                    }
                    std::cout << arg.help << std::endl;
Paul's avatar
Paul committed
317
                }
Paul's avatar
Paul committed
318
319
                std::cout << std::endl;
            }
Paul's avatar
Format  
Paul committed
320
            if(self.find_argument([](const auto& arg) { return arg.nargs != 0; }))
Paul's avatar
Paul committed
321
322
323
            {
                std::cout << color::fg_yellow << "OPTIONS:" << color::reset << std::endl;
                for(auto&& arg : self.arguments)
Paul's avatar
Paul committed
324
                {
Paul's avatar
Paul committed
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
                    if(arg.nargs == 0)
                        continue;
                    std::cout << std::endl;
                    std::string prefix = "    ";
                    std::cout << color::fg_green;
                    if(arg.flags.empty())
                    {
                        std::cout << prefix;
                        std::cout << arg.metavar;
                    }
                    for(const std::string& a : arg.flags)
                    {
                        std::cout << prefix;
                        std::cout << a;
                        prefix = ", ";
                    }
                    std::cout << color::reset;
                    if(not arg.type.empty())
                    {
                        std::cout << " [" << color::fg_blue << arg.type << color::reset << "]";
                        if(not arg.default_value.empty())
                            std::cout << " (Default: " << arg.default_value << ")";
                    }
                    std::cout << std::endl;
                    std::cout << "        " << arg.help << std::endl;
Paul's avatar
Paul committed
350
                }
Paul's avatar
Paul committed
351
352
                std::cout << std::endl;
            }
Paul's avatar
Paul committed
353
            if(not msg.empty())
Paul's avatar
Paul committed
354
                std::cout << msg << std::endl;
Paul's avatar
Paul committed
355
356
357
        });
    }

Paul's avatar
Paul committed
358
    MIGRAPHX_DRIVER_STATIC auto help(const std::string& help)
Paul's avatar
Paul committed
359
    {
Paul's avatar
Paul committed
360
        return [=](auto&, auto& arg) { arg.help = help; };
Paul's avatar
Paul committed
361
362
    }

Paul's avatar
Paul committed
363
    MIGRAPHX_DRIVER_STATIC auto metavar(const std::string& metavar)
Paul's avatar
Paul committed
364
365
366
367
    {
        return [=](auto&, auto& arg) { arg.metavar = metavar; };
    }

368
369
370
371
372
    MIGRAPHX_DRIVER_STATIC auto type(const std::string& type)
    {
        return [=](auto&, auto& arg) { arg.type = type; };
    }

Paul's avatar
Paul committed
373
    template <class T>
Paul's avatar
Paul committed
374
    MIGRAPHX_DRIVER_STATIC auto set_value(T value)
Paul's avatar
Paul committed
375
376
    {
        return [=](auto& x, auto& arg) {
Paul's avatar
Paul committed
377
            arg.nargs  = 0;
Paul's avatar
Paul committed
378
            arg.type   = "";
Paul's avatar
Paul committed
379
            arg.action = [&, value](auto&, const std::vector<std::string>&) {
Paul's avatar
Paul committed
380
381
382
383
384
385
                x = value;
                return false;
            };
        };
    }

Paul's avatar
Format  
Paul committed
386
    template <class T>
387
388
    void set_exe_name_to(T& x)
    {
Paul's avatar
Paul committed
389
        actions.push_back([&](const auto& self) { x = self.exe_name; });
390
391
    }

Paul's avatar
Paul committed
392
393
394
395
396
397
398
399
400
401
402
403
404
405
    void print_usage_for(const argument& arg, const std::string& flag) const
    {
        std::cout << color::fg_yellow << "USAGE:" << color::reset << std::endl;
        std::cout << "    " << exe_name << " ";
        std::cout << flag;
        if(not arg.type.empty())
            std::cout << " [" << arg.type << "]";
        std::cout << std::endl;
    }

    auto spellcheck(const std::vector<std::string>& inputs)
    {
        struct result_t
        {
Paul's avatar
Format  
Paul committed
406
407
408
            const argument* arg     = nullptr;
            std::string correct     = "";
            std::string incorrect   = "";
Paul's avatar
Paul committed
409
410
411
            std::ptrdiff_t distance = std::numeric_limits<std::ptrdiff_t>::max();
        };
        result_t result;
Paul's avatar
Format  
Paul committed
412
        for(const auto& input : inputs)
Paul's avatar
Paul committed
413
        {
Paul's avatar
Format  
Paul committed
414
            if(input.empty())
Paul's avatar
Paul committed
415
                continue;
Paul's avatar
Format  
Paul committed
416
            if(input[0] != '-')
Paul's avatar
Paul committed
417
                continue;
Paul's avatar
Format  
Paul committed
418
            for(const auto& arg : arguments)
Paul's avatar
Paul committed
419
            {
Paul's avatar
Format  
Paul committed
420
                for(const auto& flag : arg.flags)
Paul's avatar
Paul committed
421
                {
Paul's avatar
Format  
Paul committed
422
                    if(flag.empty())
Paul's avatar
Paul committed
423
                        continue;
Paul's avatar
Format  
Paul committed
424
                    if(flag[0] != '-')
Paul's avatar
Paul committed
425
                        continue;
Paul's avatar
Format  
Paul committed
426
427
428
                    auto d =
                        levenshtein_distance(flag.begin(), flag.end(), input.begin(), input.end());
                    if(d < result.distance)
Paul's avatar
Paul committed
429
430
431
432
433
434
435
                        result = result_t{&arg, flag, input, d};
                }
            }
        }
        return result;
    }

Paul's avatar
Format  
Paul committed
436
437
    bool
    run_action(const argument& arg, const std::string& flag, const std::vector<std::string>& inputs)
Paul's avatar
Paul committed
438
439
440
441
442
443
444
445
446
447
448
449
450
451
    {
        std::string msg = "";
        try
        {
            return arg.action(*this, inputs);
        }
        catch(const std::exception& e)
        {
            msg = e.what();
        }
        catch(...)
        {
            msg = "unknown exception";
        }
Paul's avatar
Paul committed
452
453
454
455
        std::cout << color::fg_red << color::bold << "error: " << color::reset;
        auto sc = spellcheck(inputs);
        std::cout << sc.distance << std::endl;
        std::cout << sc.correct << std::endl;
Paul's avatar
Format  
Paul committed
456
        if(sc.distance < 5)
Paul's avatar
Paul committed
457
458
459
460
        {
            std::cout << "Found argument '" << color::fg_yellow << sc.incorrect << "'";
            std::cout << " which wasn't expected, or isn't valid in this context" << std::endl;
            std::cout << "       ";
Paul's avatar
Format  
Paul committed
461
462
            std::cout << "Did you mean " << color::fg_green << sc.correct << color::reset << "?"
                      << std::endl;
Paul's avatar
Paul committed
463
464
465
466
467
468
            std::cout << std::endl;
            print_usage_for(*sc.arg, sc.correct);
        }
        else
        {
            std::cout << "Invalid input to '" << color::fg_yellow;
Paul's avatar
Paul committed
469
470
471
            std::cout << flag;
            if(not arg.type.empty())
                std::cout << " [" << arg.type << "]";
Paul's avatar
Paul committed
472
473
474
475
476
            std::cout << color::reset << "'" << std::endl;
            std::cout << "       " << msg << std::endl;
            std::cout << std::endl;
            print_usage_for(arg, flag);
        }
Paul's avatar
Paul committed
477
        std::cout << std::endl;
Paul's avatar
Paul committed
478
        if(has_argument([](const auto& a) { return contains(a.flags, "--help"); }))
Paul's avatar
Paul committed
479
480
        {
            std::cout << std::endl;
Paul's avatar
Format  
Paul committed
481
482
            std::cout << "For more information try '" << color::fg_green << "--help" << color::reset
                      << "'" << std::endl;
Paul's avatar
Paul committed
483
484
485
486
        }
        return true;
    }

Paul's avatar
Paul committed
487
    bool parse(std::vector<std::string> args)
Paul's avatar
Paul committed
488
    {
Paul's avatar
Paul committed
489
        std::unordered_map<std::string, unsigned> keywords;
Paul's avatar
Paul committed
490
        for(auto&& arg : arguments)
Paul's avatar
Paul committed
491
        {
Paul's avatar
Paul committed
492
            for(auto&& flag : arg.flags)
Paul's avatar
Paul committed
493
                keywords[flag] = arg.nargs + 1;
Paul's avatar
Paul committed
494
        }
Paul's avatar
Paul committed
495
496
        auto arg_map =
            generic_parse(std::move(args), [&](const std::string& x) { return keywords[x]; });
Paul's avatar
Paul committed
497
        for(auto&& arg : arguments)
Paul's avatar
Paul committed
498
        {
Paul's avatar
Paul committed
499
            auto flags = arg.flags;
Paul's avatar
Paul committed
500
            if(flags.empty())
Paul's avatar
Paul committed
501
                flags = {""};
Paul's avatar
Paul committed
502
            for(auto&& flag : flags)
Paul's avatar
Paul committed
503
            {
Paul's avatar
Paul committed
504
                if(arg_map.count(flag) > 0)
Paul's avatar
Paul committed
505
                {
Paul's avatar
Paul committed
506
                    if(run_action(arg, flag, arg_map[flag]))
Paul's avatar
Paul committed
507
                        return true;
Paul's avatar
Paul committed
508
509
510
                }
            }
        }
Paul's avatar
Format  
Paul committed
511
        for(auto&& action : actions)
512
            action(*this);
Paul's avatar
Paul committed
513
        return false;
Paul's avatar
Paul committed
514
515
    }

Paul's avatar
Format  
Paul committed
516
    void set_exe_name(const std::string& s) { exe_name = s; }
Paul's avatar
Paul committed
517

Paul's avatar
Format  
Paul committed
518
    const std::string& get_exe_name() const { return exe_name; }
Paul's avatar
Paul committed
519

Paul's avatar
Paul committed
520
521
522
523
524
525
526
    using string_map = std::unordered_map<std::string, std::vector<std::string>>;
    template <class IsKeyword>
    static string_map generic_parse(std::vector<std::string> as, IsKeyword is_keyword)
    {
        string_map result;

        std::string flag;
Paul's avatar
Paul committed
527
        bool clear = false;
Paul's avatar
Paul committed
528
529
        for(auto&& x : as)
        {
Paul's avatar
Paul committed
530
531
            auto k = is_keyword(x);
            if(k > 0)
Paul's avatar
Paul committed
532
533
534
            {
                flag = x;
                result[flag]; // Ensure the flag exists
Paul's avatar
Paul committed
535
                if(k == 1)
Paul's avatar
Paul committed
536
                    flag = "";
Paul's avatar
Paul committed
537
                else if(k == 2)
Paul's avatar
Paul committed
538
539
540
                    clear = true;
                else
                    clear = false;
Paul's avatar
Paul committed
541
542
543
544
            }
            else
            {
                result[flag].push_back(x);
Paul's avatar
Paul committed
545
                if(clear)
Paul's avatar
Paul committed
546
547
                    flag = "";
                clear = false;
Paul's avatar
Paul committed
548
549
550
551
            }
        }
        return result;
    }
Paul's avatar
Paul committed
552

Paul's avatar
Paul committed
553
    private:
Paul's avatar
Paul committed
554
555
    std::list<argument> arguments;
    std::string exe_name = "";
556
    std::vector<std::function<void(argument_parser&)>> actions;
Paul's avatar
Paul committed
557
558
};

Paul's avatar
Paul committed
559
560
561
562
} // namespace MIGRAPHX_INLINE_NS
} // namespace driver
} // namespace migraphx

Paul's avatar
Paul committed
563
#endif