001/*
002 * Copyright 2012-2017 the original author or authors.
003 *
004 * Licensed under the Apache License, Version 2.0 (the "License");
005 * you may not use this file except in compliance with the License.
006 * You may obtain a copy of the License at
007 *
008 *      http://www.apache.org/licenses/LICENSE-2.0
009 *
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS,
012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 * See the License for the specific language governing permissions and
014 * limitations under the License.
015 */
016
017package org.springframework.boot;
018
019import java.util.List;
020import java.util.Set;
021
022/**
023 * Provides access to the arguments that were used to run a {@link SpringApplication}.
024 *
025 * @author Phillip Webb
026 * @since 1.3.0
027 */
028public interface ApplicationArguments {
029
030        /**
031         * Return the raw unprocessed arguments that were passed to the application.
032         * @return the arguments
033         */
034        String[] getSourceArgs();
035
036        /**
037         * Return the names of all option arguments. For example, if the arguments were
038         * "--foo=bar --debug" would return the values {@code ["foo", "debug"]}.
039         * @return the option names or an empty set
040         */
041        Set<String> getOptionNames();
042
043        /**
044         * Return whether the set of option arguments parsed from the arguments contains an
045         * option with the given name.
046         * @param name the name to check
047         * @return {@code true} if the arguments contain an option with the given name
048         */
049        boolean containsOption(String name);
050
051        /**
052         * Return the collection of values associated with the arguments option having the
053         * given name.
054         * <ul>
055         * <li>if the option is present and has no argument (e.g.: "--foo"), return an empty
056         * collection ({@code []})</li>
057         * <li>if the option is present and has a single value (e.g. "--foo=bar"), return a
058         * collection having one element ({@code ["bar"]})</li>
059         * <li>if the option is present and has multiple values (e.g. "--foo=bar --foo=baz"),
060         * return a collection having elements for each value ({@code ["bar", "baz"]})</li>
061         * <li>if the option is not present, return {@code null}</li>
062         * </ul>
063         * @param name the name of the option
064         * @return a list of option values for the given name
065         */
066        List<String> getOptionValues(String name);
067
068        /**
069         * Return the collection of non-option arguments parsed.
070         * @return the non-option arguments or an empty list
071         */
072        List<String> getNonOptionArgs();
073
074}