All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.apache.sis.console.CommandRunner Maven / Gradle / Ivy

The newest version!
/*
 * Licensed to the Apache Software Foundation (ASF) under one or more
 * contributor license agreements.  See the NOTICE file distributed with
 * this work for additional information regarding copyright ownership.
 * The ASF licenses this file to You under the Apache License, Version 2.0
 * (the "License"); you may not use this file except in compliance with
 * the License.  You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package org.apache.sis.console;

import java.util.List;
import java.util.ArrayList;
import java.util.Locale;
import java.util.EnumSet;
import java.util.EnumMap;
import java.util.TimeZone;
import java.io.Console;
import java.io.IOException;
import java.io.PrintWriter;
import java.io.StringWriter;
import java.io.OutputStreamWriter;
import java.nio.charset.Charset;
import org.apache.sis.util.Locales;
import org.apache.sis.util.Exceptions;
import org.apache.sis.util.resources.Errors;
import org.apache.sis.util.internal.X364;


/**
 * Base class of all sub-commands.
 * A subclasses is initialized by the {@link Command} constructor,
 * then the {@link #run()} method is invoked by {@link Command#run()}.
 *
 * @author  Martin Desruisseaux (Geomatys)
 */
abstract class CommandRunner {
    /**
     * Special value for {@code arguments[commandIndex]} meaning that this sub-command is created
     * for JUnit test purpose.
     *
     * @see #outputBuffer
     */
    static final String TEST = "TEST";

    /**
     * The instance, used by {@link ResourcesDownloader} only.
     * We use this static field as a workaround for the fact that {@code ResourcesDownloader} is not
     * instantiated by us, so we cannot pass the {@code CommandRunner} instance to its constructor.
     */
    static CommandRunner instance;

    /**
     * The name of this command, as specified by the user on the command-line.
     * May contain a mix of lower-case and upper-case letters if the user specified the command that way.
     */
    protected final String commandName;

    /**
     * The set of legal options for this command.
     *
     * @see #help(String)
     */
    private final EnumSet




© 2015 - 2024 Weber Informatics LLC | Privacy Policy