shell: merge ibs into ib -a
This commit is contained in:
parent
dffc3c7b02
commit
b0911cb092
104
shell/i.cpp
104
shell/i.cpp
|
@ -51,54 +51,41 @@ static void show_binary_short(
|
|||
show_vspace(b.vspace());
|
||||
}
|
||||
|
||||
|
||||
void _ib(Session &session)
|
||||
struct _ib_args
|
||||
{
|
||||
// TODO: Factor these errors into Session.
|
||||
Binary *b = session.currentBinary();
|
||||
if(!b) {
|
||||
FxOS_log(ERR, "No current binary!");
|
||||
return;
|
||||
bool show_all = false;
|
||||
std::string binary_name;
|
||||
Binary *binary = nullptr;
|
||||
};
|
||||
|
||||
static struct _ib_args parse_ib(Session &session, Parser &parser)
|
||||
{
|
||||
_ib_args args;
|
||||
args.binary_name = session.currentBinaryName();
|
||||
|
||||
parser.option("-b",
|
||||
[&args](Parser &p) { args.binary_name = p.symbol("binary_name"); });
|
||||
parser.option("-a", [&args](Parser &) { args.show_all = true; });
|
||||
parser.accept_options();
|
||||
|
||||
args.binary = session.project().getBinary(args.binary_name);
|
||||
if(!args.binary) {
|
||||
std::string msg
|
||||
= fmt::format("No binary “{}” in project!", args.binary_name);
|
||||
if(parser.completing())
|
||||
throw Parser::CompletionRequest("_error", msg);
|
||||
else
|
||||
FxOS_log(ERR, "%s", msg.c_str());
|
||||
}
|
||||
|
||||
show_binary_short(session.currentBinaryName(), true, *b);
|
||||
// TODO: Show more binary information
|
||||
}
|
||||
|
||||
//---
|
||||
// ibs
|
||||
//---
|
||||
|
||||
std::vector<std::string> parse_ibs(Session &, Parser &parser)
|
||||
{
|
||||
std::vector<std::string> args;
|
||||
|
||||
while(!parser.at_end())
|
||||
args.push_back(parser.symbol("binary_name"));
|
||||
|
||||
parser.end();
|
||||
return args;
|
||||
}
|
||||
|
||||
void _ibs(Session &session, std::vector<std::string> const &args)
|
||||
void _ib(Session &session, struct _ib_args const &args)
|
||||
{
|
||||
bool first = true;
|
||||
|
||||
for(auto const &name: args) {
|
||||
if(!first)
|
||||
fmt::print("\n");
|
||||
else
|
||||
first = false;
|
||||
|
||||
Binary *b = session.project().getBinary(name);
|
||||
if(b)
|
||||
show_binary_short(name, name == session.currentBinaryName(), *b);
|
||||
else
|
||||
FxOS_log(
|
||||
ERR, "No binary named “%s” in current project!", name.c_str());
|
||||
}
|
||||
|
||||
if(!args.size()) {
|
||||
if(args.show_all) {
|
||||
bool first = true;
|
||||
for(auto const &[name, b]: session.project().binaries()) {
|
||||
if(!first)
|
||||
fmt::print("\n");
|
||||
|
@ -108,6 +95,12 @@ void _ibs(Session &session, std::vector<std::string> const &args)
|
|||
show_binary_short(name, name == session.currentBinaryName(), b);
|
||||
}
|
||||
}
|
||||
else {
|
||||
bool current = (args.binary_name == session.currentBinaryName());
|
||||
show_binary_short(args.binary_name, current, *args.binary);
|
||||
}
|
||||
|
||||
// TODO: Show more binary information
|
||||
}
|
||||
|
||||
//---
|
||||
|
@ -175,8 +168,8 @@ static struct _io_args parse_io(Session &session, Parser &parser)
|
|||
_io_args args;
|
||||
std::string binname = session.currentBinaryName();
|
||||
|
||||
parser.option("-b",
|
||||
[&binname](Parser &p) { binname = p.symbol("binary_name"); });
|
||||
parser.option(
|
||||
"-b", [&binname](Parser &p) { binname = p.symbol("binary_name"); });
|
||||
parser.accept_options();
|
||||
|
||||
args.binary = session.project().getBinary(binname);
|
||||
|
@ -281,8 +274,8 @@ static char const *syscall_nonrom_str = " %%%04x -> %08x (%s memory)\n";
|
|||
static std::string parse_ios(Session &, Parser &parser)
|
||||
{
|
||||
std::string binname;
|
||||
parser.option("-b",
|
||||
[&binname](Parser &p) { binname = p.symbol("binary_name"); });
|
||||
parser.option(
|
||||
"-b", [&binname](Parser &p) { binname = p.symbol("binary_name"); });
|
||||
parser.accept_options();
|
||||
parser.end();
|
||||
return binname;
|
||||
|
@ -403,9 +396,8 @@ static struct _isc_args parse_isc(Session &session, Parser &parser)
|
|||
_isc_args args;
|
||||
|
||||
parser.option("-s", [&args](Parser &) { args.sort = true; });
|
||||
parser.option("-b", [&args](Parser &p) {
|
||||
args.binary_name = p.symbol("binary_name");
|
||||
});
|
||||
parser.option("-b",
|
||||
[&args](Parser &p) { args.binary_name = p.symbol("binary_name"); });
|
||||
parser.accept_options();
|
||||
|
||||
Binary *binary = session.currentBinary();
|
||||
|
@ -503,20 +495,12 @@ void _isc(Session &session, std::string binary_name, bool sort,
|
|||
//---
|
||||
|
||||
static ShellCommand _ib_cmd(
|
||||
"ib", [](Session &s, Parser &p) { p.end(), _ib(s); },
|
||||
[](Session &, Parser &p) { p.end(); }, "Info Binary (current)", R"(
|
||||
ib
|
||||
"ib", [](Session &s, Parser &p) { _ib(s, parse_ib(s, p)); },
|
||||
[](Session &s, Parser &p) { parse_ib(s, p); }, "Info Binary", R"(
|
||||
ib [-b <binary> | -a]
|
||||
|
||||
Prints detailed information about the currently-selected binary in the project.
|
||||
)");
|
||||
|
||||
static ShellCommand _ibs_cmd(
|
||||
"ibs", [](Session &s, Parser &p) { _ibs(s, parse_ibs(s, p)); },
|
||||
[](Session &s, Parser &p) { parse_ibs(s, p); }, "Info Binaries", R"(
|
||||
ibs [<binary>...]
|
||||
|
||||
Prints short information about named binaries in the current project. If no
|
||||
argument is specified, prints information about all binaries.
|
||||
Prints detailed information about the current binary, or the one specified with
|
||||
-b, or all if -a is given.
|
||||
)");
|
||||
|
||||
static ShellCommand _if_cmd(
|
||||
|
|
Loading…
Reference in New Issue