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 &registry)

Handle entropic download subcommand.

src/cli/download.cpp:329

Show on the map →

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
lines 332–332int rc = 0;lines 333–334const bool has_selector = !args.family.empty() || !args.size.empty() || !args.quant.empty();lines 335–335◇ if (args.want_list)lines 336–336rc = list_models(registry);lines 337–337elselines 337–338◇ if (const std::string key = resolve_selector_key(args, registry); key.empty())lines 339–339◇ if (!has_selector)lines 340–344std::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");lines 346–346rc = 1;lines 347–347elselines 347–347◇ if (const auto* entry = resolve_entry(registry, key); !entry)lines 348–348rc = 1;lines 349–349elselines 350–351auto target_dir = args.override_dir.empty() ? default_model_dir() : args.override_dir;lines 352–352rc = fetch_to(*entry, target_dir, key);lines 353–353◇ if (rc == 0)lines 354–354rc = fetch_mmproj_if_paired(*entry, registry, target_dir);lines 357–357return rc;

Requirements

REQ-PROD-001

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

Show on the map →

Called by dispatch, fetch_mmproj_if_paired

Calls curl_download

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
lines 252–252int rc = 0;lines 253–253std::error_code ec;lines 254–254std::filesystem::create_directories(target_dir, ec);lines 255–255auto target_file = target_dir / (entry.name + ".gguf");lines 256–257const bool already = std::filesystem::exists(target_file) && std::filesystem::file_size(target_file) > 0;lines 259–259◇ if (ec)lines 260–261std::fprintf(stderr, "entropic download: cannot create %s: %s\n", target_dir.c_str(), ec.message().c_str());lines 262–262rc = 1;lines 263–263elselines 263–263◇ if (already)lines 264–265std::printf("Model '%s' already at %s — nothing to do.\n", key.c_str(), target_file.c_str());lines 266–266elselines 267–269std::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());lines 270–270rc = curl_download(entry.url, target_file);lines 271–271◇ if (rc != 0)lines 272–275std::fprintf(stderr, "entropic download: curl exited with status %d\n" "Partial file left at %s — rerun to resume.\n", rc, target_file.c_str());lines 276–276elselines 277–279std::printf("\nDone. Point the engine at this dir with:\n" " export ENTROPIC_MODEL_DIR=%s\n", target_dir.c_str());lines 282–282return rc;

Requirements

REQ-PROD-001

list_models

int entropic::cli::anonymous_namespace{download.cpp}::list_models(const entropic::config::BundledModels &registry)

Print the registry as a table.

src/cli/download.cpp:62

Show on the map →

Called by dispatch

Calls entries

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
lines 64–64std::printf("%-12s %-6s %s\n", "KEY", "SIZE", "DESCRIPTION");lines 65–65std::printf("%-12s %-6s %s\n", "---", "----", "-----------");lines 66–66◇ for (const auto& [key, entry] : registry.entries())lines 67–68std::printf("%-12s %4.1fGB %s\n", key.c_str(), entry.size_gb, entry.description.c_str());lines 70–70return 0;

Requirements

REQ-PROD-001

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

Show on the map →

Called by run_download

Calls match_any_value_flag

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
lines 166–166DownloadArgs out;lines 169–169◇ for (int i = 1; i < argc; i++)lines 170–170std::string arg = argv[i];lines 171–171◇ if (arg == "--list" || arg == "-l")lines 171–171out.want_list = true;lines 171–171continue;lines 172–172◇ if (arg == "--dir" && i + 1 < argc)lines 172–172out.override_dir = argv[++i];lines 172–172continue;lines 173–173◇ if (match_any_value_flag(arg, i, argc, argv, out))lines 173–173continue;lines 174–174◇ if (!arg.empty() && arg[0] != '-')lines 174–174out.key = arg;lines 174–174continue;lines 175–176std::fprintf(stderr, "entropic download: unknown option '%s'\n", arg.c_str());lines 177–177out.error = true;lines 179–179return out;

Requirements

REQ-PROD-001

resolve_entry

const entropic::config::BundledModelEntry * entropic::cli::resolve_entry(const entropic::config::BundledModels &registry, const std::string &key)

Resolve a registry entry by key with user-friendly error output.

src/cli/download.cpp:222

Show on the map →

Called by dispatch, fetch_mmproj_if_paired

Calls get

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
lines 225–225const auto* entry = registry.get(key);lines 226–226◇ if (!entry)lines 227–230std::fprintf(stderr, "entropic download: unknown model key '%s'. " "Run `entropic download --list` for available keys.\n", key.c_str());lines 231–231return nullptr;lines 233–233◇ if (entry->url.empty())lines 234–236std::fprintf(stderr, "entropic download: model '%s' has no URL in the registry.\n", key.c_str());lines 237–237return nullptr;lines 239–239return entry;

Requirements

REQ-PROD-001

resolve_selector_key

std::string entropic::cli::resolve_selector_key(const DownloadArgs &args, const entropic::config::BundledModels &registry)

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
lines 195–195◇ if (!args.key.empty())lines 195–195return args.key;lines 196–196const bool hf = !args.family.empty();lines 197–197const bool hs = !args.size.empty();lines 198–198const bool hq = !args.quant.empty();lines 199–199◇ if (!hf && !hs && !hq)lines 199–199return "";lines 200–200std::string key;lines 201–201◇ if (!(hf && hs && hq))lines 202–203std::fprintf(stderr, "entropic download: --family/--size/--quant " "must be given together (or pass a model key).\n");lines 204–204elselines 205–205key = registry.find_by(args.family, args.size, args.quant);lines 206–206◇ if (key.empty())lines 207–210std::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());lines 213–213return key;

Requirements

REQ-PROD-001

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;
}
Activity · 13 steps
lines 372–372auto args = parse_download_args(argc, argv);lines 373–373int rc = 0;lines 374–374◇ if (args.error)lines 375–375rc = 1;lines 376–376elselines 377–377entropic::config::BundledModels registry;lines 378–378auto err = registry.auto_discover_and_load();lines 379–379◇ if (!err.empty())lines 380–383std::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());lines 384–384rc = 1;lines 385–385elselines 386–386rc = dispatch(args, registry);lines 389–389return rc;

Requirements

REQ-PROD-001