<commit_before>package org.jboss.forge.addon.shell.command;

import java.util.Collections;
import java.util.Iterator;

import javax.inject.Inject;

import org.jboss.forge.addon.resource.Resource;
import org.jboss.forge.addon.shell.Shell;
import org.jboss.forge.addon.shell.ui.AbstractShellCommand;
import org.jboss.forge.addon.text.Highlighter;
import org.jboss.forge.addon.ui.context.UIBuilder;
import org.jboss.forge.addon.ui.context.UIContext;
import org.jboss.forge.addon.ui.context.UIExecutionContext;
import org.jboss.forge.addon.ui.hints.InputType;
import org.jboss.forge.addon.ui.input.UIInput;
import org.jboss.forge.addon.ui.input.UIInputMany;
import org.jboss.forge.addon.ui.metadata.UICommandMetadata;
import org.jboss.forge.addon.ui.metadata.WithAttributes;
import org.jboss.forge.addon.ui.output.UIOutput;
import org.jboss.forge.addon.ui.result.Result;
import org.jboss.forge.addon.ui.result.Results;
import org.jboss.forge.addon.ui.util.Metadata;

/**
 * @author <a href="mailto:<EMAIL>"><NAME>, III</a>
 */
public class CatCommand extends AbstractShellCommand
{
   @Inject
   private Highlighter highlighter;

   @Inject
   @WithAttributes(shortName = 'c', label = "Color", description = "Enable color hightlight in output")
   private UIInput<Boolean> color;

   @Inject
   @WithAttributes(label = "Arguments", type = InputType.FILE_PICKER)
   private UIInputMany<String> arguments;

   @Override
   public UICommandMetadata getMetadata(UIContext context)
   {
      return Metadata
               .from(super.getMetadata(context), getClass())
               .name("cat")
               .description(
                        "The cat utility reads files sequentially, writing them to the standard output.  "
                                 + "The file operands are processed in command-line order.");
   }

   @Override
   public void initializeUI(UIBuilder builder) throws Exception
   {
      builder.add(arguments);
      builder.add(color);

      color.setDefaultValue(false);
   }

   @Override
   public Result execute(UIExecutionContext context) throws Exception
   {
      Shell shell = (Shell) context.getUIContext().getProvider();
      Resource<?> currentResource = shell.getCurrentResource();
      Iterator<String> it = arguments.getValue() == null ? Collections.<String> emptyList().iterator() : arguments
               .getValue().iterator();

      Result result = Results.success();
      UIOutput output = shell.getOutput();
      while (it.hasNext())
      {
         final Resource<?> resource = it.hasNext() ?
                  (currentResource.resolveChildren(it.next()).get(0))
                  : currentResource;

         if (!resource.exists())
         {
            output.err().println("cat: " + resource.getName() + ": No such file or directory");
            result = Results.fail();
         }
         else
         {
            try
            {
               if (color.getValue())
               {
                  highlighter.byFileName(resource.getName(), resource.getContents(), output.out());
               }
               else
               {
                  output.out().println(resource.getContents());
               }
            }
            catch (UnsupportedOperationException uoe)
            {
               output.err().println("cat: " + resource.getName() + ": " + uoe.getMessage());
               result = Results.fail();
            }
         }
      }
      return result;
   }
}<commit_msg>FORGE-2302: Printing new line after cat -c<commit_after>package org.jboss.forge.addon.shell.command;

import java.util.Collections;
import java.util.Iterator;

import javax.inject.Inject;

import org.jboss.forge.addon.resource.Resource;
import org.jboss.forge.addon.shell.Shell;
import org.jboss.forge.addon.shell.ui.AbstractShellCommand;
import org.jboss.forge.addon.text.Highlighter;
import org.jboss.forge.addon.ui.context.UIBuilder;
import org.jboss.forge.addon.ui.context.UIContext;
import org.jboss.forge.addon.ui.context.UIExecutionContext;
import org.jboss.forge.addon.ui.hints.InputType;
import org.jboss.forge.addon.ui.input.UIInput;
import org.jboss.forge.addon.ui.input.UIInputMany;
import org.jboss.forge.addon.ui.metadata.UICommandMetadata;
import org.jboss.forge.addon.ui.metadata.WithAttributes;
import org.jboss.forge.addon.ui.output.UIOutput;
import org.jboss.forge.addon.ui.result.Result;
import org.jboss.forge.addon.ui.result.Results;
import org.jboss.forge.addon.ui.util.Metadata;

/**
 * @author <a href="mailto:<EMAIL>"><NAME>, III</a>
 */
public class CatCommand extends AbstractShellCommand
{
   @Inject
   private Highlighter highlighter;

   @Inject
   @WithAttributes(shortName = 'c', label = "Color", description = "Enable color hightlight in output")
   private UIInput<Boolean> color;

   @Inject
   @WithAttributes(label = "Arguments", type = InputType.FILE_PICKER)
   private UIInputMany<String> arguments;

   @Override
   public UICommandMetadata getMetadata(UIContext context)
   {
      return Metadata
               .from(super.getMetadata(context), getClass())
               .name("cat")
               .description(
                        "The cat utility reads files sequentially, writing them to the standard output.  "
                                 + "The file operands are processed in command-line order.");
   }

   @Override
   public void initializeUI(UIBuilder builder) throws Exception
   {
      builder.add(arguments);
      builder.add(color);

      color.setDefaultValue(false);
   }

   @Override
   public Result execute(UIExecutionContext context) throws Exception
   {
      Shell shell = (Shell) context.getUIContext().getProvider();
      Resource<?> currentResource = shell.getCurrentResource();
      Iterator<String> it = arguments.getValue() == null ? Collections.<String> emptyList().iterator() : arguments
               .getValue().iterator();

      Result result = Results.success();
      UIOutput output = shell.getOutput();
      while (it.hasNext())
      {
         final Resource<?> resource = it.hasNext() ?
                  (currentResource.resolveChildren(it.next()).get(0))
                  : currentResource;

         if (!resource.exists())
         {
            output.err().println("cat: " + resource.getName() + ": No such file or directory");
            result = Results.fail();
         }
         else
         {
            try
            {
               if (color.getValue())
               {
                  highlighter.byFileName(resource.getName(), resource.getContents(), output.out());
                  output.out().println();
               }
               else
               {
                  output.out().println(resource.getContents());
               }
            }
            catch (UnsupportedOperationException uoe)
            {
               output.err().println("cat: " + resource.getName() + ": " + uoe.getMessage());
               result = Results.fail();
            }
         }
      }
      return result;
   }
}
{'fraction_non_alphanumeric': 0.12067738722072008, 'fraction_numerical': 0.0008538494378824534, 'mean_word_length': 2.4349951124144673, 'pattern_counts': {'":': 4, '<': 23, '<?xml version=': 0, '>': 23, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3143152', 'n_tokens_mistral': 2029, 'n_tokens_neox': 1962, 'n_words': 371}