<commit_before>/*
 * libbrlapi - A library providing access to braille terminals for applications.
 *
 * Copyright (C) 2006-2022 by
 *   <NAME> <<EMAIL>>
 *   <NAME> <<EMAIL>>
 *
 * libbrlapi comes with ABSOLUTELY NO WARRANTY.
 *
 * This is free software, placed under the terms of the
 * GNU Lesser General Public License, as published by the Free Software
 * Foundation; either version 2.1 of the License, or (at your option) any
 * later version. Please see the file LICENSE-LGPL for details.
 *
 * Web Page: http://brltty.app/
 *
 * This software is maintained by <NAME> <<EMAIL>>.
 */

package org.a11y.brlapi;
import org.a11y.brlapi.programs.*;
import org.a11y.brlapi.clients.*;

import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;

public class ApiTool extends Program {
  private final static KeywordMap<Class<? extends Program>> knownPrograms =
                   new KeywordMap<>();

  private static void addProgram (Class<? extends Program> type) {
    String name = type.getSimpleName();

    if (isClient(type)) {
      name = Strings.replaceAll(name, "Client$", "");
    } else {
      name = Strings.replaceAll(name, "Program$", "");
    }

    knownPrograms.put(toOperandName(Strings.wordify(name)), type);
  }

  static {
    addProgram(ApiErrorClient.class);
    addProgram(ApiExceptionClient.class);
    addProgram(BoundCommandsClient.class);
    addProgram(ComputerBrailleClient.class);
    addProgram(DriverKeysClient.class);
    addProgram(EchoClient.class);
    addProgram(GetDriverClient.class);
    addProgram(GetModelClient.class);
    addProgram(GetSizeClient.class);
    addProgram(ListParametersClient.class);
    addProgram(PauseClient.class);
    addProgram(SetParameterClient.class);
    addProgram(VersionProgram.class);
    addProgram(WriteArgumentsClient.class);
    addProgram(WriteDotsClient.class);
    addProgram(WriteTextClient.class);
  }

  public ApiTool (String... arguments) {
    super(arguments);
    addRequiredParameters("program/client");
    addRepeatingParameter("argument");
  }

  @Override
  protected final void extendUsageSummary (StringBuilder usage) {
    super.extendUsageSummary(usage);

    if (knownPrograms.isEmpty()) {
      usage.append("\nNo programs or clients have been defined.");
    } else {
      usage.append("\nThese programs and clients have been defined")
           .append(" (each has its own -help option):");

      for (String name : knownPrograms.getKeywords()) {
        usage.append("\n  ").append(name);
      }
    }
  }

  private String programName = null;
  private Class<? extends Program> programType = null;
  private String[] programArguments = null;

  @Override
  protected final void processParameters (String[] parameters)
            throws SyntaxException
  {
    int count = parameters.length;

    if (count == 0) {
      throw new SyntaxException("missing program/client name");
    }

    programName = parameters[0];
    programType = knownPrograms.get(programName);

    if (programType == null) {
      throw new SyntaxException("unknown program/client: %s", programName);
    }<commit_msg>Java bindings: Add a general usage statement to ApiTool -h. (dm)<commit_after>/*
 * libbrlapi - A library providing access to braille terminals for applications.
 *
 * Copyright (C) 2006-2022 by
 *   <NAME> <<EMAIL>>
 *   <NAME> <<EMAIL>>
 *
 * libbrlapi comes with ABSOLUTELY NO WARRANTY.
 *
 * This is free software, placed under the terms of the
 * GNU Lesser General Public License, as published by the Free Software
 * Foundation; either version 2.1 of the License, or (at your option) any
 * later version. Please see the file LICENSE-LGPL for details.
 *
 * Web Page: http://brltty.app/
 *
 * This software is maintained by <NAME> <<EMAIL>>.
 */

package org.a11y.brlapi;
import org.a11y.brlapi.programs.*;
import org.a11y.brlapi.clients.*;

import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;

public class ApiTool extends Program {
  private final static KeywordMap<Class<? extends Program>> knownPrograms =
                   new KeywordMap<>();

  private static void addProgram (Class<? extends Program> type) {
    String name = type.getSimpleName();

    if (isClient(type)) {
      name = Strings.replaceAll(name, "Client$", "");
    } else {
      name = Strings.replaceAll(name, "Program$", "");
    }

    knownPrograms.put(toOperandName(Strings.wordify(name)), type);
  }

  static {
    addProgram(ApiErrorClient.class);
    addProgram(ApiExceptionClient.class);
    addProgram(BoundCommandsClient.class);
    addProgram(ComputerBrailleClient.class);
    addProgram(DriverKeysClient.class);
    addProgram(EchoClient.class);
    addProgram(GetDriverClient.class);
    addProgram(GetModelClient.class);
    addProgram(GetSizeClient.class);
    addProgram(ListParametersClient.class);
    addProgram(PauseClient.class);
    addProgram(SetParameterClient.class);
    addProgram(VersionProgram.class);
    addProgram(WriteArgumentsClient.class);
    addProgram(WriteDotsClient.class);
    addProgram(WriteTextClient.class);
  }

  public ApiTool (String... arguments) {
    super(arguments);
    addRequiredParameters("program/client");
    addRepeatingParameter("argument");
  }

  @Override
  protected final void extendUsageSummary (StringBuilder usage) {
    super.extendUsageSummary(usage);

    if (knownPrograms.isEmpty()) {
      usage.append("\nNo programs or clients have been defined.");
    } else {
      usage.append("\nThis program gives command line access to")
           .append(", and can be used to exercise,")
           .append(" the functionality provided by the BrlAPI interface.");

      usage.append("\nThese programs and clients have been defined")
           .append(" (each has its own -help option):");

      for (String name : knownPrograms.getKeywords()) {
        usage.append("\n  ").append(name);
      }
    }
  }

  private String programName = null;
  private Class<? extends Program> programType = null;
  private String[] programArguments = null;

  @Override
  protected final void processParameters (String[] parameters)
            throws SyntaxException
  {
    int count = parameters.length;

    if (count == 0) {
      throw new SyntaxException("missing program/client name");
    }

    programName = parameters[0];
    programType = knownPrograms.get(programName);

    if (programType == null) {
      throw new SyntaxException("unknown program/client: %s", programName);
    }
{'fraction_non_alphanumeric': 0.11305414940941862, 'fraction_numerical': 0.005522319374137137, 'mean_word_length': 3.6339729921819472, 'pattern_counts': {'":': 0, '<': 31, '<?xml version=': 0, '>': 31, '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': '892265', 'n_tokens_mistral': 1878, 'n_tokens_neox': 1827, 'n_words': 496}