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 package net.sourceforge.plantumldependency.commoncli.option.impl.help;
26
27 import static java.util.logging.Level.INFO;
28 import static java.util.logging.Logger.getLogger;
29 import static net.sourceforge.plantumldependency.common.utils.check.ParameterCheckerUtils.checkNull;
30 import static net.sourceforge.plantumldependency.commoncli.constants.log.ErrorConstants.JAVA_PROGRAM_NULL_ERROR;
31
32 import java.util.logging.Logger;
33
34 import net.sourceforge.plantumldependency.commoncli.exception.CommandLineException;
35 import net.sourceforge.plantumldependency.commoncli.option.execution.AbstractOptionExecution;
36 import net.sourceforge.plantumldependency.commoncli.program.JavaProgram;
37
38
39
40
41
42
43
44
45
46 public class HelpOptionExecution extends AbstractOptionExecution {
47
48
49 private static final long serialVersionUID = 7861414955826853050L;
50
51
52 private static final transient Logger LOGGER = getLogger(HelpOptionExecution.class.getName());
53
54
55 private JavaProgram javaProgram;
56
57
58
59
60
61
62
63
64
65
66
67 public HelpOptionExecution(final JavaProgram program, final int optionPriority) {
68 super(optionPriority);
69 setJavaProgram(program);
70 }
71
72
73
74
75
76
77 @Override
78 public HelpOptionExecution deepClone() {
79 final HelpOptionExecution a = (HelpOptionExecution) super.deepClone();
80 a.javaProgram = getJavaProgram().deepClone();
81 return a;
82 }
83
84
85
86
87
88
89 @Override
90 public void execute() throws CommandLineException {
91 final StringBuilder buffer = getJavaProgram().getFullUsage();
92
93 final String bufferStr = buffer.toString();
94 System.out.println(bufferStr);
95 LOGGER.log(INFO, bufferStr);
96 }
97
98
99
100
101
102
103
104
105 private JavaProgram getJavaProgram() {
106 return javaProgram;
107 }
108
109
110
111
112
113
114
115
116
117 private void setJavaProgram(final JavaProgram value) {
118 checkNull(value, JAVA_PROGRAM_NULL_ERROR);
119
120 javaProgram = value;
121 }
122
123
124
125
126
127
128 @Override
129 public String toString() {
130 return getClass().getSimpleName() + " [" + super.toString() + ", javaProgram=" + javaProgram + "]";
131 }
132 }