download.cpp¶
src/cli/download.cpp
@file download.cpp @brief `entropic download` subcommand — fetch GGUF models to the canonical install path.
Owners: @tvanfossen
dispatch
int entropic::cli::dispatch(const DownloadArgs &args, const entropic::config::BundledModels ®istry)
Handle entropic download subcommand.
src/cli/download.cpp:329
Called by run_download
Calls default_model_dir, fetch_mmproj_if_paired, fetch_to, list_models, resolve_entry, resolve_selector_key
Source · 30 lines
int dispatch(const DownloadArgs& args,
const entropic::config::BundledModels& registry)
{
int rc = 0;
const bool has_selector = !args.family.empty() || !args.size.empty()
|| !args.quant.empty();
if (args.want_list) {
rc = list_models(registry);
} else if (const std::string key = resolve_selector_key(args, registry);
key.empty()) {
if (!has_selector) {
std::fprintf(stderr,
"Usage: entropic download <model-key>\n"
" entropic download --family F --size S --quant Q\n"
" entropic download --list\n"
" entropic download --dir DIR <model-key>\n");
}
rc = 1;
} else if (const auto* entry = resolve_entry(registry, key); !entry) {
rc = 1;
} else {
auto target_dir = args.override_dir.empty()
? default_model_dir() : args.override_dir;
rc = fetch_to(*entry, target_dir, key);
if (rc == 0) {
rc = fetch_mmproj_if_paired(*entry, registry, target_dir);
}
}
return rc;
}Activity · 18 steps
Requirements
fetch_to
int entropic::cli::fetch_to(const entropic::config::BundledModelEntry &entry, const std::filesystem::path &target_dir, const std::string &key)
Download one registry entry to a target directory.
src/cli/download.cpp:248
Source · 36 lines
int fetch_to(const entropic::config::BundledModelEntry& entry,
const std::filesystem::path& target_dir,
const std::string& key)
{
int rc = 0;
std::error_code ec;
std::filesystem::create_directories(target_dir, ec);
auto target_file = target_dir / (entry.name + ".gguf");
const bool already = std::filesystem::exists(target_file)
&& std::filesystem::file_size(target_file) > 0;
if (ec) {
std::fprintf(stderr, "entropic download: cannot create %s: %s\n",
target_dir.c_str(), ec.message().c_str());
rc = 1;
} else if (already) {
std::printf("Model '%s' already at %s — nothing to do.\n",
key.c_str(), target_file.c_str());
} else {
std::printf("Downloading %s (%.1f GB)\n from: %s\n to: %s\n",
entry.name.c_str(), entry.size_gb,
entry.url.c_str(), target_file.c_str());
rc = curl_download(entry.url, target_file);
if (rc != 0) {
std::fprintf(stderr,
"entropic download: curl exited with status %d\n"
"Partial file left at %s — rerun to resume.\n",
rc, target_file.c_str());
} else {
std::printf("\nDone. Point the engine at this dir with:\n"
" export ENTROPIC_MODEL_DIR=%s\n",
target_dir.c_str());
}
}
return rc;
}Activity · 19 steps
Requirements
list_models
int entropic::cli::anonymous_namespace{download.cpp}::list_models(const entropic::config::BundledModels ®istry)Print the registry as a table.
src/cli/download.cpp:62
Source · 10 lines
int list_models(const entropic::config::BundledModels& registry)
{
std::printf("%-12s %-6s %s\n", "KEY", "SIZE", "DESCRIPTION");
std::printf("%-12s %-6s %s\n", "---", "----", "-----------");
for (const auto& [key, entry] : registry.entries()) {
std::printf("%-12s %4.1fGB %s\n",
key.c_str(), entry.size_gb, entry.description.c_str());
}
return 0;
}Activity · 5 steps
Requirements
parse_download_args
DownloadArgs entropic::cli::parse_download_args(int argc, char *argv[])
Parse command-line args for entropic download .
src/cli/download.cpp:164
Source · 17 lines
DownloadArgs parse_download_args(int argc, char* argv[])
{
DownloadArgs out;
// Early-continue (flat) rather than an else-if chain — keeps the knots
// nesting gate happy as selector flags are added.
for (int i = 1; i < argc; i++) {
std::string arg = argv[i];
if (arg == "--list" || arg == "-l") { out.want_list = true; continue; }
if (arg == "--dir" && i + 1 < argc) { out.override_dir = argv[++i]; continue; }
if (match_any_value_flag(arg, i, argc, argv, out)) { continue; }
if (!arg.empty() && arg[0] != '-') { out.key = arg; continue; }
std::fprintf(stderr, "entropic download: unknown option '%s'\n",
arg.c_str());
out.error = true;
}
return out;
}Activity · 17 steps
Requirements
resolve_entry
const entropic::config::BundledModelEntry * entropic::cli::resolve_entry(const entropic::config::BundledModels ®istry, const std::string &key)
Resolve a registry entry by key with user-friendly error output.
src/cli/download.cpp:222
Source · 19 lines
const entropic::config::BundledModelEntry* resolve_entry(
const entropic::config::BundledModels& registry, const std::string& key)
{
const auto* entry = registry.get(key);
if (!entry) {
std::fprintf(stderr,
"entropic download: unknown model key '%s'. "
"Run `entropic download --list` for available keys.\n",
key.c_str());
return nullptr;
}
if (entry->url.empty()) {
std::fprintf(stderr,
"entropic download: model '%s' has no URL in the registry.\n",
key.c_str());
return nullptr;
}
return entry;
}Activity · 8 steps
Requirements
resolve_selector_key
std::string entropic::cli::resolve_selector_key(const DownloadArgs &args, const entropic::config::BundledModels ®istry)
Resolve the target model key from an explicit key or a --family/--size/--quant selector (gh#62).
src/cli/download.cpp:191
Source · 24 lines
std::string resolve_selector_key(
const DownloadArgs& args,
const entropic::config::BundledModels& registry)
{
if (!args.key.empty()) { return args.key; }
const bool hf = !args.family.empty();
const bool hs = !args.size.empty();
const bool hq = !args.quant.empty();
if (!hf && !hs && !hq) { return ""; }
std::string key;
if (!(hf && hs && hq)) {
std::fprintf(stderr, "entropic download: --family/--size/--quant "
"must be given together (or pass a model key).\n");
} else {
key = registry.find_by(args.family, args.size, args.quant);
if (key.empty()) {
std::fprintf(stderr, "entropic download: no bundled model matches "
"--family %s --size %s --quant %s. Try --list.\n",
args.family.c_str(), args.size.c_str(),
args.quant.c_str());
}
}
return key;
}Activity · 15 steps
Requirements
run_download
int entropic::cli::run_download(int argc, char *argv[])
Handle entropic download subcommand.
src/cli/download.cpp:370
Source · 21 lines
int run_download(int argc, char* argv[])
{
auto args = parse_download_args(argc, argv);
int rc = 0;
if (args.error) {
rc = 1;
} else {
entropic::config::BundledModels registry;
auto err = registry.auto_discover_and_load();
if (!err.empty()) {
std::fprintf(stderr,
"entropic download: cannot find bundled_models.yaml: %s\n"
"(Expected under <install-prefix>/share/entropic/ or the source tree's data/.)\n",
err.c_str());
rc = 1;
} else {
rc = dispatch(args, registry);
}
}
return rc;
}