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

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

There is a newer version: 1.4
Show 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.EnumSet;
import java.util.Locale;
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)
 * @since   0.3
 * @version 0.4
 * @module
 */
final class HelpSC extends SubCommand {
    /**
     * The commands, in the order to be shown.
     */
    private static final String[] COMMANDS = {
        "help",
        "about",
        "mime-type",
        "metadata",
        "crs"
    };

    /**
     * Copies the configuration of the given sub-command. This constructor is used
     * for printing help about an other command.
     */
    HelpSC(final SubCommand parent) {
        super(parent);
    }

    /**
     * Creates the {@code "help"} sub-command.
     */
    HelpSC(final int commandIndex, final String... args) throws InvalidOptionException {
        super(commandIndex, args, EnumSet.of(Option.LOCALE, Option.ENCODING, Option.HELP));
    }

    /**
     * Prints the help instructions.
     */
    @Override
    public int run() {
        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 SubCommand#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.
     */
    void help(final boolean showHeader, final String[] commandNames, final EnumSet




© 2015 - 2024 Weber Informatics LLC | Privacy Policy