adoroszlai commented on code in PR #8030:
URL: https://github.com/apache/ozone/pull/8030#discussion_r1991581473


##########
hadoop-ozone/dist/src/shell/ozone/ozone:
##########
@@ -103,6 +104,10 @@ function ozonecmd_case
         exit -1
       fi
     ;;
+    completion)
+      OZONE_CLASSNAME=org.apache.hadoop.ozone.utils.AutoCompletion;
+      OZONE_RUN_ARTIFACT_NAME="ozone-tools"
+    ;;

Review Comment:
   I prefer your original idea about adding this as `ozone util completion` 
(let's wait for more feedback on this before changing anything).  Candidates 
for moving under `ozone util` in the future:
   
   - `checknative`
   - `classpath`
   - `envvars`
   
   (Or maybe these belong to `ozone debug`?)
   
   Maybe also the following, but need to examine what they are exactly, and if 
we still need them.
   
   - `daemonlog`
   - `dtutil`



##########
hadoop-ozone/tools/src/main/java/org/apache/hadoop/ozone/utils/AutoCompletion.java:
##########
@@ -0,0 +1,128 @@
+/*
+ * 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.hadoop.ozone.utils;
+
+import java.util.Objects;
+import org.apache.hadoop.hdds.cli.GenericCli;
+import org.apache.ratis.util.ReflectionUtils;
+import org.reflections.Reflections;
+import picocli.AutoComplete;
+import picocli.CommandLine;
+import picocli.CommandLine.Option;
+
+/**
+ * Tool to generate bash/zsh auto-complete scripts for Ozone CLI.
+ */
+public final class AutoCompletion {
+
+  private static final String OZONE_COMMAND = "ozone ";
+  private static final int PREFIX_LENGTH = OZONE_COMMAND.length();
+  private static final String[] PACKAGES_TO_SCAN = {
+      "org.apache.hadoop.hdds",
+      "org.apache.hadoop.ozone",
+      "org.apache.ozone",
+  };
+
+  private AutoCompletion() { }
+
+  public static void main(String[] args) {
+    final CommandLine ozone = new CommandLine(new Ozone());
+    for (String pkg : PACKAGES_TO_SCAN) {
+      new Reflections(pkg).getSubTypesOf(GenericCli.class).stream()
+          .map(AutoCompletion::getCommand).filter(Objects::nonNull)
+          .filter(cmd -> commandFilter(cmd.getCommandSpec()))

Review Comment:
   If we change the parameter to `CommandLine cmd` (and method name to 
something like `isPublicCommand`, which I think better describes the 
intention), then this filter can use a method reference like 
`.filter(AutoCompletion::isPublicCommand)`.



##########
hadoop-ozone/tools/src/main/java/org/apache/hadoop/ozone/utils/AutoCompletion.java:
##########
@@ -0,0 +1,128 @@
+/*
+ * 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.hadoop.ozone.utils;
+
+import java.util.Objects;
+import org.apache.hadoop.hdds.cli.GenericCli;
+import org.apache.ratis.util.ReflectionUtils;
+import org.reflections.Reflections;
+import picocli.AutoComplete;
+import picocli.CommandLine;
+import picocli.CommandLine.Option;
+
+/**
+ * Tool to generate bash/zsh auto-complete scripts for Ozone CLI.
+ */
+public final class AutoCompletion {
+
+  private static final String OZONE_COMMAND = "ozone ";
+  private static final int PREFIX_LENGTH = OZONE_COMMAND.length();
+  private static final String[] PACKAGES_TO_SCAN = {
+      "org.apache.hadoop.hdds",
+      "org.apache.hadoop.ozone",
+      "org.apache.ozone",
+  };
+
+  private AutoCompletion() { }
+
+  public static void main(String[] args) {
+    final CommandLine ozone = new CommandLine(new Ozone());
+    for (String pkg : PACKAGES_TO_SCAN) {
+      new Reflections(pkg).getSubTypesOf(GenericCli.class).stream()
+          .map(AutoCompletion::getCommand).filter(Objects::nonNull)

Review Comment:
   Best have one pipeline op per line.
   
   ```suggestion
             .map(AutoCompletion::getCommand)
             .filter(Objects::nonNull)
   ```



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