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

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

/*
 * 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.Locale;
import java.util.logging.LogManager;
import java.util.logging.ConsoleHandler;
import java.io.Console;
import java.io.PrintStream;
import java.io.PrintWriter;
import java.io.IOException;
import java.sql.SQLException;
import org.opengis.referencing.operation.TransformException;
import org.apache.sis.storage.DataStoreException;
import org.apache.sis.util.ArraysExt;
import org.apache.sis.util.resources.Errors;
import org.apache.sis.util.logging.MonolineFormatter;


/**
 * Command line interface for Apache SIS. The {@link #main(String[])} method accepts the following actions:
 *
 * 
* * * * * * * * *
Supported command-line actions
{@code help} Show a help overview.
{@code about} Show information about Apache SIS and system configuration.
{@code mime-type} Show MIME type for the given file.
{@code metadata} Show metadata information for the given file.
{@code crs} Show Coordinate Reference System information for the given file or code.
{@code identifier} Show identifiers for metadata and referencing systems in the given file.
{@code transform} Convert or transform coordinates from given source CRS to target CRS.
* * Each command can accepts some of the following options: * *
* * * * * * * * * * * * *
Supported command-line options
{@code --sourceCRS} The Coordinate Reference System of input data.
{@code --targetCRS} The Coordinate Reference System of output data.
{@code --format} The output format: {@code xml}, {@code wkt}, {@code wkt1} or {@code text}.
{@code --locale} The locale to use for the command output.
{@code --timezone} The timezone for the dates to be formatted.
{@code --encoding} The encoding to use for the command outputs and some inputs.
{@code --colors} Whether colorized output shall be enabled.
{@code --brief} Whether the output should contains only brief information.
{@code --verbose} Whether the output should contains more detailed information.
{@code --debug} Prints full stack trace in case of failure.
{@code --help} Lists the options available for a specific command.
* * The {@code --locale}, {@code --timezone} and {@code --encoding} options apply to the command output sent * to the {@linkplain System#out standard output stream}, but usually do not apply to the error messages sent * to the {@linkplain System#err standard error stream}. The reason is that command output may be targeted to * a client, while the error messages are usually for the operator. * *

SIS installation on remote machines

* Some sub-commands can operate on SIS installation on remote machines, provided that remote access has been enabled * at the Java Virtual Machine startup time. See {@linkplain org.apache.sis.console package javadoc} for more information. * * @author Martin Desruisseaux (Geomatys) * @version 0.8 * @since 0.3 * @module */ public final class Command { /** * The code given to {@link System#exit(int)} when the program failed because of a unknown sub-command. */ public static final int INVALID_COMMAND_EXIT_CODE = 1; /** * The code given to {@link System#exit(int)} when the program failed because of a unknown option. * The set of valid options depend on the sub-command to execute. */ public static final int INVALID_OPTION_EXIT_CODE = 2; /** * The code given to {@link System#exit(int)} when the program failed because of an illegal user argument. * The user arguments are everything which is not a command name or an option. They are typically file names, * but can occasionally be other types like URL. */ public static final int INVALID_ARGUMENT_EXIT_CODE = 3; /** * The code given to {@link System#exit(int)} when a file given in argument uses an unknown file format. */ public static final int UNKNOWN_STORAGE_EXIT_CODE = 4; /** * The code given to {@link System#exit(int)} when the program failed because of an {@link java.io.IOException}. */ public static final int IO_EXCEPTION_EXIT_CODE = 100; /** * The code given to {@link System#exit(int)} when the program failed because of an {@link java.sql.SQLException}. */ public static final int SQL_EXCEPTION_EXIT_CODE = 101; /** * The code given to {@link System#exit(int)} when the program failed for a reason * other than the ones enumerated in the above constants. */ public static final int OTHER_ERROR_EXIT_CODE = 199; /** * The sub-command to execute. */ private final CommandRunner command; /** * Creates a new command for the given arguments. The first value in the given array which is * not an option is taken as the command name. All other values are options or filenames. * * @param args the command-line arguments. * @throws InvalidCommandException if an invalid command has been given. * @throws InvalidOptionException if the given arguments contain an invalid option. */ protected Command(final String[] args) throws InvalidCommandException, InvalidOptionException { int commandIndex = -1; String commandName = null; for (int i=0; i




© 2015 - 2025 Weber Informatics LLC | Privacy Policy