001/* 002 * SPDX-FileCopyrightText: none 003 * SPDX-License-Identifier: CC0-1.0 004 */ 005 006package gov.nist.secauto.metaschema.cli.processor.command; 007 008import gov.nist.secauto.metaschema.cli.processor.CLIProcessor.CallingContext; 009import gov.nist.secauto.metaschema.cli.processor.InvalidArgumentException; 010import gov.nist.secauto.metaschema.core.util.CollectionUtil; 011 012import org.apache.commons.cli.CommandLine; 013import org.apache.commons.cli.Option; 014 015import java.util.Collection; 016import java.util.List; 017 018import edu.umd.cs.findbugs.annotations.NonNull; 019 020public interface ICommand { 021 @NonNull 022 String getName(); 023 024 @NonNull 025 String getDescription(); 026 027 @NonNull 028 default List<ExtraArgument> getExtraArguments() { 029 return CollectionUtil.emptyList(); 030 } 031 032 default int requiredExtraArgumentsCount() { 033 return (int) getExtraArguments().stream() 034 .filter(ExtraArgument::isRequired) 035 .count(); 036 } 037 038 @NonNull 039 default Collection<? extends Option> gatherOptions() { 040 // by default there are no options to handle 041 return CollectionUtil.emptyList(); 042 } 043 044 @NonNull 045 Collection<ICommand> getSubCommands(); 046 047 boolean isSubCommandRequired(); 048 049 @SuppressWarnings("unused") 050 default ICommand getSubCommandByName(@NonNull String name) { 051 // no sub commands by default 052 return null; 053 } 054 055 @SuppressWarnings("unused") 056 default void validateOptions( 057 @NonNull CallingContext callingContext, 058 @NonNull CommandLine cmdLine) throws InvalidArgumentException { 059 // by default there are no options to handle 060 } 061 062 @NonNull 063 ICommandExecutor newExecutor(@NonNull CallingContext callingContext, @NonNull CommandLine cmdLine); 064}