Skip to content

Commit

Permalink
Добавил help и вынес название программы
Browse files Browse the repository at this point in the history
  • Loading branch information
khasanovbi committed Jan 17, 2017
1 parent a6c260b commit 080f8df
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 5 deletions.
2 changes: 2 additions & 0 deletions build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#!/bin/bash
mvn clean compile assembly:single
15 changes: 14 additions & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<groupId>ru.khasanov</groupId>
<artifactId>flash</artifactId>
<packaging>jar</packaging>
<version>1.0-SNAPSHOT</version>
<version>0.1.0</version>
<build>
<plugins>
<plugin>
Expand All @@ -15,6 +15,19 @@
<target>1.7</target>
</configuration>
</plugin>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<configuration>
<archive>
<manifest>
<mainClass>ru.khasanov.Main</mainClass>
</manifest>
</archive>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
</configuration>
</plugin>
</plugins>
</build>
<name>flash</name>
Expand Down
5 changes: 5 additions & 0 deletions src/main/java/ru/khasanov/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,13 @@ private static void disableLogging() {
public static void main(String[] args) {
Settings settings = new Settings();
JCommander jCommander = new JCommander(settings);
jCommander.setProgramName(Server.NAME);
try {
jCommander.parse(args);
if (settings.isHelp()) {
jCommander.usage();
return;
}
if (!settings.isLoggingEnable()) {
disableLogging();
}
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/ru/khasanov/Server.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
* Created by bulat on 06.01.17.
*/
public class Server {
public static final String NAME = "Flash";
public static final String VERSION = "0.1.0";
private static final Integer MIN_WORKER_COUNT = 2;
private static final Logger logger = LoggerFactory.getLogger(Server.class);
Expand Down Expand Up @@ -88,7 +89,7 @@ public ServerSocketChannel initServerSocketChannel() throws IOException {
serverSocketChannel.configureBlocking(false);
SocketAddress socketAddress = new InetSocketAddress("localhost", settings.getPort());
serverSocketChannel.socket().bind(socketAddress);
System.out.println(String.format("Started Flash %s server at %s", VERSION, socketAddress));
System.out.println(String.format("Started %s %s server at %s", NAME, VERSION, socketAddress));
return serverSocketChannel;
}

Expand Down
2 changes: 1 addition & 1 deletion src/main/java/ru/khasanov/http/Response.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public void setDefaultHeaders() {
}

public void setServerHeader() {
headers.put(ResponseHeader.SERVER, "Flash/" + Server.VERSION);
headers.put(ResponseHeader.SERVER, String.format("%s/%s", Server.NAME, Server.VERSION));
}

public StatusCode getStatusCode() {
Expand Down
8 changes: 6 additions & 2 deletions src/main/java/ru/khasanov/settings/Settings.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,20 @@
* Created by bulat on 06.01.17.
*/
public class Settings {
@Parameter(names = {"-h", "--help"}, help = true, description = "Display help information")
private boolean help = false;
@Parameter(names = {"-c", "--cache"}, arity = 1, description = "Enable cache using")
private boolean cacheEnable = true;
@Parameter(names = {"-r", "--root-directory"}, description = "Set root directory path",
validateWith = DirectoryExistsValidator.class)
private String rootDirectory = "root_dir";
@Parameter(names = {"-p", "--port"}, description = "Set port", validateWith = PortValidator.class)
private int port = 8080;
@Parameter(names = {"-l", "--loggingEnable"}, arity = 1, description = "Enable logging")
@Parameter(names = {"-l", "--logging-enable"}, arity = 1, description = "Enable logging")
private boolean loggingEnable = true;

public boolean isHelp() {
return help;
}
public boolean isCacheEnable() {
return cacheEnable;
}
Expand Down

0 comments on commit 080f8df

Please sign in to comment.