text: "use strict";
  // Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license.
  // See LICENSE in the project root for license information.
  Object.defineProperty(exports, "__esModule", { value: true });
  const colors = require("colors");
  const DynamicCommandLineParser_1 = require("../DynamicCommandLineParser");
  const DynamicCommandLineAction_1 = require("../DynamicCommandLineAction");
  function createParser() {
      const commandLineParser = new DynamicCommandLineParser_1.DynamicCommandLineParser({
          toolFilename: 'example',
          toolDescription: 'An example project'
      });
      commandLineParser.defineFlagParameter({
          parameterLongName: '--global-flag',
          parameterShortName: '-g',
          description: 'A flag that affects all actions'
      });
      const action = new DynamicCommandLineAction_1.DynamicCommandLineAction({
          actionName: 'do-job',
          summary: 'does the job',
          documentation: 'a longer description'
      });
      commandLineParser.addAction(action);
      // Choice
      action.defineChoiceParameter({
          parameterLongName: '--choice',
          parameterShortName: '-c',
          description: 'A choice',
          alternatives: ['one', 'two', 'three', 'default'],
          environmentVariable: 'ENV_CHOICE'
      });
      action.defineChoiceParameter({
          parameterLongName: '--choice-with-default',
          description: 'A choice with a default',
          alternatives: ['one', 'two', 'three', 'default'],
          environmentVariable: 'ENV_CHOICE',
          defaultValue: 'default'
      });
      // Flag
      action.defineFlagParameter({
          parameterLongName: '--flag',
          parameterShortName: '-f',
          description: 'A flag',
          environmentVariable: 'ENV_FLAG'
      });
      // Integer
      action.defineIntegerParameter({
          parameterLongName: '--integer',
          parameterShortName: '-i',
          description: 'An integer',
          argumentName: 'NUMBER',
          environmentVariable: 'ENV_INTEGER'
      });
      action.defineIntegerParameter({
          parameterLongName: '--integer-with-default',
          description: 'An integer with a default',
          argumentName: 'NUMBER',
          environmentVariable: 'ENV_INTEGER',
          defaultValue: 123
      });
      action.defineIntegerParameter({
          parameterLongName: '--integer-required',
          description: 'An integer',
          argumentName: 'NUMBER',
          required: true
      });
      // String
      action.defineStringParameter({
          parameterLongName: '--string',
          parameterShortName: '-s',
          description: 'A string',
          argumentName: 'TEXT',
          environmentVariable: 'ENV_INTEGER'
      });
      action.defineStringParameter({
          parameterLongName: '--string-with-default',
          description: 'A string with a default',
          argumentName: 'TEXT',
          environmentVariable: 'ENV_INTEGER',
          defaultValue: '123'
      });
      // String List
      action.defineStringListParameter({
          parameterLongName: '--string-list',
          parameterShortName: '-l',
          description: 'A string list',
          argumentName: 'LIST',
          environmentVariable: 'ENV_INTEGER'
      });
      return commandLineParser;
  }
  function expectPropertiesToMatchSnapshot(object, propertyNames) {
      const snapshotObject = {};
      for (const propertyName of propertyNames) {
          snapshotObject[propertyName] = object[propertyName];
      }
      expect(snapshotObject).toMatchSnapshot();
  }
  const snapshotPropertyNames = [
      'description',
      'kind',
      'longName',
      'shortName',
      'value',
      'kind',
      'argumentName',
      'environmentVariable',
      'required',
      'defaultValue',
      'values'
  ];
  describe('CommandLineParameter', () => {
      it('prints the global help', () => {
          const commandLineParser = createParser();
          const helpText = colors.stripColors(commandLineParser.renderHelpText());
          expect(helpText).toMatchSnapshot();
      });
      it('prints the action help', () => {
          const commandLineParser = createParser();
          const helpText = colors.stripColors(commandLineParser.getAction('do-job').renderHelpText());
          expect(helpText).toMatchSnapshot();
      });
      it('parses an input with ALL parameters', () => {
          const commandLineParser = createParser();
          const action = commandLineParser.getAction('do-job');
          const args = [
              '--global-flag',
              'do-job',
              '--choice', 'two',
              '--flag',
              '--integer', '123',
              '--integer-required', '321',
              '--string', 'hello',
              '--string-list', 'first',
              '--string-list', 'second'
          ];
          return commandLineParser.execute(args).then(() => {
              expect(commandLineParser.selectedAction).toBe(action);
              expectPropertiesToMatchSnapshot(commandLineParser.getFlagParameter('--global-flag'), snapshotPropertyNames);
              expectPropertiesToMatchSnapshot(action.getChoiceParameter('--choice'), snapshotPropertyNames);
              expectPropertiesToMatchSnapshot(action.getChoiceParameter('--choice-with-default'), snapshotPropertyNames);
              expectPropertiesToMatchSnapshot(action.getFlagParameter('--flag'), snapshotPropertyNames);
              expectPropertiesToMatchSnapshot(action.getIntegerParameter('--integer'), snapshotPropertyNames);
              expectPropertiesToMatchSnapshot(action.getIntegerParameter('--integer-with-default'), snapshotPropertyNames);
              expectPropertiesToMatchSnapshot(action.getIntegerParameter('--integer-required'), snapshotPropertyNames);
              expectPropertiesToMatchSnapshot(action.getStringParameter('--string'), snapshotPropertyNames);
              expectPropertiesToMatchSnapshot(action.getStringParameter('--string-with-default'), snapshotPropertyNames);
              expectPropertiesToMatchSnapshot(action.getStringListParameter('--string-list'), snapshotPropertyNames);
              const copiedArgs = [];
              for (const parameter of action.parameters) {
                  copiedArgs.push(`### ${parameter.longName} output: ###`);
                  parameter.appendToArgList(copiedArgs);
              }
              expect(copiedArgs).toMatchSnapshot();
          });
      });
      it('parses an input with NO parameters', () => {
          const commandLineParser = createParser();
          const action = commandLineParser.getAction('do-job');
          const args = ['do-job', '--integer-required', '123'];
          return commandLineParser.execute(args).then(() => {
              expect(commandLineParser.selectedAction).toBe(action);
              expectPropertiesToMatchSnapshot(commandLineParser.getFlagParameter('--global-flag'), snapshotPropertyNames);
              expectPropertiesToMatchSnapshot(action.getChoiceParameter('--choice'), snapshotPropertyNames);
              expectPropertiesToMatchSnapshot(action.getChoiceParameter('--choice-with-default'), snapshotPropertyNames);
              expectPropertiesToMatchSnapshot(action.getFlagParameter('--flag'), snapshotPropertyNames);
              expectPropertiesToMatchSnapshot(action.getIntegerParameter('--integer'), snapshotPropertyNames);
              expectPropertiesToMatchSnapshot(action.getIntegerParameter('--integer-with-default'), snapshotPropertyNames);
              expectPropertiesToMatchSnapshot(action.getIntegerParameter('--integer-required'), snapshotPropertyNames);
              expectPropertiesToMatchSnapshot(action.getStringParameter('--string'), snapshotPropertyNames);
              expectPropertiesToMatchSnapshot(action.getStringParameter('--string-with-default'), snapshotPropertyNames);
              expectPropertiesToMatchSnapshot(action.getStringListParameter('--string-list'), snapshotPropertyNames);
              const copiedArgs = [];
              for (const parameter of action.parameters) {
                  copiedArgs.push(`### ${parameter.longName} output: ###`);
                  parameter.appendToArgList(copiedArgs);
              }
              expect(copiedArgs).toMatchSnapshot();
          });
      });
  });
  //# sourceMappingURL=CommandLineParameter.test.js.map