Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
gaoqiong
MIGraphX
Commits
f83bf5a5
Commit
f83bf5a5
authored
Jun 21, 2022
by
Paul
Browse files
Improve help output
parent
c0398ded
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
73 additions
and
4 deletions
+73
-4
src/driver/argument_parser.hpp
src/driver/argument_parser.hpp
+67
-1
src/driver/main.cpp
src/driver/main.cpp
+6
-3
No files found.
src/driver/argument_parser.hpp
View file @
f83bf5a5
...
@@ -19,6 +19,10 @@
...
@@ -19,6 +19,10 @@
#include <migraphx/stringutils.hpp>
#include <migraphx/stringutils.hpp>
#include <migraphx/rank.hpp>
#include <migraphx/rank.hpp>
#ifndef _WIN32
#include <unistd.h>
#endif
namespace
migraphx
{
namespace
migraphx
{
namespace
driver
{
namespace
driver
{
inline
namespace
MIGRAPHX_INLINE_NS
{
inline
namespace
MIGRAPHX_INLINE_NS
{
...
@@ -51,6 +55,32 @@ template <class T>
...
@@ -51,6 +55,32 @@ template <class T>
using
is_multi_value
=
using
is_multi_value
=
std
::
integral_constant
<
bool
,
(
is_container
<
T
>
{}
and
not
std
::
is_convertible
<
T
,
std
::
string
>
{})
>
;
std
::
integral_constant
<
bool
,
(
is_container
<
T
>
{}
and
not
std
::
is_convertible
<
T
,
std
::
string
>
{})
>
;
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
;
}
template
<
class
T
>
template
<
class
T
>
struct
value_parser
struct
value_parser
{
{
...
@@ -195,10 +225,45 @@ struct argument_parser
...
@@ -195,10 +225,45 @@ struct argument_parser
MIGRAPHX_DRIVER_STATIC
auto
show_help
(
const
std
::
string
&
msg
=
""
)
MIGRAPHX_DRIVER_STATIC
auto
show_help
(
const
std
::
string
&
msg
=
""
)
{
{
return
do_action
([
=
](
auto
&
self
)
{
return
do_action
([
=
](
auto
&
self
)
{
std
::
cout
<<
color
::
fg_yellow
<<
"FLAGS:"
<<
color
::
reset
<<
std
::
endl
;
std
::
cout
<<
std
::
endl
;
for
(
auto
&&
arg
:
self
.
arguments
)
{
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
;
}
std
::
cout
<<
std
::
endl
;
std
::
cout
<<
color
::
fg_yellow
<<
"OPTIONS:"
<<
color
::
reset
<<
std
::
endl
;
for
(
auto
&&
arg
:
self
.
arguments
)
for
(
auto
&&
arg
:
self
.
arguments
)
{
{
if
(
arg
.
nargs
==
0
)
continue
;
std
::
cout
<<
std
::
endl
;
std
::
cout
<<
std
::
endl
;
std
::
string
prefix
=
" "
;
std
::
string
prefix
=
" "
;
std
::
cout
<<
color
::
fg_green
;
if
(
arg
.
flags
.
empty
())
if
(
arg
.
flags
.
empty
())
{
{
std
::
cout
<<
prefix
;
std
::
cout
<<
prefix
;
...
@@ -210,9 +275,10 @@ struct argument_parser
...
@@ -210,9 +275,10 @@ struct argument_parser
std
::
cout
<<
a
;
std
::
cout
<<
a
;
prefix
=
", "
;
prefix
=
", "
;
}
}
std
::
cout
<<
color
::
reset
;
if
(
not
arg
.
type
.
empty
())
if
(
not
arg
.
type
.
empty
())
{
{
std
::
cout
<<
" ["
<<
arg
.
type
<<
"]"
;
std
::
cout
<<
" ["
<<
color
::
fg_blue
<<
arg
.
type
<<
color
::
reset
<<
"]"
;
if
(
not
arg
.
default_value
.
empty
())
if
(
not
arg
.
default_value
.
empty
())
std
::
cout
<<
" (Default: "
<<
arg
.
default_value
<<
")"
;
std
::
cout
<<
" (Default: "
<<
arg
.
default_value
<<
")"
;
}
}
...
...
src/driver/main.cpp
View file @
f83bf5a5
...
@@ -552,9 +552,9 @@ struct onnx : command<onnx>
...
@@ -552,9 +552,9 @@ struct onnx : command<onnx>
struct
main_command
struct
main_command
{
{
static
std
::
string
get_command_help
()
static
std
::
string
get_command_help
(
const
std
::
string
&
title
=
"Commands:"
)
{
{
std
::
string
result
=
"Commands:
\n
"
;
std
::
string
result
=
title
+
"
\n
"
;
return
std
::
accumulate
(
get_commands
().
begin
(),
return
std
::
accumulate
(
get_commands
().
begin
(),
get_commands
().
end
(),
get_commands
().
end
(),
result
,
result
,
...
@@ -571,7 +571,10 @@ struct main_command
...
@@ -571,7 +571,10 @@ struct main_command
ap
.
show_help
(
version_str
));
ap
.
show_help
(
version_str
));
}
}
void
run
()
{}
void
run
()
{
std
::
cout
<<
get_command_help
(
"Missing command:"
)
<<
std
::
endl
;
}
};
};
}
// namespace MIGRAPHX_INLINE_NS
}
// namespace MIGRAPHX_INLINE_NS
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment