<commit_before>/**
 * Copyright 2013 Red Hat, Inc. and/or its affiliates.
 *
 * Licensed under the Eclipse Public License version 1.0, available at
 * http://www.eclipse.org/legal/epl-v10.html
 */

package org.jboss.forge.addon.shell.aesh;

import java.util.HashMap;
import java.util.Map;

import org.jboss.aesh.cl.CommandLine;
import org.jboss.aesh.cl.parser.CommandLineParser;
import org.jboss.forge.addon.shell.ui.ShellContext;
import org.jboss.forge.addon.ui.controller.WizardCommandController;
import org.jboss.forge.addon.ui.input.InputComponent;

/**
 * Encapsulates the {@link WizardCommandController}.
 * 
 * @author <a href="<EMAIL>"><NAME></a>
 * @author <a href="mailto:<EMAIL>"><NAME>, III</a>
 */
public class ShellWizard extends AbstractShellInteraction
{
   public ShellWizard(WizardCommandController wizardCommandController, ShellContext shellContext,
            CommandLineUtil commandLineUtil, ForgeCommandRegistry forgeCommandRegistry)
   {
      super(wizardCommandController, shellContext, commandLineUtil);
   }

   @Override
   public WizardCommandController getController()
   {
      return (WizardCommandController) super.getController();
   }

   @Override
   public CommandLineParser getParser(ShellContext shellContext, String completeLine) throws Exception
   {
      getController().initialize();
      return populate(shellContext, completeLine, new HashMap<String, InputComponent<?, ?>>());
   }

   private CommandLineParser populate(ShellContext shellContext, String line,
            final Map<String, InputComponent<?, ?>> inputs)
            throws Exception
   {
      WizardCommandController controller = getController();
      inputs.putAll(controller.getInputs());
      CommandLineParser parser = commandLineUtil.generateParser(controller, shellContext, inputs);
      CommandLine cmdLine = parser.parse(line, true);
      commandLineUtil.populateUIInputs(cmdLine, inputs);
      if (controller.canMoveToNextStep())
      {
         controller.next().initialize();
         parser = populate(shellContext, line, inputs);
      }
      return parser;
   }
}
<commit_msg>Fixed ShellWizard logic<commit_after>/**
 * Copyright 2013 Red Hat, Inc. and/or its affiliates.
 *
 * Licensed under the Eclipse Public License version 1.0, available at
 * http://www.eclipse.org/legal/epl-v10.html
 */

package org.jboss.forge.addon.shell.aesh;

import java.util.HashMap;
import java.util.Map;

import org.jboss.aesh.cl.CommandLine;
import org.jboss.aesh.cl.parser.CommandLineParser;
import org.jboss.forge.addon.shell.ui.ShellContext;
import org.jboss.forge.addon.ui.controller.WizardCommandController;
import org.jboss.forge.addon.ui.input.InputComponent;

/**
 * Encapsulates the {@link WizardCommandController}.
 * 
 * @author <a href="<EMAIL>"><NAME></a>
 * @author <a href="mailto:<EMAIL>"><NAME>, III</a>
 */
public class ShellWizard extends AbstractShellInteraction
{
   public ShellWizard(WizardCommandController wizardCommandController, ShellContext shellContext,
            CommandLineUtil commandLineUtil, ForgeCommandRegistry forgeCommandRegistry)
   {
      super(wizardCommandController, shellContext, commandLineUtil);
   }

   @Override
   public WizardCommandController getController()
   {
      return (WizardCommandController) super.getController();
   }

   @Override
   public CommandLineParser getParser(ShellContext shellContext, String completeLine) throws Exception
   {
      getController().initialize();
      return populate(shellContext, completeLine, new HashMap<String, InputComponent<?, ?>>(),
               new HashMap<String, InputComponent<?, ?>>());
   }

   private CommandLineParser populate(ShellContext shellContext, String line,
            final Map<String, InputComponent<?, ?>> allInputs, Map<String, InputComponent<?, ?>> lastPage)
            throws Exception
   {
      WizardCommandController controller = getController();
      Map<String, InputComponent<?, ?>> pageInputs = new HashMap<>(controller.getInputs());
      allInputs.putAll(pageInputs);
      CommandLineParser parser = commandLineUtil.generateParser(controller, shellContext, allInputs);
      CommandLine cmdLine = parser.parse(line, true);
      Map<String, InputComponent<?, ?>> populatedInputs = commandLineUtil.populateUIInputs(cmdLine, allInputs);
      for (String input : pageInputs.keySet())
      {
         if (populatedInputs.containsKey(input))
         {
            // Trim inputs from last page, because information from the current page was provided
            lastPage.keySet().removeAll(populatedInputs.keySet());
            allInputs.keySet().removeAll(lastPage.keySet());
            parser = commandLineUtil.generateParser(controller, shellContext, allInputs);
            break;
         }
      }

      if (controller.canMoveToNextStep())
      {
         controller.next().initialize();
         parser = populate(shellContext, line, allInputs, pageInputs);
      }
      return parser;
   }
}

{'fraction_non_alphanumeric': 0.10983705491852747, 'fraction_numerical': 0.0032186682760008047, 'mean_word_length': 3.908193484698914, 'pattern_counts': {'":': 0, '<': 36, '<?xml version=': 0, '>': 36, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '1091054', 'n_tokens_mistral': 1398, 'n_tokens_neox': 1362, 'n_words': 289}