@@ -25,12 +25,40 @@ private void parseCommandLine(String[] args) {
25
25
CommandLineParser parser = new DefaultParser ();
26
26
try {
27
27
CommandLine commands = parser .parse (this .OPTIONS , args , true );
28
- this .uri = this .parseUri (commands .getOptionValue (FUNCTIONS_URI_OPTION ));
29
- this .workerId = this .parseWorkerId (commands .getOptionValue (FUNCTIONS_WORKER_ID_OPTION ));
30
- this .requestId = this .parseRequestId (commands .getOptionValue (FUNCTIONS_REQUEST_ID_OPTION ));
31
- this .logToConsole = commands .hasOption (FUNCTIONS_CONSOLE_LOG_OPTION );
28
+
29
+ if (commands .hasOption ("fu" )) {
30
+ this .uri = this .parseUri (commands .getOptionValue (FUNCTIONS_URI_OPTION ));
31
+ }else if (commands .hasOption ("h" ) && commands .hasOption ("p" )) {
32
+ this .host = this .parseHost (commands .getOptionValue ("h" ));
33
+ this .port = this .parsePort (commands .getOptionValue ("p" ));
34
+ }else {
35
+ throw new ParseException ("Error parsing command line options. Please include functions host and port or uri." );
36
+ }
37
+
38
+ if (commands .hasOption ("fw" )) {
39
+ this .workerId = this .parseWorkerId (commands .getOptionValue (FUNCTIONS_WORKER_ID_OPTION ));
40
+ }else if (commands .hasOption ("w" )) {
41
+ this .workerId = this .parseWorkerId (commands .getOptionValue ("w" ));
42
+ }else {
43
+ throw new ParseException ("Error parsing command line options. Please include worker id." );
44
+ }
45
+
46
+ if (commands .hasOption ("fq" )) {
47
+ this .requestId = this .parseRequestId (commands .getOptionValue (FUNCTIONS_REQUEST_ID_OPTION ));
48
+ }else if (commands .hasOption ("q" )) {
49
+ this .requestId = this .parseRequestId (commands .getOptionValue ("q" ));
50
+ }else {
51
+ throw new ParseException ("Error parsing command line options. Please include request id." );
52
+ }
53
+
54
+ this .logToConsole = commands .hasOption (FUNCTIONS_CONSOLE_LOG_OPTION ) || commands .hasOption ("l" );
55
+
32
56
if (commands .hasOption (FUNCTIONS_GRPC_MAX_MESSAGE_LENGTH_OPTION )) {
33
57
this .maxMessageSize = this .parseMaxMessageSize (commands .getOptionValue (FUNCTIONS_GRPC_MAX_MESSAGE_LENGTH_OPTION ));
58
+ } else if (commands .hasOption ("m" )) {
59
+ this .maxMessageSize = this .parseMaxMessageSize (commands .getOptionValue ("m" ));
60
+ }else {
61
+ throw new ParseException ("Error parsing command line options. Please include message size in bytes." );
34
62
}
35
63
this .commandParseSucceeded = true ;
36
64
} catch (ParseException ex ) {
@@ -61,26 +89,46 @@ public static void main(String[] args) {
61
89
private boolean logToConsole ;
62
90
private Integer maxMessageSize = null ;
63
91
private final Options OPTIONS = new Options ()
64
- .addOption (Option .builder ("u" ).longOpt (FUNCTIONS_URI_OPTION )
92
+ .addOption (Option .builder ("h" ).longOpt ("host" )
93
+ .hasArg ().argName ("HostName" )
94
+ .desc ("The address of the machine that the Azure Functions host is running on" )
95
+ .build ())
96
+ .addOption (Option .builder ("p" ).longOpt ("port" )
97
+ .hasArg ().argName ("PortNumber" )
98
+ .desc ("The port number which the Azure Functions host is listening to" )
99
+ .build ())
100
+ .addOption (Option .builder ("w" ).longOpt ("workerId" )
101
+ .hasArg ().argName ("WorkerId" )
102
+ .desc ("The ID of this running worker throughout communication session" )
103
+ .build ())
104
+ .addOption (Option .builder ("q" ).longOpt ("requestId" )
105
+ .hasArg ().argName ("RequestId" )
106
+ .desc ("The startup request ID of this communication session" )
107
+ .build ())
108
+ .addOption (Option .builder ("l" ).longOpt ("consoleLog" )
109
+ .desc ("Whether to duplicate all host logs to console as well" )
110
+ .build ())
111
+ .addOption (Option .builder ("m" ).longOpt ("grpcMaxMessageLength" )
112
+ .hasArg ().argName ("MessageSizeInBytes" )
113
+ .desc ("The maximum message size could be used by GRPC protocol" )
114
+ .build ())
115
+ .addOption (Option .builder ("fu" ).longOpt (FUNCTIONS_URI_OPTION )
65
116
.hasArg ().argName ("Uri" )
66
117
.desc ("The uri of the machine that the Azure Functions host is running on" )
67
- .required ()
68
118
.build ())
69
- .addOption (Option .builder ("w " ).longOpt (FUNCTIONS_WORKER_ID_OPTION )
119
+ .addOption (Option .builder ("fw " ).longOpt (FUNCTIONS_WORKER_ID_OPTION )
70
120
.hasArg ().argName ("WorkerId" )
71
121
.desc ("The ID of this running worker throughout communication session" )
72
- .required ()
73
122
.build ())
74
- .addOption (Option .builder ("q " ).longOpt (FUNCTIONS_REQUEST_ID_OPTION )
123
+ .addOption (Option .builder ("fq " ).longOpt (FUNCTIONS_REQUEST_ID_OPTION )
75
124
.hasArg ().argName ("RequestId" )
76
125
.desc ("The startup request ID of this communication session" )
77
- .required ()
78
126
.build ())
79
- .addOption (Option .builder ("l " ).longOpt (FUNCTIONS_GRPC_MAX_MESSAGE_LENGTH_OPTION )
127
+ .addOption (Option .builder ("fm " ).longOpt (FUNCTIONS_GRPC_MAX_MESSAGE_LENGTH_OPTION )
80
128
.hasArg ().argName ("MessageSizeInBytes" )
81
129
.desc ("The maximum message size could be used by GRPC protocol" )
82
130
.build ())
83
- .addOption (Option .builder ("m " ).longOpt (FUNCTIONS_CONSOLE_LOG_OPTION )
131
+ .addOption (Option .builder ("fl " ).longOpt (FUNCTIONS_CONSOLE_LOG_OPTION )
84
132
.desc ("Whether to duplicate all host logs to console as well" )
85
133
.build ());
86
134
@@ -89,6 +137,21 @@ public String getHost() {
89
137
return this .host ;
90
138
}
91
139
140
+ private String parseHost (String input ) { return input ; }
141
+
142
+ private int parsePort (String input ) throws ParseException {
143
+ try {
144
+ int result = Integer .parseInt (input );
145
+ if (result < 1 || result > 65535 ) {
146
+ throw new IndexOutOfBoundsException ("port number out of range" );
147
+ }
148
+ return result ;
149
+ } catch (NumberFormatException | IndexOutOfBoundsException ex ) {
150
+ throw new ParseException (String .format (
151
+ "port number \" %s\" is not qualified. It must be an integer within range [1, 65535]" , input ));
152
+ }
153
+ }
154
+
92
155
@ Override
93
156
public int getPort () {
94
157
return this .port ;
0 commit comments