summaryrefslogtreecommitdiff
path: root/BJC-Utils2/src/main/java/bjc/utils/cli/GenericHelp.java
blob: 38adf57b29ce99af78ca4c4ad39b3e9a2ab58e2c (plain)
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
package bjc.utils.cli;

/**
 * Generic implementation of a help topic
 *
 * @author ben
 *
 */
public class GenericHelp implements CommandHelp {
	// The strings for this help topic
	private final String	summary;
	private final String	description;

	/**
	 * Create a new help topic
	 *
	 * @param summary
	 *                The summary of this help topic
	 * @param description
	 *                The description of this help topic, or null if this
	 *                help topic doesn't have a more detailed description
	 */
	public GenericHelp(final String summary, final String description) {
		if (summary == null) throw new NullPointerException("Help summary must be non-null");

		this.summary = summary;
		this.description = description;
	}

	@Override
	public String getDescription() {
		if (description == null) return summary;

		return description;
	}

	@Override
	public String getSummary() {
		return summary;
	}

	@Override
	public String toString() {
		final StringBuilder builder = new StringBuilder();

		builder.append("GenericHelp [");

		if (summary != null) {
			builder.append("summary=");
			builder.append(summary);
		}

		if (description != null) {
			builder.append(", ");
			builder.append("description=");
			builder.append(description);
		}

		builder.append("]");

		return builder.toString();
	}
}