1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.apache.maven.index.cli;
20
21 import java.io.File;
22 import java.io.IOException;
23 import java.io.PrintStream;
24 import java.util.ArrayList;
25 import java.util.Comparator;
26 import java.util.List;
27
28 import org.apache.commons.cli.Option;
29 import org.codehaus.plexus.util.FileUtils;
30 import org.junit.Test;
31
32 public class NexusIndexerCliTest extends AbstractNexusIndexerCliTest {
33
34 protected NexusIndexerCli cli;
35
36 @Override
37 public void setUp() throws Exception {
38 super.setUp();
39
40 cli = new NexusIndexerCli();
41
42 System.setOut(new PrintStream(out));
43 System.setErr(new PrintStream(out));
44 }
45
46 @Override
47 protected int execute(String... args) {
48 return cli.execute(args);
49 }
50
51 private static final String LS = System.getProperty("line.separator");
52
53 private static class OptionComparator implements Comparator<Option> {
54 public int compare(Option opt1, Option opt2) {
55 return opt1.getOpt().compareToIgnoreCase(opt2.getOpt());
56 }
57 }
58
59 public String getOptionsAsHtml() {
60 List<Option> optList =
61 new ArrayList<>(new NexusIndexerCli().buildCliOptions().getOptions());
62 optList.sort(new OptionComparator());
63
64 StringBuilder sb = new StringBuilder();
65 boolean a = true;
66 sb.append(
67 "<table border='1' class='zebra-striped'><tr class='a'><th><b>Options</b></th><th><b>Description</b></th></tr>");
68 for (Option option : optList) {
69 a = !a;
70 sb.append("<tr class='").append(a ? 'a' : 'b').append("'><td><code>-<a name='");
71 sb.append(option.getOpt());
72 sb.append("'>");
73 sb.append(option.getOpt());
74 sb.append("</a>,--<a name='");
75 sb.append(option.getLongOpt());
76 sb.append("'>");
77 sb.append(option.getLongOpt());
78 sb.append("</a>");
79 if (option.hasArg()) {
80 if (option.hasArgName()) {
81 sb.append(" <").append(option.getArgName()).append(">");
82 } else {
83 sb.append(' ');
84 }
85 }
86 sb.append("</code></td><td>");
87 sb.append(option.getDescription());
88 sb.append("</td></tr>");
89 sb.append(LS);
90 }
91 sb.append("</table>");
92 return sb.toString();
93 }
94
95 @Test
96 public void testOptionsAsHtml() throws IOException {
97 File options = getTestFile("target/test-classes/options.html");
98 FileUtils.fileWrite(options, "UTF-8", getOptionsAsHtml());
99 }
100 }