Skip to content

Commit bf24e83

Browse files
committed
feat: Implement loading of extensions from config files....
调整了一下
1 parent ef0a753 commit bf24e83

1 file changed

Lines changed: 54 additions & 33 deletions

File tree

apps/ll-cli/src/main.cpp

Lines changed: 54 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -656,36 +656,42 @@ linglong::utils::error::Result<linglong::repo::OSTreeRepo *> initOSTreeRepo()
656656
// ===== begin: ll-cli config helpers =====
657657
using json = nlohmann::json;
658658

659-
static constexpr const char kConfigUsageLines[] =
660-
" ll-cli config set-extensions [--global | <appid> | --base <baseid>] ext1,ext2\n"
661-
" ll-cli config add-extensions [--global | <appid> | --base <baseid>] ext1,ext2\n"
662-
" ll-cli config set-env [--global | <appid> | --base <baseid>] KEY=VAL [KEY=VAL ...]\n"
663-
" ll-cli config unset-env [--global | <appid> | --base <baseid>] KEY [KEY ...]\n"
664-
" ll-cli config add-fs [--global | <appid> | --base <baseid>] --host PATH --target "
665-
"PATH [--mode ro|rw] [--persist]\n"
666-
" ll-cli config rm-fs [--global | <appid> | --base <baseid>] (--target PATH | "
667-
"--index N)\n"
668-
" ll-cli config add-fs-allow [--global | <appid> | --base <baseid>] --host PATH --target "
669-
"PATH [--mode ro|rw] [--persist]\n"
670-
" ll-cli config rm-fs-allow [--global | <appid> | --base <baseid>] (--target PATH | "
671-
"--index N)\n"
672-
" ll-cli config clear-fs-allow [--global | <appid> | --base <baseid>]\n"
673-
" ll-cli config set-command [--global | <appid> | --base <baseid>] <cmd> [--entrypoint P] "
674-
"[--cwd D] [--args-prefix \"...\"] [--args-suffix \"...\"] [KEY=VAL ...]\n"
675-
" ll-cli config unset-command [--global | <appid> | --base <baseid>] <cmd>\n";
676-
677-
static constexpr const char kConfigShortHelp[] =
678-
"Configuration commands:\n"
679-
" config Manage ll-cli configuration (see `ll-cli config --help`)\n";
680-
681-
static constexpr const char kFooterMessage[] =
682-
"If you found any problems during use,\n"
683-
"You can report bugs to the linyaps team under this project: https://github.com/OpenAtom-Linyaps/"
684-
"linyaps/issues";
659+
static std::string configUsageLines()
660+
{
661+
return std::string{
662+
_(" ll-cli config set-extensions [--global | <appid> | --base <baseid>] ext1,ext2\n"
663+
" ll-cli config add-extensions [--global | <appid> | --base <baseid>] ext1,ext2\n"
664+
" ll-cli config set-env [--global | <appid> | --base <baseid>] KEY=VAL [KEY=VAL ...]\n"
665+
" ll-cli config unset-env [--global | <appid> | --base <baseid>] KEY [KEY ...]\n"
666+
" ll-cli config add-fs [--global | <appid> | --base <baseid>] --host PATH --target PATH [--mode "
667+
"ro|rw] [--persist]\n"
668+
" ll-cli config rm-fs [--global | <appid> | --base <baseid>] (--target PATH | --index N)\n"
669+
" ll-cli config add-fs-allow [--global | <appid> | --base <baseid>] --host PATH --target PATH [--mode "
670+
"ro|rw] [--persist]\n"
671+
" ll-cli config rm-fs-allow [--global | <appid> | --base <baseid>] (--target PATH | --index N)\n"
672+
" ll-cli config clear-fs-allow [--global | <appid> | --base <baseid>]\n"
673+
" ll-cli config set-command [--global | <appid> | --base <baseid>] <cmd> [--entrypoint P] [--cwd D] "
674+
"[--args-prefix \"...\"] [--args-suffix \"...\"] [KEY=VAL ...]\n"
675+
" ll-cli config unset-command [--global | <appid> | --base <baseid>] <cmd>\n") };
676+
}
677+
678+
static std::string configShortHelp()
679+
{
680+
return std::string{ _("Configuration commands:\n"
681+
" config Manage ll-cli configuration (see `ll-cli config --help`)\n") };
682+
}
683+
684+
static std::string configFooterMessage()
685+
{
686+
return std::string{ _("If you found any problems during use,\n"
687+
"You can report bugs to the linyaps team under this project: "
688+
"https://github.com/OpenAtom-Linyaps/linyaps/issues") };
689+
}
685690

686691
static void printConfigUsage(FILE *stream = stderr)
687692
{
688-
std::fprintf(stream, "Usage:\n%s", kConfigUsageLines);
693+
auto usageLines = configUsageLines();
694+
std::fprintf(stream, "%s\n%s", _("Usage:"), usageLines.c_str());
689695
}
690696

691697
enum class Scope { Global, App, Base };
@@ -1498,18 +1504,33 @@ int runCliApplication(int argc, char **mainArgv)
14981504
CLI::App commandParser{ _(
14991505
"linyaps CLI\n"
15001506
"A CLI program to run application and manage application and runtime\n") };
1501-
commandParser.formatter(std::make_shared<ConfigAwareFormatter>(kConfigShortHelp,
1502-
std::string("Configuration commands:\n")
1503-
+ kConfigUsageLines,
1504-
_(kFooterMessage)));
1507+
auto shortConfigHelp = configShortHelp();
1508+
auto fullConfigHelp = shortConfigHelp + configUsageLines();
1509+
commandParser.formatter(std::make_shared<ConfigAwareFormatter>(shortConfigHelp,
1510+
fullConfigHelp,
1511+
configFooterMessage()));
1512+
commandParser.option_defaults()->group(_("Options"));
1513+
if (auto formatter = commandParser.get_formatter()) {
1514+
formatter->label("OPTIONS", _("OPTIONS"));
1515+
formatter->label("SUBCOMMAND", _("SUBCOMMAND"));
1516+
formatter->label("SUBCOMMANDS", _("SUBCOMMANDS"));
1517+
formatter->label("POSITIONALS", _("POSITIONALS"));
1518+
formatter->label("Usage", _("Usage"));
1519+
formatter->label("REQUIRED", _("REQUIRED"));
1520+
}
15051521
auto argv = commandParser.ensure_utf8(mainArgv);
15061522
if (argc == 1) {
15071523
std::cout << commandParser.help() << std::endl;
15081524
return 0;
15091525
}
15101526

1511-
commandParser.get_help_ptr()->description(_("Print this help message and exit"));
1512-
commandParser.set_help_all_flag("--help-all", _("Expand all help"));
1527+
if (auto *helpOption = commandParser.get_help_ptr()) {
1528+
helpOption->description(_("Print this help message and exit"));
1529+
helpOption->group(_("Options"));
1530+
}
1531+
if (auto *helpAllOption = commandParser.set_help_all_flag("--help-all", _("Expand all help"))) {
1532+
helpAllOption->group(_("Options"));
1533+
}
15131534
commandParser.usage(_("Usage: ll-cli [OPTIONS] [SUBCOMMAND]"));
15141535
commandParser.footer("");
15151536

0 commit comments

Comments
 (0)