<commit_before>package polyglot;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.nio.file.Paths;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.TimeUnit;
import java.util.logging.LogManager;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.slf4j.bridge.SLF4JBridgeHandler;

import com.google.auth.Credentials;
import com.google.common.base.Charsets;
import com.google.common.base.Joiner;
import com.google.common.io.CharStreams;
import com.google.protobuf.DescriptorProtos.FileDescriptorSet;
import com.google.protobuf.Descriptors.Descriptor;
import com.google.protobuf.Descriptors.MethodDescriptor;
import com.google.protobuf.DynamicMessage;
import com.google.protobuf.InvalidProtocolBufferException;
import com.google.protobuf.util.JsonFormat;

import io.grpc.CallOptions;
import io.grpc.stub.StreamObserver;
import polyglot.ConfigProto.CallConfiguration;
import polyglot.ConfigProto.Configuration;
import polyglot.ConfigProto.OutputConfiguration;
import polyglot.ConfigProto.ProtoConfiguration;
import polyglot.config.CommandLineArgs;
import polyglot.config.ConfigurationLoader;
import polyglot.grpc.CompositeStreamObserver;
import polyglot.grpc.DynamicGrpcClient;
import polyglot.io.FileMessageWriter;
import polyglot.io.LoggingMessageWriter;
import polyglot.io.LoggingStatsWriter;
import polyglot.oauth2.OauthCredentialsFactory;
import polyglot.protobuf.ProtocInvoker;
import polyglot.protobuf.ProtocInvoker.ProtocInvocationException;
import polyglot.protobuf.ServiceResolver;

public class Main {
  private static final Logger logger = LoggerFactory.getLogger(Main.class);

  public static void main(String[] args) {
    // Fix the logging setup.
    setupJavaUtilLogging();

    final CommandLineArgs arguments;
    try {
      arguments = CommandLineArgs.parse(args);
    } catch (RuntimeException e) {
      logger.info("Usage: polyglot " + CommandLineArgs.getUsage(), e);
      return;
    }

    ConfigurationLoader configLoader = arguments.configSetPath().isPresent()
        ? ConfigurationLoader.forFile(arguments.configSetPath().get())
        : ConfigurationLoader.forDefaultConfigSet();
    configLoader = configLoader.withOverrides(arguments);
    Configuration config = arguments.configName().isPresent()
        ? configLoader.getNamedConfiguration(arguments.configName().get())
        : configLoader.getDefaultConfiguration();
    logger.info("Loaded configuration: " + config.getName());
    
    FileDescriptorSet fileDescriptorSet = getFileDescriptorSet(config.getProtoConfig());
    
    if (arguments.command().isPresent()) {
    	switch (arguments.command().get()) {
    	case "list_services":
    		ServiceList.listServices(
    		    fileDescriptorSet, config.getProtoConfig().getProtoDiscoveryRoot(), 
    		    arguments.serviceFilter(), arguments.methodFilter(), arguments.withMessage());
    		break;
    		
    	default:
    		runLegacyCommands(fileDescriptorSet, config, arguments);    		
    	}
    }
  }
  
  /** The "legacy commands" will be deprecated when we move over to a "polyglot [command]" style invocation */
  private static void runLegacyCommands(FileDescriptorSet fileDescriptorSet, final Configuration config, final CommandLineArgs arguments) {
    ServiceResolver serviceResolver = ServiceResolver.fromFileDescriptorSet(fileDescriptorSet);
    MethodDescriptor methodDescriptor =
            serviceResolver.resolveServiceMethod(arguments.grpcMethodName());
<commit_msg>Fixed legacy command method<commit_after>package polyglot;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.nio.file.Paths;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.TimeUnit;
import java.util.logging.LogManager;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.slf4j.bridge.SLF4JBridgeHandler;

import com.google.auth.Credentials;
import com.google.common.base.Charsets;
import com.google.common.base.Joiner;
import com.google.common.io.CharStreams;
import com.google.protobuf.DescriptorProtos.FileDescriptorSet;
import com.google.protobuf.Descriptors.Descriptor;
import com.google.protobuf.Descriptors.MethodDescriptor;
import com.google.protobuf.DynamicMessage;
import com.google.protobuf.InvalidProtocolBufferException;
import com.google.protobuf.util.JsonFormat;

import io.grpc.CallOptions;
import io.grpc.stub.StreamObserver;
import polyglot.ConfigProto.CallConfiguration;
import polyglot.ConfigProto.Configuration;
import polyglot.ConfigProto.OutputConfiguration;
import polyglot.ConfigProto.ProtoConfiguration;
import polyglot.config.CommandLineArgs;
import polyglot.config.ConfigurationLoader;
import polyglot.grpc.CompositeStreamObserver;
import polyglot.grpc.DynamicGrpcClient;
import polyglot.io.FileMessageWriter;
import polyglot.io.LoggingMessageWriter;
import polyglot.io.LoggingStatsWriter;
import polyglot.oauth2.OauthCredentialsFactory;
import polyglot.protobuf.ProtocInvoker;
import polyglot.protobuf.ProtocInvoker.ProtocInvocationException;
import polyglot.protobuf.ServiceResolver;

public class Main {
  private static final Logger logger = LoggerFactory.getLogger(Main.class);

  public static void main(String[] args) {
    // Fix the logging setup.
    setupJavaUtilLogging();

    final CommandLineArgs arguments;
    try {
      arguments = CommandLineArgs.parse(args);
    } catch (RuntimeException e) {
      logger.info("Usage: polyglot " + CommandLineArgs.getUsage(), e);
      return;
    }

    ConfigurationLoader configLoader = arguments.configSetPath().isPresent()
        ? ConfigurationLoader.forFile(arguments.configSetPath().get())
        : ConfigurationLoader.forDefaultConfigSet();
    configLoader = configLoader.withOverrides(arguments);
    Configuration config = arguments.configName().isPresent()
        ? configLoader.getNamedConfiguration(arguments.configName().get())
        : configLoader.getDefaultConfiguration();
    logger.info("Loaded configuration: " + config.getName());
    
    FileDescriptorSet fileDescriptorSet = getFileDescriptorSet(config.getProtoConfig());
    
    if (!arguments.command().isPresent()) {
      runLegacyCommands(fileDescriptorSet, config, arguments);
    
    } else {
    	switch (arguments.command().get()) {
    	case "list_services":
    		ServiceList.listServices(
    		    fileDescriptorSet, config.getProtoConfig().getProtoDiscoveryRoot(), 
    		    arguments.serviceFilter(), arguments.methodFilter(), arguments.withMessage());
    		break;
    		
    	default:
    	  logger.warn("Unknown command: " + arguments.command().get());
    	}
    }
  }
  
  /** The "legacy commands" will be deprecated when we move over to a "polyglot [command]" style invocation */
  private static void runLegacyCommands(FileDescriptorSet fileDescriptorSet, final Configuration config, final CommandLineArgs arguments) {
    ServiceResolver serviceResolver = ServiceResolver.fromFileDescriptorSet(fileDescriptorSet);
    MethodDescriptor methodDescriptor =
            serviceResolver.resolveServiceMethod(arguments.grpcMethodName());

{'fraction_non_alphanumeric': 0.09519150125803746, 'fraction_numerical': 0.0013978194017332962, 'mean_word_length': 5.141630901287554, 'pattern_counts': {'":': 2, '<': 3, '<?xml version=': 0, '>': 3, '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': '4604599', 'n_tokens_mistral': 1947, 'n_tokens_neox': 1945, 'n_words': 361}