feat: Add 1 and update 3 files
This commit is contained in:
@@ -71,7 +71,7 @@ fi
|
||||
# GPU list (may have 0, 1, or multiple)
|
||||
GPU_JSON="[]"
|
||||
if command -v lspci &>/dev/null; then
|
||||
GPU_LINES=$(lspci 2>/dev/null | grep -i 'vga\|3d\|display' | sed 's/^[^ ]* //; s/VGA compatible controller: //; s/3D controller: //; s/Display controller: //' || true)
|
||||
GPU_LINES=$(lspci 2>/dev/null | grep -i 'VGA compatible controller\|3D controller\|Display controller' | sed 's/^[^ ]* //; s/VGA compatible controller: //; s/3D controller: //; s/Display controller: //' || true)
|
||||
if [ -n "$GPU_LINES" ]; then
|
||||
GPU_JSON="["
|
||||
first=true
|
||||
|
||||
56
source/src/commands/list-templates.cpp
Normal file
56
source/src/commands/list-templates.cpp
Normal file
@@ -0,0 +1,56 @@
|
||||
#include "command_registry.hpp"
|
||||
#include "templates.hpp"
|
||||
#include "utils/output.hpp"
|
||||
#include "tableprint.hpp"
|
||||
|
||||
namespace dropshell {
|
||||
|
||||
int list_templates_handler(const CommandContext &ctx);
|
||||
|
||||
static std::vector<std::string> list_templates_name_list = {"list-templates", "ls-templates", "templates"};
|
||||
|
||||
void list_templates_autocomplete(const CommandContext &ctx) {
|
||||
// no arguments
|
||||
}
|
||||
|
||||
struct ListTemplatesCommandRegister {
|
||||
ListTemplatesCommandRegister() {
|
||||
CommandRegistry::instance().register_command({
|
||||
list_templates_name_list,
|
||||
list_templates_handler,
|
||||
list_templates_autocomplete,
|
||||
false, // hidden
|
||||
true, // requires_config
|
||||
true, // requires_install
|
||||
0, // min_args
|
||||
0, // max_args
|
||||
"list-templates",
|
||||
"List all available templates and their sources.",
|
||||
R"(
|
||||
List all available templates from configured local paths and registries.
|
||||
list-templates Show template names and where they come from.
|
||||
)"
|
||||
});
|
||||
}
|
||||
} list_templates_command_register;
|
||||
|
||||
int list_templates_handler(const CommandContext &ctx) {
|
||||
auto templates = gTemplateManager().get_template_list_with_source();
|
||||
|
||||
if (templates.empty()) {
|
||||
info << "No templates found." << std::endl;
|
||||
return 0;
|
||||
}
|
||||
|
||||
tableprint tp("Available Templates");
|
||||
tp.add_row({"Template", "Source"});
|
||||
|
||||
for (const auto &[name, source] : templates)
|
||||
tp.add_row({name, source});
|
||||
|
||||
tp.sort({1, 0});
|
||||
tp.print();
|
||||
return 0;
|
||||
}
|
||||
|
||||
} // namespace dropshell
|
||||
@@ -440,6 +440,21 @@
|
||||
return templates;
|
||||
}
|
||||
|
||||
std::vector<std::pair<std::string, std::string>> template_manager::get_template_list_with_source() const
|
||||
{
|
||||
ASSERT(mLoaded && mSources.size() > 0, "Template manager not loaded, or no template sources found.");
|
||||
std::vector<std::pair<std::string, std::string>> result;
|
||||
std::set<std::string> seen;
|
||||
for (const auto& source : mSources) {
|
||||
auto source_templates = source->get_template_list();
|
||||
for (const auto& t : source_templates) {
|
||||
if (seen.insert(t).second)
|
||||
result.push_back({t, source->get_description()});
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
bool template_manager::has_template(const std::string &template_name) const
|
||||
{
|
||||
ASSERT(mLoaded && mSources.size() > 0, "Template manager not loaded, or no template sources found.");
|
||||
|
||||
@@ -97,6 +97,7 @@ class template_manager {
|
||||
static bool check_template_shell_scripts_syntax(const std::string& template_path);
|
||||
|
||||
void list_templates() const;
|
||||
std::vector<std::pair<std::string, std::string>> get_template_list_with_source() const;
|
||||
|
||||
void load_sources();
|
||||
void print_sources() const;
|
||||
|
||||
Reference in New Issue
Block a user