From 2ccd4a1f40d371100b94c676c4c39c97829e153b Mon Sep 17 00:00:00 2001 From: twyen Date: Mon, 22 Jan 2018 11:52:16 -0800 Subject: Implement blocking commands Test: Unit tests PiperOrigin-RevId: 182813080 Change-Id: I952f49352fb57c02c4efb9cc4ede84dc7c32c893 --- java/com/android/dialer/commandline/Command.java | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) (limited to 'java/com/android/dialer/commandline/Command.java') diff --git a/java/com/android/dialer/commandline/Command.java b/java/com/android/dialer/commandline/Command.java index 5a35d4002..83618a255 100644 --- a/java/com/android/dialer/commandline/Command.java +++ b/java/com/android/dialer/commandline/Command.java @@ -17,15 +17,31 @@ package com.android.dialer.commandline; import android.support.annotation.NonNull; -import com.google.common.collect.ImmutableList; import com.google.common.util.concurrent.ListenableFuture; /** Handles a Command from {@link CommandLineReceiver}. */ public interface Command { - ListenableFuture run(ImmutableList args); + /** + * Thrown when {@code args} in {@link #run(Arguments)} does not match the expected format. The + * commandline will print {@code message} and {@link #getUsage()}. + */ + class IllegalCommandLineArgumentException extends Exception { + public IllegalCommandLineArgumentException(String message) { + super(message); + } + } /** Describe the command when "help" is listing available commands. */ @NonNull String getShortDescription(); + + /** + * Call when 'command --help' is called or when {@link IllegalCommandLineArgumentException} is + * thrown to inform the user how should the command be used. + */ + @NonNull + String getUsage(); + + ListenableFuture run(Arguments args) throws IllegalCommandLineArgumentException; } -- cgit v1.2.3