jiacai2050 commented on code in PR #1481:
URL: 
https://github.com/apache/incubator-horaedb/pull/1481#discussion_r1503982790


##########
horaectl/src/cmd/cluster.rs:
##########
@@ -0,0 +1,45 @@
+// 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.
+
+use clap::{ArgMatches, Command};
+
+use crate::{
+    cmd::{
+        cluster_diagnose::diagnose,
+        cluster_list::list,
+        cluster_schedule::{schedule, schedule_resolve},
+    },
+    operation::cluster::{clusters_diagnose, clusters_list},
+};
+
+pub fn cluster() -> Command {
+    Command::new("cluster")

Review Comment:
   Use derive macro to define command, it's more concise. See
   
https://github.com/apache/incubator-horaedb/blob/cd70bfc2394255afdf401a6d885de2d8bd140021/src/tools/src/bin/sst-convert.rs#L48



##########
horaectl/Cargo.toml:
##########
@@ -0,0 +1,38 @@
+# 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]
+name = "horaectl"
+
+[package.license]
+workspace = true
+
+[package.version]
+workspace = true
+
+[package.edition]
+workspace = true
+
+[dependencies]
+chrono = { workspace = true }
+clap = { version = "=4.4.18", features = ["derive"] }

Review Comment:
   I thinks other crates also depend on this, make it workspace level dep.
   
   Also check for other dependencies.



##########
horaectl/src/cmd/mod.rs:
##########
@@ -0,0 +1,120 @@
+// 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.
+
+mod cluster;
+mod cluster_diagnose;
+mod cluster_list;
+mod cluster_schedule;
+pub mod quit;
+
+use std::{io, io::Write};
+
+use clap::{Arg, Command};
+
+use crate::{
+    cmd::{
+        cluster::{cluster, cluster_resolve},
+        quit::quit,
+    },
+    util::{CLUSTER_NAME, META_ADDR},
+};
+
+fn cmd() -> Command {
+    let horaectl = Command::new("horaectl")
+        .about("horaectl is a command line tool for HoraeDB")
+        .arg(
+            Arg::new("meta_addr")
+                .short('m')
+                .long("meta")
+                .value_name("META_ADDR")
+                .default_value("127.0.0.1:8080")
+                .help("meta addr is used to connect to meta server"),
+        )
+        .arg(
+            Arg::new("cluster_name")
+                .short('c')
+                .long("cluster")
+                .value_name("CLUSTER_NAME")
+                .default_value("defaultCluster")
+                .help("Cluster to connect to"),
+        );
+
+    let matches = horaectl.clone().get_matches();
+    META_ADDR
+        .set(matches.get_one::<String>("meta_addr").unwrap().to_string())
+        .unwrap();
+    CLUSTER_NAME
+        .set(
+            matches
+                .get_one::<String>("cluster_name")
+                .unwrap()
+                .to_string(),
+        )
+        .unwrap();
+
+    horaectl.subcommand(cluster()).subcommand(quit())
+}
+
+pub async fn execute() {
+    let horaectl = cmd();
+    loop {
+        print_prompt(META_ADDR.get().unwrap(), CLUSTER_NAME.get().unwrap());
+
+        let args = match read_args() {
+            Ok(args) => args,
+            Err(e) => {
+                println!("{}", e);

Review Comment:
   ```suggestion
                   println!("Read input failed, err:{e}");
   ```



-- 
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]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to