1 /* 2 * Copyright (C) 2018 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License 15 */ 16 17 package com.android.dialer.commandline; 18 19 import android.support.annotation.NonNull; 20 import com.google.common.util.concurrent.ListenableFuture; 21 22 /** Handles a Command from {@link CommandLineReceiver}. */ 23 public interface Command { 24 25 /** 26 * Thrown when {@code args} in {@link #run(Arguments)} does not match the expected format. The 27 * commandline will print {@code message} and {@link #getUsage()}. 28 */ 29 class IllegalCommandLineArgumentException extends Exception { IllegalCommandLineArgumentException(String message)30 public IllegalCommandLineArgumentException(String message) { 31 super(message); 32 } 33 } 34 35 /** Describe the command when "help" is listing available commands. */ 36 @NonNull getShortDescription()37 String getShortDescription(); 38 39 /** 40 * Call when 'command --help' is called or when {@link IllegalCommandLineArgumentException} is 41 * thrown to inform the user how should the command be used. 42 */ 43 @NonNull getUsage()44 String getUsage(); 45 run(Arguments args)46 ListenableFuture<String> run(Arguments args) throws IllegalCommandLineArgumentException; 47 } 48