Skip to content

Commit fcdfa01

Browse files
committed
server: Adding a help message for the case when -role option is not specified
1 parent 12a9660 commit fcdfa01

File tree

5 files changed

+72
-33
lines changed

5 files changed

+72
-33
lines changed

Diff for: java/server/src/org/openqa/grid/common/CommandLineOptionHelper.java

+23
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,29 @@ public boolean isParamPresent(String name) {
4545
return false;
4646
}
4747

48+
public boolean hasParamValue(String name) {
49+
int index = -1;
50+
for (int i = 0; i < args.length; i++) {
51+
if (name.equals(args[i])) {
52+
index = i;
53+
break;
54+
}
55+
}
56+
if (index == -1) {
57+
throw new GridConfigurationException("The parameter " + name + " isn't specified.");
58+
}
59+
60+
if (args.length == index) {
61+
return false;
62+
}
63+
64+
if (((index + 1) < args.length) && !args[index + 1].startsWith("-")) {
65+
return true;
66+
} else {
67+
return false;
68+
}
69+
}
70+
4871
public String getParamValue(String name) {
4972
int index = -1;
5073
for (int i = 0; i < args.length; i++) {

Diff for: java/server/src/org/openqa/grid/common/GridDocHelper.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ public static void printHubHelp(String msg, boolean error) {
3838
printHelpInConsole(msg, hubProperties, error);
3939
RemoteControlLauncher.printWrappedLine(
4040
"",
41-
"This synopsis lists options available in hub role only. To get help on the command line options available for other roles run the server with both -role and -help options.");
41+
"This synopsis lists options available in hub role only. To get help on the command line options available for other roles run the server with -help option and the corresponding -role option value.");
4242
}
4343

4444
public static void printNodeHelp(String msg) {
@@ -49,7 +49,7 @@ public static void printNodeHelp(String msg, boolean error) {
4949
printHelpInConsole(msg, nodeProperties, error);
5050
RemoteControlLauncher.printWrappedLine(
5151
"",
52-
"This synopsis lists options available in node role only. To get help on the command line options available for other roles run the server with both -role and -help options.");
52+
"This synopsis lists options available in node role only. To get help on the command line options available for other roles run the server with -help option and the corresponding -role option value.");
5353
}
5454

5555
private static String getParam(Properties properties, String param) {

Diff for: java/server/src/org/openqa/grid/common/GridRole.java

+1-2
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,7 @@ public static GridRole find(String[] args) {
5656
for (int i = 0; i < args.length; i++) {
5757
if ("-role".equals(args[i])) {
5858
if (i == args.length - 1) {
59-
throw new GridConfigurationException(
60-
"-role needs to be followed by the role of this component in the grid.");
59+
return null;
6160
} else {
6261
String role = args[i + 1].toLowerCase();
6362
if (nodeAliases.contains(role)) {

Diff for: java/server/src/org/openqa/grid/selenium/GridLauncher.java

+44-27
Original file line numberDiff line numberDiff line change
@@ -43,39 +43,16 @@ public class GridLauncher {
4343
private static final Logger log = Logger.getLogger(GridLauncher.class.getName());
4444

4545
public static void main(String[] args) throws Exception {
46-
4746
CommandLineOptionHelper helper = new CommandLineOptionHelper(args);
4847
GridRole role = GridRole.find(args);
4948

5049
if (role == null) {
51-
System.out.println(
52-
"\n" +
53-
"The role '" + helper.getParamValue("-role") + "' does not match a recognized role for Selenium server\n" +
54-
"\n" +
55-
"Selenium server can run in one of the following roles:\n" +
56-
" hub as a hub of a Selenium grid\n" +
57-
" node as a node of a Selenium grid\n" +
58-
" standalone as a standalone server not being a part of a grid\n" +
59-
"\n" +
60-
"If -role option is not specified the server runs standalone\n" +
61-
"\n");
62-
RemoteControlLauncher.printWrappedLine("",
63-
"To get help on the command line options available for each role run the server with both -role and -help options");
50+
printInfoAboutRoles(helper);
6451
return;
6552
}
6653

67-
if (helper.isParamPresent("-help") || helper.isParamPresent("-h")){
68-
String separator = "\n-----------------------------------------\n";
69-
if (role == GridRole.NOT_GRID) {
70-
RemoteControlLauncher.usage(separator+"To use as a standalone server"+separator);
71-
} else if (role == GridRole.HUB) {
72-
GridDocHelper.printHubHelp(
73-
separator + "To use in a grid environment as the hub:" + separator, false);
74-
} else if (role == GridRole.NODE) {
75-
GridDocHelper.printNodeHelp(separator + "To use in a grid environment as a node:" + separator, false);
76-
} else {
77-
GridDocHelper.printHubHelp(separator + "To use in a grid environment :" + separator, false);
78-
}
54+
if (helper.isParamPresent("-help") || helper.isParamPresent("-h")) {
55+
printInfoAboutOptionsForRole(role);
7956
return;
8057
}
8158

@@ -114,7 +91,47 @@ public static void main(String[] args) throws Exception {
11491
}
11592
break;
11693
default:
117-
throw new RuntimeException("NI");
94+
throw new GridConfigurationException("Unknown role: " + role);
95+
}
96+
}
97+
98+
private static void printInfoAboutRoles(CommandLineOptionHelper helper) {
99+
if (helper.hasParamValue("-role")) {
100+
RemoteControlLauncher.printWrappedLine(
101+
"",
102+
"Error: the role '" + helper.getParamValue("-role") + "' does not match a recognized server role\n");
103+
} else {
104+
RemoteControlLauncher.printWrappedLine(
105+
"",
106+
"Error: -role option needs to be followed by the value that defines role of this component in the grid\n");
107+
}
108+
System.out.println(
109+
"Selenium server can run in one of the following roles:\n" +
110+
" hub as a hub of a Selenium grid\n" +
111+
" node as a node of a Selenium grid\n" +
112+
" standalone as a standalone server not being a part of a grid\n" +
113+
"\n" +
114+
"If -role option is omitted the server runs standalone\n");
115+
RemoteControlLauncher.printWrappedLine(
116+
"",
117+
"To get help on the options available for a specific role run the server"
118+
+ " with -help option and the corresponding -role option value");
119+
}
120+
121+
private static void printInfoAboutOptionsForRole(GridRole role) {
122+
String separator = "\n-------------------------------\n";
123+
switch (role) {
124+
case NOT_GRID:
125+
RemoteControlLauncher.usage(separator + "Running as a standalone server:" + separator);
126+
break;
127+
case HUB:
128+
GridDocHelper.printHubHelp(separator + "Running as a grid hub:" + separator, false);
129+
break;
130+
case NODE:
131+
GridDocHelper.printNodeHelp(separator + "Running as a grid node:" + separator, false);
132+
break;
133+
default:
134+
throw new GridConfigurationException("Unknown role: " + role);
118135
}
119136
}
120137

Diff for: java/server/src/org/openqa/selenium/server/cli/RemoteControlLauncher.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ public class RemoteControlLauncher {
3131

3232
public static void usage(String msg) {
3333
if (msg != null) {
34-
System.out.println(msg + ":");
34+
System.out.println(msg);
3535
}
3636
String INDENT = " ";
3737
String INDENT2X = INDENT + INDENT;
@@ -109,7 +109,7 @@ public static void usage(String msg) {
109109
"then all \"https\" strings in the HTML of the test application will be changed to be \"http\".");
110110
printWrappedLine(
111111
"",
112-
"\nThis synopsis lists options available in standalone role only. To get help on the command line options available for other roles run the server with both -role and -help options.");
112+
"\nThis synopsis lists options available in standalone role only. To get help on the options available for other roles run the server with -help option and the corresponding -role option value.");
113113
}
114114

115115
public static RemoteControlConfiguration parseLauncherOptions(String[] args) {

0 commit comments

Comments
 (0)