import program from "commander"; import { makeLogger } from "../../lib/logging" import { machineConfigPackage, rmPackageEntry, rmPackageEntryByLabel, setPackageBoot } from "@createdreamtech/carti-core" import * as clib from "@createdreamtech/carti-core" import { Bundle, bundle, PackageEntryOptions, generateLuaConfig } from "@createdreamtech/carti-core" import { Config, getMachineConfig, initMachineConfig, writeMachineConfig, CARTI_DOCKER_PACKAGE_PATH, CARTI_BUILD_BUNDLES_PATH, machineConfigExists } from "../../lib/config" import inquirer from "inquirer" import { shortDesc, parseShortDesc } from "../../lib/bundle"; import * as utils from "../util" import os from "os" import { https } from "follow-redirects" import fs from "fs-extra" import { spawnSync } from "child_process"; import path from "path" import rimraf from "rimraf"; import { promisify } from 'util'; import { bundleFetcher } from "../../lib/fetcher"; import { Readable } from "stream"; import { fromStreamToStr } from "../../lib/utils"; import url from "url" import { CID } from "multiformats"; import { cwd } from "process"; import { CartiBundleStorage } from "../../lib/storage/carti_bundles"; import { commandHandler, progressBar } from "./command_util"; import chalk from "chalk"; const rmAll = promisify(rimraf) type addMachineCommandType = "ram" | "rom" | "flashdrive"; export const addMachineCommand = (config: Config): program.Command => { const add = (addType: addMachineCommandType) => { return (name: string, options: PackageEntryOptions & {yes: boolean}) => { const { length, start, shared, yes, label,} = options return commandHandler(handleAdd, config, name, { length, start, shared, label }, addType, yes) } } const machineCommand = program.command("machine") .description("Utilize cartesi machine commands to specify and generate stored machines") .storeOptionsAsProperties(false) .passCommandToAction(false) const machineRepoCommand = new program.Command("repo") .description("a util to annotate repo dependencies for automatic retrieval from config") .storeOptionsAsProperties(false) .passCommandToAction(false) machineRepoCommand.command("deps") .description("lists links to repo dependencies for optional inclusion in config") .action(() => commandHandler(handleDepsRepo, config)) machineRepoCommand.command("list") .description("lists repos specified in the machine config") .action(() => commandHandler(handleListRepo, config)) machineRepoCommand.command("add ") .description("write comma seperated list of repos to add into config") .action((repos) => commandHandler(handleAddRepo, config, repos)) machineRepoCommand.command("rm ") .description("write comma seprated list of repos to remove from config") .action((repos) => commandHandler(handleRmRepo, config, repos)) const machineRmCommand = new program.Command("rm") .description("Rm bundles from cartesi machine description using ram | rom | flashdrive options") .storeOptionsAsProperties(false) .passCommandToAction(false) machineRmCommand.command("ram") .description("remove ram entry from machine-package") .action(() => commandHandler(handleRm, config, "ram")) machineRmCommand.command("rom") .description("remove rom entry from machine-package") .action(() => commandHandler(handleRm, config, "rom")) machineRmCommand.command("flash