"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const core_1 = require("@oclif/core");
const fs_1 = require("fs");
const base_1 = __importDefault(require("../base"));
class RemoveTrackJson extends base_1.default {
    async run() {
        const { args, flags: runFlags } = await 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 = config.tracks?.filter(({ trackId }) => trackId !== inputId);
        await this.writeJsonFile(this.target, config);
    }
}
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 = {
    track: core_1.Args.string({
        required: true,
        description: 'track JSON file or command line arg blob',
    }),
};
RemoveTrackJson.flags = {
    target: core_1.Flags.string({
        description: 'path to config file in JB2 installation directory to write out to.\nCreates ./config.json if nonexistent',
    }),
    out: core_1.Flags.string({
        description: 'synonym for target',
    }),
};
exports.default = RemoveTrackJson;
