diff --git a/src/console.cpp b/src/console.cpp index ca700c819..6c90b9815 100644 --- a/src/console.cpp +++ b/src/console.cpp @@ -76,54 +76,49 @@ static void setup_commands(std::shared_ptr & commands) { // // Show commands // - commands->add_command(ShellContext::MAIN, CommandFlags::USER, {F_(show)}, [=](Shell & shell, const std::vector & arguments) { - to_app(shell).system_.show_system(shell); - }); - commands->add_command(ShellContext::MAIN, - CommandFlags::USER, - string_vector{F_(show), F_(system)}, - [=](Shell & shell, const std::vector & arguments) { to_app(shell).system_.show_system(shell); }); + commands->add_command( + ShellContext::MAIN, + CommandFlags::USER, + {F_(show)}, + {F_(show_commands)}, + [=](Shell & shell, const std::vector & arguments) { + if (arguments.empty()) { + to_app(shell).system_.show_system(shell); + return; + } - commands->add_command(ShellContext::MAIN, - CommandFlags::ADMIN, - string_vector{F_(show), F_(users)}, - [](Shell & shell, const std::vector & arguments) { to_app(shell).system_.show_users(shell); }); - - commands->add_command(ShellContext::MAIN, - CommandFlags::USER, - string_vector{F_(show), F_(devices)}, - [](Shell & shell, const std::vector & arguments) { to_app(shell).show_devices(shell); }); - - commands->add_command(ShellContext::MAIN, CommandFlags::USER, string_vector{F_(show), F_(log)}, [](Shell & shell, const std::vector & arguments) { - to_app(shell).webLogService.show(shell); - }); - - - commands->add_command(ShellContext::MAIN, CommandFlags::USER, string_vector{F_(show), F_(ems)}, [](Shell & shell, const std::vector & arguments) { - to_app(shell).show_ems(shell); - }); - - commands->add_command(ShellContext::MAIN, CommandFlags::USER, string_vector{F_(show), F_(values)}, [](Shell & shell, const std::vector & arguments) { - to_app(shell).show_device_values(shell); - to_app(shell).show_sensor_values(shell); - }); - - commands->add_command(ShellContext::MAIN, - CommandFlags::USER, - string_vector{F_(show), F_(mqtt)}, - [](Shell & shell, const std::vector & arguments) { Mqtt::show_mqtt(shell); }); - - - commands->add_command(ShellContext::MAIN, - CommandFlags::USER, - string_vector{F_(show), F_(commands)}, - [](Shell & shell, const std::vector & arguments) { Command::show_all(shell); }); + auto command = arguments.front(); + if (command == F_(commands)) { + Command::show_all(shell); + } else if (command == F_(system)) { + to_app(shell).system_.show_system(shell); + } else if (command == F_(users) && (shell.has_flags(CommandFlags::ADMIN))) { + to_app(shell).system_.show_users(shell); // admin only + } else if (command == F_(devices)) { + to_app(shell).show_devices(shell); + } else if (command == F_(log)) { + to_app(shell).webLogService.show(shell); + } else if (command == F_(ems)) { + to_app(shell).show_ems(shell); + } else if (command == F_(values)) { + to_app(shell).show_device_values(shell); + to_app(shell).show_sensor_values(shell); + } else if (command == F_(mqtt)) { + Mqtt::show_mqtt(shell); + } else if (command == F_(commands)) { + Command::show_all(shell); + } else { + shell.printfln("Unknown show command"); + } + }, + [](Shell & shell, const std::vector & current_arguments, const std::string & next_argument) -> std::vector { + return std::vector{"system", "users", "devices", "log", "ems", "values", "mqtt", "commands"}; + }); // // System commands // - #if defined(EMSESP_TEST) // create commands test commands->add_command(ShellContext::MAIN, diff --git a/src/locale_common.h b/src/locale_common.h index 97fb49ff0..08a65d68c 100644 --- a/src/locale_common.h +++ b/src/locale_common.h @@ -154,6 +154,7 @@ MAKE_WORD_CUSTOM(deviceid_mandatory, "") MAKE_WORD_CUSTOM(device_type_optional, "[device]") MAKE_WORD_CUSTOM(invalid_log_level, "Invalid log level") MAKE_WORD_CUSTOM(log_level_optional, "[level]") +MAKE_WORD_CUSTOM(show_commands, "[system | users | devices | log | ems | values | mqtt | commands") MAKE_WORD_CUSTOM(name_mandatory, "") MAKE_WORD_CUSTOM(name_optional, "[name]") MAKE_WORD_CUSTOM(new_password_prompt1, "Enter new password: ") diff --git a/src/locale_translations.h b/src/locale_translations.h index 2fbbc0ec9..55a49b86c 100644 --- a/src/locale_translations.h +++ b/src/locale_translations.h @@ -63,7 +63,7 @@ MAKE_WORD_TRANSLATION(info_cmd, "list all values (verbose)", "Liste aller Werte" MAKE_WORD_TRANSLATION(commands_cmd, "list all commands", "Liste aller Kommandos", "lijst van alle commando's", "", "wyświetl wszystkie komendy", "Viser alle kommandoer", "", "Tüm komutları listele", "elencaa tutti i comandi", "zobraziť všetky príkazy") // TODO translate MAKE_WORD_TRANSLATION(entities_cmd, "list all entities", "Liste aller Entitäten", "lijst van alle entiteiten", "", "wyświetl wszsytkie encje", "Viser alle enheter", "", "Tüm varlıkları listele", "elenca tutte le entità", "zobraziť všetky entity") // TODO translate MAKE_WORD_TRANSLATION(send_cmd, "send a telegram", "Sende EMS-Telegramm", "stuur een telegram", "", "wyślij telegram", "send et telegram", "", "Bir telegram gönder", "invia un telegramma", "poslať telegram") // TODO translate -MAKE_WORD_TRANSLATION(setiovalue_cmd, "set io value", "Setze Werte E/A", "instellen standaardwaarde", "", "ustaw wartość", "sett en io verdi", "", "Giriş/Çıkış değerlerini ayarla", "imposta valore io", "nastaviť hodnotu io") // TODO translate +MAKE_WORD_TRANSLATION(setiovalue_cmd, "set I/O value", "Setze Werte E/A", "instellen standaardwaarde", "", "ustaw wartość", "sett en io verdi", "", "Giriş/Çıkış değerlerini ayarla", "imposta valore io", "nastaviť hodnotu io") // TODO translate MAKE_WORD_TRANSLATION(changeloglevel_cmd, "change log level", "Ändere Protokollebene", "aanpassen log niveau", "", "zmień poziom log-u", "endre loggnivå", "", "Kayıt seviyesini değiştir", "cambia livello registrazione", "zmeniť úroveň protokolu") // TODO translate MAKE_WORD_TRANSLATION(fetch_cmd, "refresh all EMS values", "Aktualisiere alle EMS-Werte", "Verversen alle EMS waardes", "", "odśwież wszystkie wartości EMS", "oppfrisk alle EMS verdier", "", "Bütün EMS değerlerini yenile", "aggiornare tutti i valori EMS", "obnoviť všetky hodnoty EMS") // TODO translate MAKE_WORD_TRANSLATION(restart_cmd, "restart EMS-ESP", "Neustart", "opnieuw opstarten", "", "uruchom ponownie EMS-ESP", "restart EMS-ESP", "redémarrer EMS-ESP", "EMS-ESPyi yeniden başlat", "riavvia EMS-ESP", "reštart EMS-ESP") // TODO translate