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
6cfe98a5
Commit
6cfe98a5
authored
Jun 21, 2022
by
Paul
Browse files
Improve error with incorrect order for command
parent
91523467
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
32 additions
and
3 deletions
+32
-3
src/driver/argument_parser.hpp
src/driver/argument_parser.hpp
+11
-0
src/driver/main.cpp
src/driver/main.cpp
+21
-3
No files found.
src/driver/argument_parser.hpp
View file @
6cfe98a5
...
...
@@ -377,6 +377,14 @@ struct argument_parser
};
}
template
<
class
T
>
void
set_exe_name_to
(
T
&
x
)
{
actions
.
push_back
([
&
](
auto
&
self
)
{
x
=
self
.
exe_name
;
});
}
bool
run_action
(
const
argument
&
arg
,
const
std
::
string
&
flag
,
const
std
::
vector
<
std
::
string
>&
inputs
)
{
...
...
@@ -441,6 +449,8 @@ struct argument_parser
}
}
}
for
(
auto
&&
action
:
actions
)
action
(
*
this
);
return
false
;
}
...
...
@@ -484,6 +494,7 @@ struct argument_parser
private:
std
::
list
<
argument
>
arguments
;
std
::
string
exe_name
=
""
;
std
::
vector
<
std
::
function
<
void
(
argument_parser
&
)
>>
actions
;
};
}
// namespace MIGRAPHX_INLINE_NS
...
...
src/driver/main.cpp
View file @
6cfe98a5
...
...
@@ -570,7 +570,7 @@ struct main_command
{
std
::
string
version_str
=
"MIGraphX Version: "
+
std
::
to_string
(
MIGRAPHX_VERSION_MAJOR
)
+
"."
+
std
::
to_string
(
MIGRAPHX_VERSION_MINOR
);
ap
(
unused
,
{},
ap
.
metavar
(
"<command>"
),
ap
.
set_value
(
true
));
ap
(
wrong_commands
,
{},
ap
.
metavar
(
"<command>"
),
ap
.
append
(
));
ap
(
nullptr
,
{
"-h"
,
"--help"
},
ap
.
help
(
"Show help"
),
ap
.
show_help
(
get_command_help
()));
ap
(
nullptr
,
{
"-v"
,
"--version"
},
...
...
@@ -579,14 +579,32 @@ struct main_command
// Trim command off of exe name
ap
.
set_exe_name
(
ap
.
get_exe_name
().
substr
(
0
,
ap
.
get_exe_name
().
size
()
-
5
));
ap
.
set_exe_name_to
(
exe_name
);
}
bool
unused
=
false
;
std
::
vector
<
std
::
string
>
wrong_commands
{};
std
::
string
exe_name
=
"<exe>"
;
void
run
()
{
std
::
cout
<<
color
::
fg_red
<<
color
::
bold
<<
"error: "
<<
color
::
reset
;
std
::
cout
<<
get_command_help
(
"missing command:"
)
<<
std
::
endl
;
auto
it
=
std
::
find_if
(
wrong_commands
.
begin
(),
wrong_commands
.
end
(),
[](
const
auto
&
c
)
{
return
get_commands
().
count
(
c
)
>
0
;
});
if
(
it
==
wrong_commands
.
end
())
{
std
::
cout
<<
"'"
<<
color
::
fg_yellow
<<
wrong_commands
.
front
()
<<
color
::
reset
<<
"' is not a valid command."
<<
std
::
endl
;
std
::
cout
<<
get_command_help
(
"Available commands:"
)
<<
std
::
endl
;
}
else
{
std
::
cout
<<
"command '"
<<
color
::
fg_yellow
<<
*
it
<<
color
::
reset
<<
"' must be first argument"
<<
std
::
endl
;
std
::
cout
<<
std
::
endl
;
std
::
cout
<<
color
::
fg_yellow
<<
"USAGE:"
<<
color
::
reset
<<
std
::
endl
;
std
::
cout
<<
" "
<<
exe_name
<<
" "
<<
*
it
<<
" <options>"
<<
std
::
endl
;
}
std
::
cout
<<
std
::
endl
;
}
};
...
...
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