forked from jooby-project/jooby
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCmd.java
More file actions
47 lines (41 loc) · 951 Bytes
/
Cmd.java
File metadata and controls
47 lines (41 loc) · 951 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
/**
* Jooby https://jooby.io
* Apache License Version 2.0 https://jooby.io/LICENSE.txt
* Copyright 2014 Edgar Espina
*/
package io.jooby.cli;
import javax.annotation.Nonnull;
/**
* Base class for application commands.
*
* @since 2.0.5
*/
public abstract class Cmd implements Runnable {
private Context context;
@Override public void run() {
try {
run(context);
} catch (Throwable x) {
sneakyThrow0(x);
}
}
/**
* Run a command.
*
* @param context Command context.
* @throws Exception If something goes wrong.
*/
public abstract void run(@Nonnull Context context) throws Exception;
/**
* Set command context.
*
* @param context Command context.
*/
public void setContext(@Nonnull Context context) {
this.context = context;
}
@SuppressWarnings("unchecked")
private static <E extends Throwable> void sneakyThrow0(final Throwable x) throws E {
throw (E) x;
}
}