"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const command_1 = require("@oclif/command");
const fs_1 = require("fs");
const base_1 = __importDefault(require("../base"));
class RemoveTrackJson extends base_1.default {
    async run() {
        var _a;
        const { args, flags: runFlags } = this.parse(RemoveTrackJson);
        const output = runFlags.target || runFlags.out || '.';
        const isDir = (await fs_1.promises.lstat(output)).isDirectory();
        this.target = isDir ? `${output}/config.json` : output;
        const { track: inputId } = args;
        const config = await this.readJsonFile(this.target);
        config.tracks = (_a = config.tracks) === null || _a === void 0 ? void 0 : _a.filter(({ trackId }) => trackId !== inputId);
        await this.writeJsonFile(this.target, config);
    }
}
exports.default = RemoveTrackJson;
RemoveTrackJson.description = 'Remove a track configuration from a JBrowse 2 configuration. Be aware that this can cause crashes in saved sessions that refer to this track!';
RemoveTrackJson.examples = ['$ jbrowse remove-track-json trackId'];
RemoveTrackJson.args = [
    {
        name: 'track',
        required: true,
        description: `track JSON file or command line arg blob`,
    },
];
RemoveTrackJson.flags = {
    target: command_1.flags.string({
        description: 'path to config file in JB2 installation directory to write out to.\nCreates ./config.json if nonexistent',
    }),
    out: command_1.flags.string({
        description: 'synonym for target',
    }),
};
