|
| 1 | +package org.geometrycommands; |
| 2 | + |
| 3 | +import org.geometrycommands.HelpCommand.HelpOptions; |
| 4 | + |
| 5 | +import java.io.Reader; |
| 6 | +import java.io.Writer; |
| 7 | + |
| 8 | +public class HelpCommand implements Command<HelpOptions> { |
| 9 | + |
| 10 | + /** |
| 11 | + * Get the Command's name |
| 12 | + * |
| 13 | + * @return The Command's name |
| 14 | + */ |
| 15 | + @Override |
| 16 | + public String getName() { |
| 17 | + return "help"; |
| 18 | + } |
| 19 | + |
| 20 | + /** |
| 21 | + * Get the description of what the Command does |
| 22 | + * |
| 23 | + * @return The description of what the Command does |
| 24 | + */ |
| 25 | + @Override |
| 26 | + public String getDescription() { |
| 27 | + return "Get help"; |
| 28 | + } |
| 29 | + |
| 30 | + /** |
| 31 | + * Get a new Options |
| 32 | + * |
| 33 | + * @return A new Options |
| 34 | + */ |
| 35 | + @Override |
| 36 | + public HelpOptions getOptions() { |
| 37 | + return new HelpOptions(); |
| 38 | + } |
| 39 | + |
| 40 | + /** |
| 41 | + * Execute this Command with the given Options |
| 42 | + * |
| 43 | + * @param options The Options |
| 44 | + * @param reader The java.io.Reader |
| 45 | + * @param writer The java.io.Writer |
| 46 | + * @throws Exception if an error occurs |
| 47 | + */ |
| 48 | + @Override |
| 49 | + public void execute(HelpOptions options, Reader reader, Writer writer) throws Exception { |
| 50 | + final String newLine = System.getProperty("line.separator"); |
| 51 | + StringBuilder builder = new StringBuilder(); |
| 52 | + builder.append("Usage: geom <command> <args>").append(newLine); |
| 53 | + builder.append(newLine); |
| 54 | + builder.append("'geom list' lists available commands.").append(newLine); |
| 55 | + builder.append(newLine); |
| 56 | + builder.append("Use 'geom <command> --help' for help using a specific command."); |
| 57 | + writer.write(builder.toString()); |
| 58 | + } |
| 59 | + |
| 60 | + public static class HelpOptions extends Options { |
| 61 | + } |
| 62 | + |
| 63 | +} |
0 commit comments