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


##########
hadoop-ozone/tools/src/main/java/org/apache/hadoop/ozone/utils/AutoCompletion.java:
##########
@@ -0,0 +1,164 @@
+/*
+ * 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 org.apache.hadoop.hdds.scm.server.StorageContainerManagerStarter;
+import org.apache.hadoop.ozone.HddsDatanodeService;
+import org.apache.hadoop.ozone.admin.OzoneAdmin;
+import org.apache.hadoop.ozone.audit.parser.AuditParser;
+import org.apache.hadoop.ozone.conf.OzoneGetConf;
+import org.apache.hadoop.ozone.csi.CsiServer;
+import org.apache.hadoop.ozone.debug.OzoneDebug;
+import org.apache.hadoop.ozone.freon.Freon;
+import org.apache.hadoop.ozone.genconf.GenerateOzoneRequiredConfigurations;
+import org.apache.hadoop.ozone.insight.Insight;
+import org.apache.hadoop.ozone.om.OzoneManagerStarter;
+import org.apache.hadoop.ozone.recon.ReconServer;
+import org.apache.hadoop.ozone.repair.OzoneRepair;
+import org.apache.hadoop.ozone.s3.Gateway;
+import org.apache.hadoop.ozone.shell.OzoneRatis;
+import org.apache.hadoop.ozone.shell.OzoneShell;
+import org.apache.hadoop.ozone.shell.checknative.CheckNative;
+import org.apache.hadoop.ozone.shell.s3.S3Shell;
+import org.apache.hadoop.ozone.shell.tenant.TenantShell;
+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 AutoCompletion() { }
+
+  public static void main(String[] args) {
+
+    CommandLine hierarchy = new CommandLine(new Ozone())
+        .addSubcommand("admin", new OzoneAdmin().getCmd())
+        .addSubcommand("auditparser", new AuditParser().getCmd())
+        .addSubcommand("checknative", new CheckNative().getCmd())
+        .addSubcommand("csi", new CsiServer().getCmd())
+        .addSubcommand("datanode", new HddsDatanodeService().getCmd())
+        .addSubcommand("debug", new OzoneDebug().getCmd())
+        .addSubcommand("freon", new Freon().getCmd())
+        .addSubcommand("genconf", new 
GenerateOzoneRequiredConfigurations().getCmd())
+        .addSubcommand("getconf", new OzoneGetConf().getCmd())
+        .addSubcommand("httpfs", new HttpFSServerWebServer())
+        .addSubcommand("insight", new Insight().getCmd())
+        .addSubcommand("om", new OzoneManagerStarter(null).getCmd())
+        .addSubcommand("ratis", new OzoneRatis().getCmd())
+        .addSubcommand("recon", new ReconServer().getCmd())
+        .addSubcommand("repair", new OzoneRepair().getCmd())
+        .addSubcommand("s3", new S3Shell().getCmd())
+        .addSubcommand("s3g", new Gateway().getCmd())
+        .addSubcommand("scm", new 
StorageContainerManagerStarter(null).getCmd())
+        .addSubcommand("sh", new OzoneShell().getCmd(), "shell")
+        .addSubcommand("tenant", new TenantShell().getCmd())
+        .addSubcommand("version", new OzoneVersionInfo());
+
+    /*
+     * The following commands are marked as hidden,
+     * so they won't have auto complete.
+     *   - OzoneAdmin

Review Comment:
   I think `OzoneAdmin` can be made visible.  It's no more dangerous than 
`OzoneRepair`.



##########
hadoop-ozone/tools/src/main/java/org/apache/hadoop/ozone/utils/AutoCompletion.java:
##########
@@ -0,0 +1,164 @@
+/*
+ * 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 org.apache.hadoop.hdds.scm.server.StorageContainerManagerStarter;
+import org.apache.hadoop.ozone.HddsDatanodeService;
+import org.apache.hadoop.ozone.admin.OzoneAdmin;
+import org.apache.hadoop.ozone.audit.parser.AuditParser;
+import org.apache.hadoop.ozone.conf.OzoneGetConf;
+import org.apache.hadoop.ozone.csi.CsiServer;
+import org.apache.hadoop.ozone.debug.OzoneDebug;
+import org.apache.hadoop.ozone.freon.Freon;
+import org.apache.hadoop.ozone.genconf.GenerateOzoneRequiredConfigurations;
+import org.apache.hadoop.ozone.insight.Insight;
+import org.apache.hadoop.ozone.om.OzoneManagerStarter;
+import org.apache.hadoop.ozone.recon.ReconServer;
+import org.apache.hadoop.ozone.repair.OzoneRepair;
+import org.apache.hadoop.ozone.s3.Gateway;
+import org.apache.hadoop.ozone.shell.OzoneRatis;
+import org.apache.hadoop.ozone.shell.OzoneShell;
+import org.apache.hadoop.ozone.shell.checknative.CheckNative;
+import org.apache.hadoop.ozone.shell.s3.S3Shell;
+import org.apache.hadoop.ozone.shell.tenant.TenantShell;
+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 AutoCompletion() { }
+
+  public static void main(String[] args) {
+
+    CommandLine hierarchy = new CommandLine(new Ozone())
+        .addSubcommand("admin", new OzoneAdmin().getCmd())
+        .addSubcommand("auditparser", new AuditParser().getCmd())
+        .addSubcommand("checknative", new CheckNative().getCmd())
+        .addSubcommand("csi", new CsiServer().getCmd())
+        .addSubcommand("datanode", new HddsDatanodeService().getCmd())
+        .addSubcommand("debug", new OzoneDebug().getCmd())
+        .addSubcommand("freon", new Freon().getCmd())
+        .addSubcommand("genconf", new 
GenerateOzoneRequiredConfigurations().getCmd())
+        .addSubcommand("getconf", new OzoneGetConf().getCmd())
+        .addSubcommand("httpfs", new HttpFSServerWebServer())
+        .addSubcommand("insight", new Insight().getCmd())
+        .addSubcommand("om", new OzoneManagerStarter(null).getCmd())
+        .addSubcommand("ratis", new OzoneRatis().getCmd())
+        .addSubcommand("recon", new ReconServer().getCmd())
+        .addSubcommand("repair", new OzoneRepair().getCmd())
+        .addSubcommand("s3", new S3Shell().getCmd())
+        .addSubcommand("s3g", new Gateway().getCmd())
+        .addSubcommand("scm", new 
StorageContainerManagerStarter(null).getCmd())
+        .addSubcommand("sh", new OzoneShell().getCmd(), "shell")
+        .addSubcommand("tenant", new TenantShell().getCmd())
+        .addSubcommand("version", new OzoneVersionInfo());
+
+    /*
+     * The following commands are marked as hidden,
+     * so they won't have auto complete.
+     *   - OzoneAdmin
+     *   - Insight
+     *   - CsiServer
+     *   - HddsDatanodeService
+     *   - OzoneManagerStarter
+     *   - Gateway
+     *   - StorageContainerManagerStarter
+     */
+
+    /*
+     * We don't have auto-complete support for the following commands
+     *   - dtutil    -- hadoop command
+     *   - classpath -- handled in shell script, we can introduce a dummy 
class here
+     *   - envvars   -- handled in shell script, we can introduce a dummy 
class here
+     *   - fs        -- hadoop command
+     *   - daemonlog -- hadoop command
+     */
+
+    System.out.println(AutoComplete.bash("ozone", hierarchy));
+  }
+
+  /**
+   * Ozone top level command, used only to generate auto-complete.
+   */
+  @CommandLine.Command(name = "ozone",
+          description = "Ozone top level command")
+  private static class Ozone {

Review Comment:
   Also in follow-up, I think we can convert this to a real command and reduce 
duplication in `ozone` shell script by delegating more tasks (like usage help 
generation) to this new command.



##########
hadoop-ozone/tools/src/main/java/org/apache/hadoop/ozone/utils/AutoCompletion.java:
##########
@@ -0,0 +1,164 @@
+/*
+ * 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 org.apache.hadoop.hdds.scm.server.StorageContainerManagerStarter;
+import org.apache.hadoop.ozone.HddsDatanodeService;
+import org.apache.hadoop.ozone.admin.OzoneAdmin;
+import org.apache.hadoop.ozone.audit.parser.AuditParser;
+import org.apache.hadoop.ozone.conf.OzoneGetConf;
+import org.apache.hadoop.ozone.csi.CsiServer;
+import org.apache.hadoop.ozone.debug.OzoneDebug;
+import org.apache.hadoop.ozone.freon.Freon;
+import org.apache.hadoop.ozone.genconf.GenerateOzoneRequiredConfigurations;
+import org.apache.hadoop.ozone.insight.Insight;
+import org.apache.hadoop.ozone.om.OzoneManagerStarter;
+import org.apache.hadoop.ozone.recon.ReconServer;
+import org.apache.hadoop.ozone.repair.OzoneRepair;
+import org.apache.hadoop.ozone.s3.Gateway;
+import org.apache.hadoop.ozone.shell.OzoneRatis;
+import org.apache.hadoop.ozone.shell.OzoneShell;
+import org.apache.hadoop.ozone.shell.checknative.CheckNative;
+import org.apache.hadoop.ozone.shell.s3.S3Shell;
+import org.apache.hadoop.ozone.shell.tenant.TenantShell;
+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 AutoCompletion() { }
+
+  public static void main(String[] args) {
+
+    CommandLine hierarchy = new CommandLine(new Ozone())
+        .addSubcommand("admin", new OzoneAdmin().getCmd())
+        .addSubcommand("auditparser", new AuditParser().getCmd())
+        .addSubcommand("checknative", new CheckNative().getCmd())
+        .addSubcommand("csi", new CsiServer().getCmd())
+        .addSubcommand("datanode", new HddsDatanodeService().getCmd())
+        .addSubcommand("debug", new OzoneDebug().getCmd())
+        .addSubcommand("freon", new Freon().getCmd())
+        .addSubcommand("genconf", new 
GenerateOzoneRequiredConfigurations().getCmd())
+        .addSubcommand("getconf", new OzoneGetConf().getCmd())
+        .addSubcommand("httpfs", new HttpFSServerWebServer())
+        .addSubcommand("insight", new Insight().getCmd())
+        .addSubcommand("om", new OzoneManagerStarter(null).getCmd())
+        .addSubcommand("ratis", new OzoneRatis().getCmd())
+        .addSubcommand("recon", new ReconServer().getCmd())
+        .addSubcommand("repair", new OzoneRepair().getCmd())
+        .addSubcommand("s3", new S3Shell().getCmd())
+        .addSubcommand("s3g", new Gateway().getCmd())
+        .addSubcommand("scm", new 
StorageContainerManagerStarter(null).getCmd())
+        .addSubcommand("sh", new OzoneShell().getCmd(), "shell")
+        .addSubcommand("tenant", new TenantShell().getCmd())
+        .addSubcommand("version", new OzoneVersionInfo());
+
+    /*
+     * The following commands are marked as hidden,
+     * so they won't have auto complete.
+     *   - OzoneAdmin
+     *   - Insight
+     *   - CsiServer
+     *   - HddsDatanodeService
+     *   - OzoneManagerStarter
+     *   - Gateway
+     *   - StorageContainerManagerStarter
+     */
+
+    /*
+     * We don't have auto-complete support for the following commands
+     *   - dtutil    -- hadoop command
+     *   - classpath -- handled in shell script, we can introduce a dummy 
class here
+     *   - envvars   -- handled in shell script, we can introduce a dummy 
class here
+     *   - fs        -- hadoop command
+     *   - daemonlog -- hadoop command
+     */
+
+    System.out.println(AutoComplete.bash("ozone", hierarchy));
+  }
+
+  /**
+   * Ozone top level command, used only to generate auto-complete.
+   */
+  @CommandLine.Command(name = "ozone",
+          description = "Ozone top level command")
+  private static class Ozone {
+    @Option(names = {"--buildpaths"},
+        description = "attempt to add class files from build tree")
+    private String buildpaths;
+
+    @Option(names = {"--config"},
+        description = "Ozone config directory")
+    private String config;
+
+    @Option(names = {"--debug"},
+        description = "turn on shell script debug mode")
+    private String debug;
+
+    @Option(names = {"--daemon"},
+        description = "attempt to add class files from build tree")
+    private String daemon;
+
+    @Option(names = {"--help"},
+        description = "usage information")
+    private String help;
+
+    @Option(names = {"--hostnames"},
+        description = "hosts to use in worker mode")
+    private String hostnames;
+
+    @Option(names = {"--hosts"},
+        description = "list of hosts to use in worker mode")
+    private String hosts;
+
+    @Option(names = {"--loglevel"},
+        description = "set the log4j level for this command")
+    private String loglevel;
+
+    @Option(names = {"--workers"},
+        description = "turn on worker mode")
+    private String workers;
+
+    @Option(names = {"--jvmargs"},
+        description = "append JVM options to any existing options defined in 
the OZONE_OPTS environment variable. " +
+            "Any defined in OZONE_CLIENT_OPTS will be appended after these 
jvmargs")
+    private String jvmargs;
+
+    @Option(names = {"--validate"},
+        description = "validates if all jars as indicated in the corresponding 
OZONE_RUN_ARTIFACT_NAME classpath " +
+            "file are present, command execution shall continue post 
validation failure if 'continue' is passed")
+    private String validate;
+
+  }
+
+  // OzoneVersionInfo class doesn't extend GenericCli, so this dummy class is 
required here.
+  @CommandLine.Command(name = "version",
+          description = "Ozone Version Information")
+  private static class OzoneVersionInfo {
+  }
+
+  // HttpFSServerWebServer class doesn't extend GenericCli, so this dummy 
class is required here.
+  @CommandLine.Command(name = "httpfs",
+          description = "HttpFSServerWebServer")
+  private static class HttpFSServerWebServer {
+  }

Review Comment:
   Can be converted in follow-up.



##########
hadoop-ozone/tools/src/main/java/org/apache/hadoop/ozone/utils/AutoCompletion.java:
##########
@@ -0,0 +1,164 @@
+/*
+ * 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 org.apache.hadoop.hdds.scm.server.StorageContainerManagerStarter;
+import org.apache.hadoop.ozone.HddsDatanodeService;
+import org.apache.hadoop.ozone.admin.OzoneAdmin;
+import org.apache.hadoop.ozone.audit.parser.AuditParser;
+import org.apache.hadoop.ozone.conf.OzoneGetConf;
+import org.apache.hadoop.ozone.csi.CsiServer;
+import org.apache.hadoop.ozone.debug.OzoneDebug;
+import org.apache.hadoop.ozone.freon.Freon;
+import org.apache.hadoop.ozone.genconf.GenerateOzoneRequiredConfigurations;
+import org.apache.hadoop.ozone.insight.Insight;
+import org.apache.hadoop.ozone.om.OzoneManagerStarter;
+import org.apache.hadoop.ozone.recon.ReconServer;
+import org.apache.hadoop.ozone.repair.OzoneRepair;
+import org.apache.hadoop.ozone.s3.Gateway;
+import org.apache.hadoop.ozone.shell.OzoneRatis;
+import org.apache.hadoop.ozone.shell.OzoneShell;
+import org.apache.hadoop.ozone.shell.checknative.CheckNative;
+import org.apache.hadoop.ozone.shell.s3.S3Shell;
+import org.apache.hadoop.ozone.shell.tenant.TenantShell;
+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 AutoCompletion() { }
+
+  public static void main(String[] args) {
+
+    CommandLine hierarchy = new CommandLine(new Ozone())
+        .addSubcommand("admin", new OzoneAdmin().getCmd())
+        .addSubcommand("auditparser", new AuditParser().getCmd())
+        .addSubcommand("checknative", new CheckNative().getCmd())
+        .addSubcommand("csi", new CsiServer().getCmd())
+        .addSubcommand("datanode", new HddsDatanodeService().getCmd())
+        .addSubcommand("debug", new OzoneDebug().getCmd())
+        .addSubcommand("freon", new Freon().getCmd())
+        .addSubcommand("genconf", new 
GenerateOzoneRequiredConfigurations().getCmd())
+        .addSubcommand("getconf", new OzoneGetConf().getCmd())
+        .addSubcommand("httpfs", new HttpFSServerWebServer())
+        .addSubcommand("insight", new Insight().getCmd())
+        .addSubcommand("om", new OzoneManagerStarter(null).getCmd())
+        .addSubcommand("ratis", new OzoneRatis().getCmd())
+        .addSubcommand("recon", new ReconServer().getCmd())
+        .addSubcommand("repair", new OzoneRepair().getCmd())
+        .addSubcommand("s3", new S3Shell().getCmd())
+        .addSubcommand("s3g", new Gateway().getCmd())
+        .addSubcommand("scm", new 
StorageContainerManagerStarter(null).getCmd())
+        .addSubcommand("sh", new OzoneShell().getCmd(), "shell")
+        .addSubcommand("tenant", new TenantShell().getCmd())
+        .addSubcommand("version", new OzoneVersionInfo());
+
+    /*
+     * The following commands are marked as hidden,
+     * so they won't have auto complete.
+     *   - OzoneAdmin
+     *   - Insight
+     *   - CsiServer
+     *   - HddsDatanodeService
+     *   - OzoneManagerStarter
+     *   - Gateway
+     *   - StorageContainerManagerStarter

Review Comment:
   Since these are hidden, I think we can skip adding new dependencies for now.



##########
hadoop-ozone/tools/src/main/java/org/apache/hadoop/ozone/utils/AutoCompletion.java:
##########
@@ -0,0 +1,164 @@
+/*
+ * 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 org.apache.hadoop.hdds.scm.server.StorageContainerManagerStarter;
+import org.apache.hadoop.ozone.HddsDatanodeService;
+import org.apache.hadoop.ozone.admin.OzoneAdmin;
+import org.apache.hadoop.ozone.audit.parser.AuditParser;
+import org.apache.hadoop.ozone.conf.OzoneGetConf;
+import org.apache.hadoop.ozone.csi.CsiServer;
+import org.apache.hadoop.ozone.debug.OzoneDebug;
+import org.apache.hadoop.ozone.freon.Freon;
+import org.apache.hadoop.ozone.genconf.GenerateOzoneRequiredConfigurations;
+import org.apache.hadoop.ozone.insight.Insight;
+import org.apache.hadoop.ozone.om.OzoneManagerStarter;
+import org.apache.hadoop.ozone.recon.ReconServer;
+import org.apache.hadoop.ozone.repair.OzoneRepair;
+import org.apache.hadoop.ozone.s3.Gateway;
+import org.apache.hadoop.ozone.shell.OzoneRatis;
+import org.apache.hadoop.ozone.shell.OzoneShell;
+import org.apache.hadoop.ozone.shell.checknative.CheckNative;
+import org.apache.hadoop.ozone.shell.s3.S3Shell;
+import org.apache.hadoop.ozone.shell.tenant.TenantShell;
+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 AutoCompletion() { }
+
+  public static void main(String[] args) {
+
+    CommandLine hierarchy = new CommandLine(new Ozone())
+        .addSubcommand("admin", new OzoneAdmin().getCmd())
+        .addSubcommand("auditparser", new AuditParser().getCmd())
+        .addSubcommand("checknative", new CheckNative().getCmd())
+        .addSubcommand("csi", new CsiServer().getCmd())
+        .addSubcommand("datanode", new HddsDatanodeService().getCmd())
+        .addSubcommand("debug", new OzoneDebug().getCmd())
+        .addSubcommand("freon", new Freon().getCmd())
+        .addSubcommand("genconf", new 
GenerateOzoneRequiredConfigurations().getCmd())
+        .addSubcommand("getconf", new OzoneGetConf().getCmd())
+        .addSubcommand("httpfs", new HttpFSServerWebServer())
+        .addSubcommand("insight", new Insight().getCmd())
+        .addSubcommand("om", new OzoneManagerStarter(null).getCmd())
+        .addSubcommand("ratis", new OzoneRatis().getCmd())
+        .addSubcommand("recon", new ReconServer().getCmd())
+        .addSubcommand("repair", new OzoneRepair().getCmd())
+        .addSubcommand("s3", new S3Shell().getCmd())
+        .addSubcommand("s3g", new Gateway().getCmd())
+        .addSubcommand("scm", new 
StorageContainerManagerStarter(null).getCmd())
+        .addSubcommand("sh", new OzoneShell().getCmd(), "shell")
+        .addSubcommand("tenant", new TenantShell().getCmd())
+        .addSubcommand("version", new OzoneVersionInfo());

Review Comment:
   Instead of hard-coding the hierarchy, we can generate it dynamically, 
looking for `GenericCli` implementations:
   
   ```java
       final String prefix = "ozone ";
       final int prefixLen = prefix.length();
       final String[] packages = {
           "org.apache.hadoop.hdds",
           "org.apache.hadoop.ozone",
           "org.apache.ozone",
       };
       CommandLine ozone = new CommandLine(new Ozone());
       for (String pkg : packages) {
         for (Class<? extends GenericCli> cls : new 
Reflections(pkg).getSubTypesOf(GenericCli.class)) {
           GenericCli cli;
           try {
             cli = ReflectionUtils.newInstance(cls);
           } catch (UnsupportedOperationException e) {
             continue;
           }
           CommandLine cmd = cli.getCmd();
           CommandLine.Model.CommandSpec spec = cmd.getCommandSpec();
           final String qualifiedName = spec.qualifiedName();
           if (spec.usageMessage().hidden() || 
CommandLine.Model.CommandSpec.DEFAULT_COMMAND_NAME.equals(spec.name())) {
             continue;
           }
           final String name = qualifiedName.startsWith(prefix) ? 
qualifiedName.substring(prefixLen) : qualifiedName;
           System.out.println(qualifiedName);
           ozone.addSubcommand(name, cmd);
         }
       }
   ```
   
   It skips `GenericCli` subclasses that do not have no-args constructor.  
We'll need to check if those should be added.



##########
hadoop-ozone/tools/src/main/java/org/apache/hadoop/ozone/utils/AutoCompletion.java:
##########
@@ -0,0 +1,164 @@
+/*
+ * 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 org.apache.hadoop.hdds.scm.server.StorageContainerManagerStarter;
+import org.apache.hadoop.ozone.HddsDatanodeService;
+import org.apache.hadoop.ozone.admin.OzoneAdmin;
+import org.apache.hadoop.ozone.audit.parser.AuditParser;
+import org.apache.hadoop.ozone.conf.OzoneGetConf;
+import org.apache.hadoop.ozone.csi.CsiServer;
+import org.apache.hadoop.ozone.debug.OzoneDebug;
+import org.apache.hadoop.ozone.freon.Freon;
+import org.apache.hadoop.ozone.genconf.GenerateOzoneRequiredConfigurations;
+import org.apache.hadoop.ozone.insight.Insight;
+import org.apache.hadoop.ozone.om.OzoneManagerStarter;
+import org.apache.hadoop.ozone.recon.ReconServer;
+import org.apache.hadoop.ozone.repair.OzoneRepair;
+import org.apache.hadoop.ozone.s3.Gateway;
+import org.apache.hadoop.ozone.shell.OzoneRatis;
+import org.apache.hadoop.ozone.shell.OzoneShell;
+import org.apache.hadoop.ozone.shell.checknative.CheckNative;
+import org.apache.hadoop.ozone.shell.s3.S3Shell;
+import org.apache.hadoop.ozone.shell.tenant.TenantShell;
+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 AutoCompletion() { }
+
+  public static void main(String[] args) {
+
+    CommandLine hierarchy = new CommandLine(new Ozone())
+        .addSubcommand("admin", new OzoneAdmin().getCmd())
+        .addSubcommand("auditparser", new AuditParser().getCmd())
+        .addSubcommand("checknative", new CheckNative().getCmd())
+        .addSubcommand("csi", new CsiServer().getCmd())
+        .addSubcommand("datanode", new HddsDatanodeService().getCmd())
+        .addSubcommand("debug", new OzoneDebug().getCmd())
+        .addSubcommand("freon", new Freon().getCmd())
+        .addSubcommand("genconf", new 
GenerateOzoneRequiredConfigurations().getCmd())
+        .addSubcommand("getconf", new OzoneGetConf().getCmd())
+        .addSubcommand("httpfs", new HttpFSServerWebServer())
+        .addSubcommand("insight", new Insight().getCmd())
+        .addSubcommand("om", new OzoneManagerStarter(null).getCmd())
+        .addSubcommand("ratis", new OzoneRatis().getCmd())
+        .addSubcommand("recon", new ReconServer().getCmd())
+        .addSubcommand("repair", new OzoneRepair().getCmd())
+        .addSubcommand("s3", new S3Shell().getCmd())
+        .addSubcommand("s3g", new Gateway().getCmd())
+        .addSubcommand("scm", new 
StorageContainerManagerStarter(null).getCmd())
+        .addSubcommand("sh", new OzoneShell().getCmd(), "shell")
+        .addSubcommand("tenant", new TenantShell().getCmd())
+        .addSubcommand("version", new OzoneVersionInfo());
+
+    /*
+     * The following commands are marked as hidden,
+     * so they won't have auto complete.
+     *   - OzoneAdmin
+     *   - Insight
+     *   - CsiServer
+     *   - HddsDatanodeService
+     *   - OzoneManagerStarter
+     *   - Gateway
+     *   - StorageContainerManagerStarter
+     */
+
+    /*
+     * We don't have auto-complete support for the following commands
+     *   - dtutil    -- hadoop command
+     *   - classpath -- handled in shell script, we can introduce a dummy 
class here
+     *   - envvars   -- handled in shell script, we can introduce a dummy 
class here

Review Comment:
   We can file follow-up tasks for converting these.



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