|
| 1 | +package org.geometrycommands; |
| 2 | + |
| 3 | +import org.geometrycommands.VersionCommand.VersionOptions; |
| 4 | + |
| 5 | +import java.io.InputStream; |
| 6 | +import java.io.Reader; |
| 7 | +import java.io.Writer; |
| 8 | +import java.util.Properties; |
| 9 | + |
| 10 | +public class VersionCommand implements Command<VersionOptions> { |
| 11 | + |
| 12 | + |
| 13 | + /** |
| 14 | + * Get the Command's name |
| 15 | + * |
| 16 | + * @return The Command's name |
| 17 | + */ |
| 18 | + @Override |
| 19 | + public String getName() { |
| 20 | + return "version"; |
| 21 | + } |
| 22 | + |
| 23 | + /** |
| 24 | + * Get the description of what the Command does |
| 25 | + * |
| 26 | + * @return The description of what the Command does |
| 27 | + */ |
| 28 | + @Override |
| 29 | + public String getDescription() { |
| 30 | + return "Get the version"; |
| 31 | + } |
| 32 | + |
| 33 | + /** |
| 34 | + * Get a new Options |
| 35 | + * |
| 36 | + * @return A new Options |
| 37 | + */ |
| 38 | + @Override |
| 39 | + public VersionOptions getOptions() { |
| 40 | + return new VersionOptions(); |
| 41 | + } |
| 42 | + |
| 43 | + /** |
| 44 | + * Execute this Command with the given Options |
| 45 | + * |
| 46 | + * @param options The Options |
| 47 | + * @param reader The java.io.Reader |
| 48 | + * @param writer The java.io.Writer |
| 49 | + * @throws Exception if an error occurs |
| 50 | + */ |
| 51 | + @Override |
| 52 | + public void execute(VersionOptions options, Reader reader, Writer writer) throws Exception { |
| 53 | + try(InputStream inputStream = VersionCommand.class.getClassLoader().getResourceAsStream("application.properties")) { |
| 54 | + Properties properties = new Properties(); |
| 55 | + properties.load(inputStream); |
| 56 | + writer.write(properties.getProperty("version")); |
| 57 | + } |
| 58 | + } |
| 59 | + |
| 60 | + public static class VersionOptions extends Options { |
| 61 | + } |
| 62 | + |
| 63 | +} |
0 commit comments