rpuch commented on a change in pull request #647: URL: https://github.com/apache/ignite-3/pull/647#discussion_r803371012
########## File path: modules/cli/src/main/java/org/apache/ignite/cli/spec/NodeEndpointOptions.java ########## @@ -0,0 +1,80 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.ignite.cli.spec; + +import org.apache.ignite.cli.IgniteCliException; +import picocli.CommandLine; + +/** + * Prepared picocli mixin for generic node hostname option. + */ +class NodeEndpointOptions { + /** + * Custom node REST endpoint address. + */ + @CommandLine.Option( + names = "--node-endpoint", + description = "Ignite server node's REST API address and port number", + paramLabel = "host:port" + ) + private String endpoint; + + /** + * Returns REST endpoint port. + * + * @return REST endpoint port. + */ + int port() { + if (endpoint == null) { + return 10300; + } + + var hostPort = parse(); + + try { + return Integer.parseInt(hostPort[1]); + } catch (NumberFormatException ex) { + throw new IgniteCliException("Can't parse port from " + hostPort[1] + " value"); + } + } + + /** + * Returns REST endpoint host. + * + * @return REST endpoint host. + */ + String host() { + return endpoint != null ? parse()[0] : "localhost"; + } + + /** + * Parses REST endpoint host and port from string. + * + * @return 2-elements array [host, port]. + */ + private String[] parse() { + var hostPort = endpoint.split(":"); + + if (hostPort.length != 2) { + throw new IgniteCliException("Incorrect host:port pair provided " + + "(example of valid value 'localhost:10300')"); Review comment: Added it to the exception message -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
