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

org.apache.sis.console.HelpCommand 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.EnumSet;
import java.util.ResourceBundle;
import java.io.IOException;
import org.apache.sis.io.TableAppender;
import org.apache.sis.util.resources.Vocabulary;


/**
 * The "help" subcommand.
 *
 * @author  Martin Desruisseaux (Geomatys)
 * @version 0.8
 * @since   0.3
 * @module
 */
final class HelpCommand extends CommandRunner {
    /**
     * The commands, in the order to be shown.
     */
    private static final String[] COMMANDS = {
        "help",
        "about",
        "mime-type",
        "metadata",
        "crs",
        "identifier",
        "transform"
    };

    /**
     * Copies the configuration of the given sub-command.
     * This constructor is used for printing help about another command.
     */
    HelpCommand(final CommandRunner parent) {
        super(parent);
    }

    /**
     * Creates the {@code "help"} sub-command.
     *
     * @param  commandIndex  index of the {@code arguments} element containing the {@code "help"} command name, or -1 if none.
     * @param  arguments     the command-line arguments provided by the user.
     * @throws InvalidOptionException if an illegal option has been provided, or the option has an illegal value.
     */
    HelpCommand(final int commandIndex, final String... arguments) throws InvalidOptionException {
        super(commandIndex, arguments, EnumSet.of(Option.LOCALE, Option.ENCODING, Option.HELP, Option.DEBUG));
    }

    /**
     * Prints the help instructions.
     *
     * @return 0 on success, or an exit code if the command failed for a reason other than a Java exception.
     * @throws IOException should never happen, because we are writing to a {@code PrintWriter}.
     */
    @Override
    public int run() throws IOException {
        if (hasUnexpectedFileCount(0, 0)) {
            return Command.INVALID_ARGUMENT_EXIT_CODE;
        }
        help(true, COMMANDS, EnumSet.allOf(Option.class));
        return 0;
    }

    /**
     * Implementation of {@link #run()}, also shared by {@link CommandRunner#help(String)}.
     *
     * @param  showHeader    {@code true} for printing the "Apache SIS" header.
     * @param  commandNames  the names of the commands to list.
     * @param  validOptions  the options to list.
     * @throws IOException should never happen, because we are writing to a {@code PrintWriter}.
     */
    void help(final boolean showHeader, final String[] commandNames, final EnumSet




© 2015 - 2025 Weber Informatics LLC | Privacy Policy