"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.handleDown = void 0;
const docker_1 = require("../../docker");
const ui_1 = require("../../utils/ui");
const options_1 = require("./options");
const KNOWN_FLAGS = ['--host'];
async function handleDown(args) {
    await (0, ui_1.initUI)();
    const parsed = (0, options_1.parseDockerTarget)(args, KNOWN_FLAGS);
    const errors = [
        ...parsed.errors,
        ...(0, options_1.collectUnexpectedDockerArgs)(parsed.remainingArgs, {
            knownFlags: [],
            maxPositionals: 0,
        }),
    ];
    if (errors.length > 0) {
        console.error((0, ui_1.box)((0, ui_1.fail)(errors.join('\n')), { title: 'Docker', padding: 1 }));
        process.exitCode = 1;
        return;
    }
    console.log((0, ui_1.info)(`Stopping Docker stack${parsed.host ? ` on ${parsed.host}` : ''}...`));
    try {
        await new docker_1.DockerExecutor().down({ host: parsed.host });
        console.log((0, ui_1.ok)(`Docker stack stopped${parsed.host ? ` on ${parsed.host}` : ''}.`));
    }
    catch (error) {
        console.error((0, ui_1.box)((0, ui_1.fail)(error instanceof Error ? error.message : String(error)), {
            title: 'Docker',
            padding: 1,
        }));
        process.exitCode = 1;
    }
}
exports.handleDown = handleDown;
//# sourceMappingURL=down-subcommand.js.map