<commit_before>"use strict";

import * as vscode from "vscode";
import * as interfaces from "./interfaces";
import * as inversify from "./inversify.config";

export function activate(context: vscode.ExtensionContext) {

    inversify.registerOutputChannel();

    // Load instance inspector and fetch list of kitchen instances
    let instanceInspector = inversify.default.get<interfaces.IInstanceInspector>("IInstanceInspector");
    let instanceList = instanceInspector.list();

    // Helper method wrapping picking of instance
    function registerCommand(commandName: string): vscode.Disposable {
        const ALL_ITEM = "[All]";
        return vscode.commands.registerCommand(`kitchen.${commandName}`, () => {
            // Load all active instances in kitchen
            instanceList.then((items: string[]) => {
                // Prepend "all items" option and show quick pick
                let extendedItems = [ALL_ITEM].concat(items);
                let instance = vscode.window.showQuickPick(extendedItems);
                instance.then((name: string) => {
                    // When no selection made skip execution
                    if (name === undefined) {
                        return;
                    }

                    // Retrieve command from IoC container and pass selected instance as argument
                    let command = inversify.default.get<interfaces.ICommandWrapper>("ICommandWrapper");
                    if (name === ALL_ITEM) {
                        command.execute([commandName]);
                    } else {
                        command.execute([commandName, name]);
                    }
                });
            });
        });
    }

    // Creates standard kitchen commands with instance list submenu
    ["converge", "create", "destroy", "test", "verify"].forEach(name => {<commit_msg>- Do not prompt about instance name when there is just one instance #13<commit_after>"use strict";

import * as vscode from "vscode";
import * as interfaces from "./interfaces";
import * as inversify from "./inversify.config";

export function activate(context: vscode.ExtensionContext) {

    inversify.registerOutputChannel();

    const ITEM_ALL = "[All]";

    // Load instance inspector and fetch list of kitchen instances
    let instanceInspector = inversify.default.get<interfaces.IInstanceInspector>("IInstanceInspector");
    let instanceList = instanceInspector.list();

    // Helper method wrapping picking of instance
    function registerCommand(commandName: string): vscode.Disposable {
        return vscode.commands.registerCommand(`kitchen.${commandName}`, () => {
            // Load all active instances in kitchen
            instanceList.then((items: string[]) => {
                switch (items.length) {
                    case 0:
                        vscode.window.showWarningMessage("Solution doesn't define any kitchen instances. Please inspect your .kitchen.yml");
                        break;
                    case 1:
                        executeCommand(commandName, items[0]);
                        break;
                    default:
                        executeCommandWithInstanceSelector(commandName, items);
                }
            });
        });
    }

    function executeCommandWithInstanceSelector(commandName: string, items: string[]) {
        // Prepend "all items" option and show quick pick
        let extendedItems = [ITEM_ALL].concat(items);
        let instance = vscode.window.showQuickPick(extendedItems);
        instance.then((instanceName: string) => {
            // When no selection made skip execution
            if (instanceName !== undefined) {
                executeCommand(commandName, instanceName);
            }
        });
    }

    function executeCommand(commandName: string, instanceName: string) {
        // Retrieve command from IoC container and pass selected instance as argument
        let command = inversify.default.get<interfaces.ICommandWrapper>("ICommandWrapper");
        if (instanceName === ITEM_ALL) {
            command.execute([commandName]);
        } else {
            command.execute([commandName, instanceName]);
        }
    }

    // Creates standard kitchen commands with instance list submenu
    ["converge", "create", "destroy", "test", "verify"].forEach(name => {
{'fraction_non_alphanumeric': 0.1011261778901402, 'fraction_numerical': 0.0011491611123879567, 'mean_word_length': 2.2070744288872515, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 15, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1306540', 'n_tokens_mistral': 1063, 'n_tokens_neox': 1010, 'n_words': 287}