You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@ozone.apache.org by "nandakumar131 (via GitHub)" <gi...@apache.org> on 2025/03/08 07:45:49 UTC

[PR] HDDS-12519. Generate auto-complete script for Ozone commands. [ozone]

nandakumar131 opened a new pull request, #8030:
URL: https://github.com/apache/ozone/pull/8030

   ## What changes were proposed in this pull request?
   Autocomplete for Ozone commands.
   
   This is not a very good implementation.
   - `GenericCli#getCmd` is used in `AutoCompletion`, which is only exposed for tests (`@VisibleForTesting`)
           - Since a new `Factory` class is used to load the `cmd` and `subCmds` the command object created in `AutoCompletion` doesn't get access to the sub commands unless `GenericCli#getCmd` is used.
   
   - If we add any new top level command, we should manually add the command to `AutoCompletion` class else generated auto-complete script will not work for the new commands.
   
   - Any change in top level options (the ones handled in ozone shell script) should also be done in `AutoCompletion` class else the the suggestion will be incorrect.
   
   - Commands which are handled in shell script needs dummy classes to generate auto-complete
   
   - Commands that are inherited from Hadoop doesn't have auto-complete
   
   
   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)
   
   
   We should be able to add an acceptance test where we compare the commands available in the ozone CLI and the generated  completion script. (I can't think of any other way to test this)
   
   As of now this is not exposed via Ozone CLI. If someone wants to test the auto-complete feature, use the below command to generate the completion script.
   
   ```
   java -classpath `bin/ozone classpath ozone-tools`:. org.apache.hadoop.ozone.utils.AutoCompletion 
   ```
   
   You can also use the completion script from [here](https://gist.github.com/nandakumar131/0f668a8fd580cde1f2cc7e5c9c949850).
   
   Any feedback to change the design are welcome.
   
   ## What is the link to the Apache JIRA
   HDDS-12519
   
   ## How was this patch tested?
   Manual testing.
   


-- 
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: issues-unsubscribe@ozone.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@ozone.apache.org
For additional commands, e-mail: issues-help@ozone.apache.org


Re: [PR] HDDS-12519. Generate auto-complete script for Ozone commands. [ozone]

Posted by "adoroszlai (via GitHub)" <gi...@apache.org>.
adoroszlai commented on code in PR #8030:
URL: https://github.com/apache/ozone/pull/8030#discussion_r1992791960


##########
hadoop-ozone/tools/src/main/java/org/apache/hadoop/ozone/utils/AutoCompletion.java:
##########
@@ -0,0 +1,131 @@
+/*
+ * 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 {

Review Comment:
   Please feel free to ignore the point about `--output-file`.



-- 
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: issues-unsubscribe@ozone.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@ozone.apache.org
For additional commands, e-mail: issues-help@ozone.apache.org


Re: [PR] HDDS-12519. Generate auto-complete script for Ozone commands. [ozone]

Posted by "nandakumar131 (via GitHub)" <gi...@apache.org>.
nandakumar131 commented on code in PR #8030:
URL: https://github.com/apache/ozone/pull/8030#discussion_r1987570973


##########
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:
   +1, will do.



-- 
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: issues-unsubscribe@ozone.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@ozone.apache.org
For additional commands, e-mail: issues-help@ozone.apache.org


Re: [PR] HDDS-12519. Generate auto-complete script for Ozone commands. [ozone]

Posted by "adoroszlai (via GitHub)" <gi...@apache.org>.
adoroszlai commented on code in PR #8030:
URL: https://github.com/apache/ozone/pull/8030#discussion_r1986119000


##########
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:
   It could also be used to generate manpages or manpage-like HTML doc.
   
   https://issues.apache.org/jira/browse/HDDS-12522



-- 
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: issues-unsubscribe@ozone.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@ozone.apache.org
For additional commands, e-mail: issues-help@ozone.apache.org


Re: [PR] HDDS-12519. Generate auto-complete script for Ozone commands. [ozone]

Posted by "adoroszlai (via GitHub)" <gi...@apache.org>.
adoroszlai commented on code in PR #8030:
URL: https://github.com/apache/ozone/pull/8030#discussion_r1992242770


##########
hadoop-ozone/tools/src/main/java/org/apache/hadoop/ozone/utils/AutoCompletion.java:
##########
@@ -0,0 +1,131 @@
+/*
+ * 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 {

Review Comment:
   I think we should make this a `@Command` with the usual options and extend `GenericCli`.
   
   Benefits:
   
   - `ozone completion --help` would work as expected, now it just ignores the option and generates the completion script to the console
   - `ozone completion` itself would have auto-completion
   - we could add an option for writing output to a file (`--output-file <filename>`)



##########
hadoop-ozone/tools/src/main/java/org/apache/hadoop/ozone/utils/AutoCompletion.java:
##########
@@ -0,0 +1,131 @@
+/*
+ * 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(AutoCompletion::isPublicCommand)
+          .forEach(command -> ozone.addSubcommand(getCommandName(command), command));
+    }
+    System.out.println(AutoComplete.bash("ozone", ozone));

Review Comment:
   Would it be better to write to a file directly?  Running `ozone completion` outputs 364KB of content to the console.
   
   ```java
       File file = new File("ozone-completion.sh");
       AutoComplete.bash("ozone", file, null, ozone);
   ```



-- 
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: issues-unsubscribe@ozone.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@ozone.apache.org
For additional commands, e-mail: issues-help@ozone.apache.org


Re: [PR] HDDS-12519. Generate auto-complete script for Ozone commands. [ozone]

Posted by "errose28 (via GitHub)" <gi...@apache.org>.
errose28 commented on PR #8030:
URL: https://github.com/apache/ozone/pull/8030#issuecomment-2719312780

   Looks like the "standard" for this kind of thing would be having the command be `ozone completion <some shell specifier>` and having it print to stdout. Here's a list of existing programs that do this according to a few LLMs. I was able to verify the first 5 in the list are accurate since I have them installed.
   ```
   kubectl completion bash
   docker completion bash
   npm completion
   pip completion --bash
   gh completion -s bash
   cargo completion bash
   rustup completions bash
   helm completion bash
   terraform -install-autocomplete
   podman completion bash
   gcloud completion bash
   op completion bash # 1password
   ```


-- 
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: issues-unsubscribe@ozone.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@ozone.apache.org
For additional commands, e-mail: issues-help@ozone.apache.org


Re: [PR] HDDS-12519. Generate auto-complete script for Ozone commands. [ozone]

Posted by "nandakumar131 (via GitHub)" <gi...@apache.org>.
nandakumar131 commented on PR #8030:
URL: https://github.com/apache/ozone/pull/8030#issuecomment-2717881529

   @adoroszlai, updated the PR based on the suggestions.
   Please take a look at the changes.


-- 
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: issues-unsubscribe@ozone.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@ozone.apache.org
For additional commands, e-mail: issues-help@ozone.apache.org


Re: [PR] HDDS-12519. Generate auto-complete script for Ozone commands. [ozone]

Posted by "nandakumar131 (via GitHub)" <gi...@apache.org>.
nandakumar131 commented on code in PR #8030:
URL: https://github.com/apache/ozone/pull/8030#discussion_r1991661994


##########
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:
   Thanks for the suggestion.
   Will wait for more input from others on this.
   
   cc. @errose28 @dombizita @Tejaskriya @sarvekshayr 



-- 
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: issues-unsubscribe@ozone.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@ozone.apache.org
For additional commands, e-mail: issues-help@ozone.apache.org


Re: [PR] HDDS-12519. Generate auto-complete script for Ozone commands. [ozone]

Posted by "nandakumar131 (via GitHub)" <gi...@apache.org>.
nandakumar131 commented on PR #8030:
URL: https://github.com/apache/ozone/pull/8030#issuecomment-2787090294

   @adoroszlai @errose28 
   Updated the PR based on the review comments, please take a look.


-- 
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: issues-unsubscribe@ozone.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@ozone.apache.org
For additional commands, e-mail: issues-help@ozone.apache.org


Re: [PR] HDDS-12519. Generate auto-complete script for Ozone commands. [ozone]

Posted by "nandakumar131 (via GitHub)" <gi...@apache.org>.
nandakumar131 commented on code in PR #8030:
URL: https://github.com/apache/ozone/pull/8030#discussion_r1992786864


##########
hadoop-ozone/tools/src/main/java/org/apache/hadoop/ozone/utils/AutoCompletion.java:
##########
@@ -0,0 +1,131 @@
+/*
+ * 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 {

Review Comment:
   Thanks for the suggestion, will update the PR.



-- 
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: issues-unsubscribe@ozone.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@ozone.apache.org
For additional commands, e-mail: issues-help@ozone.apache.org


Re: [PR] HDDS-12519. Generate auto-complete script for Ozone commands. [ozone]

Posted by "nandakumar131 (via GitHub)" <gi...@apache.org>.
nandakumar131 commented on PR #8030:
URL: https://github.com/apache/ozone/pull/8030#issuecomment-2788793309

   @kerneltime there is a plan to add robot test for validating the autocomplete script.
   > it should be possible to use the type command in bash to check if the generated autocomplete functions were correctly loaded in a robot test.
   
   Thanks for the pointers.


-- 
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: issues-unsubscribe@ozone.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@ozone.apache.org
For additional commands, e-mail: issues-help@ozone.apache.org


Re: [PR] HDDS-12519. Generate auto-complete script for Ozone commands. [ozone]

Posted by "nandakumar131 (via GitHub)" <gi...@apache.org>.
nandakumar131 commented on PR #8030:
URL: https://github.com/apache/ozone/pull/8030#issuecomment-2791405501

   @adoroszlai Planning on doing as part of follow up jira, that will come after we add support for all the available commands.
   We still have to add support for `daemonlog`, `dtutil` and the commands that are implemented in shell script.
   Let me create the Jiras and refer it here.


-- 
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: issues-unsubscribe@ozone.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@ozone.apache.org
For additional commands, e-mail: issues-help@ozone.apache.org


Re: [PR] HDDS-12519. Generate auto-complete script for Ozone commands. [ozone]

Posted by "adoroszlai (via GitHub)" <gi...@apache.org>.
adoroszlai merged PR #8030:
URL: https://github.com/apache/ozone/pull/8030


-- 
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: issues-unsubscribe@ozone.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@ozone.apache.org
For additional commands, e-mail: issues-help@ozone.apache.org


Re: [PR] HDDS-12519. Generate auto-complete script for Ozone commands. [ozone]

Posted by "nandakumar131 (via GitHub)" <gi...@apache.org>.
nandakumar131 commented on PR #8030:
URL: https://github.com/apache/ozone/pull/8030#issuecomment-2708105086

   Planning on adding auto-complete for `classpath` and `envvars` commands. Will either do it in this PR or in a follow-up.


-- 
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: issues-unsubscribe@ozone.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@ozone.apache.org
For additional commands, e-mail: issues-help@ozone.apache.org


Re: [PR] HDDS-12519. Generate auto-complete script for Ozone commands. [ozone]

Posted by "nandakumar131 (via GitHub)" <gi...@apache.org>.
nandakumar131 commented on code in PR #8030:
URL: https://github.com/apache/ozone/pull/8030#discussion_r1991487737


##########
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:
   Created [HDDS-12570](https://issues.apache.org/jira/browse/HDDS-12570).



-- 
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: issues-unsubscribe@ozone.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@ozone.apache.org
For additional commands, e-mail: issues-help@ozone.apache.org


Re: [PR] HDDS-12519. Generate auto-complete script for Ozone commands. [ozone]

Posted by "errose28 (via GitHub)" <gi...@apache.org>.
errose28 commented on code in PR #8030:
URL: https://github.com/apache/ozone/pull/8030#discussion_r1991799247


##########
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:
   `daemonlog` looks like a wrapper to set the log level on a service over HTTP, similar to doing this through the web UI, which looks useful. I can't figure out the use case for `dtutil` though.
   
   What would the distinction be between `util` and `debug`? I think `checknative`, `classpath`, and `envvars` make sense under `debug`, but I'm ok with `ozone completion` being a top level command since its result applies to the whole CLI.



-- 
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: issues-unsubscribe@ozone.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@ozone.apache.org
For additional commands, e-mail: issues-help@ozone.apache.org


Re: [PR] HDDS-12519. Generate auto-complete script for Ozone commands. [ozone]

Posted by "nandakumar131 (via GitHub)" <gi...@apache.org>.
nandakumar131 commented on code in PR #8030:
URL: https://github.com/apache/ozone/pull/8030#discussion_r1991701279


##########
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:
   Created [HDDS-12571](https://issues.apache.org/jira/browse/HDDS-12571).



-- 
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: issues-unsubscribe@ozone.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@ozone.apache.org
For additional commands, e-mail: issues-help@ozone.apache.org


Re: [PR] HDDS-12519. Generate auto-complete script for Ozone commands. [ozone]

Posted by "adoroszlai (via GitHub)" <gi...@apache.org>.
adoroszlai commented on PR #8030:
URL: https://github.com/apache/ozone/pull/8030#issuecomment-2790592290

   > there is a plan to add robot test for validating the autocomplete script
   
   @nandakumar131 as part of this PR or follow-up?


-- 
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: issues-unsubscribe@ozone.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@ozone.apache.org
For additional commands, e-mail: issues-help@ozone.apache.org


Re: [PR] HDDS-12519. Generate auto-complete script for Ozone commands. [ozone]

Posted by "adoroszlai (via GitHub)" <gi...@apache.org>.
adoroszlai commented on PR #8030:
URL: https://github.com/apache/ozone/pull/8030#issuecomment-2791733649

   Thanks @nandakumar131 for the patch, @errose28, @kerneltime for the review.


-- 
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: issues-unsubscribe@ozone.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@ozone.apache.org
For additional commands, e-mail: issues-help@ozone.apache.org


Re: [PR] HDDS-12519. Generate auto-complete script for Ozone commands. [ozone]

Posted by "nandakumar131 (via GitHub)" <gi...@apache.org>.
nandakumar131 commented on PR #8030:
URL: https://github.com/apache/ozone/pull/8030#issuecomment-2792028799

   Thanks @adoroszlai for the review & merge, @errose28 and @kerneltime for the review.


-- 
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: issues-unsubscribe@ozone.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@ozone.apache.org
For additional commands, e-mail: issues-help@ozone.apache.org


Re: [PR] HDDS-12519. Generate auto-complete script for Ozone commands. [ozone]

Posted by "kerneltime (via GitHub)" <gi...@apache.org>.
kerneltime commented on PR #8030:
URL: https://github.com/apache/ozone/pull/8030#issuecomment-2787168122

   I have not run this locally but I believe it should be possible to use the `type` command in bash to check if the generated autocomplete functions were correctly loaded in a robot test.


-- 
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: issues-unsubscribe@ozone.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@ozone.apache.org
For additional commands, e-mail: issues-help@ozone.apache.org


Re: [PR] HDDS-12519. Generate auto-complete script for Ozone commands. [ozone]

Posted by "nandakumar131 (via GitHub)" <gi...@apache.org>.
nandakumar131 commented on code in PR #8030:
URL: https://github.com/apache/ozone/pull/8030#discussion_r1987570337


##########
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:
   Thanks for the suggestion @adoroszlai. I was planning on doing this. 😄  Just wanted to make sure that everything is working in first place.
   
   As of now, we don't have any command without no-args constructor that needs auto-complete. I will add dynamic loading of `GenericCli` implementation.
   
   `OzoneVersionInfo` is an exception. We should either make `OzoneVersionInfo` extend `GenericCli` or add it in a hard-coded way.
   
   For now I will add it directly and have a follow-up jira to make `OzoneVersionInfo` extend `GenericCli`.



-- 
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: issues-unsubscribe@ozone.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@ozone.apache.org
For additional commands, e-mail: issues-help@ozone.apache.org


Re: [PR] HDDS-12519. Generate auto-complete script for Ozone commands. [ozone]

Posted by "nandakumar131 (via GitHub)" <gi...@apache.org>.
nandakumar131 commented on code in PR #8030:
URL: https://github.com/apache/ozone/pull/8030#discussion_r1987571980


##########
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:
   Makes sense.



-- 
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: issues-unsubscribe@ozone.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@ozone.apache.org
For additional commands, e-mail: issues-help@ozone.apache.org


Re: [PR] HDDS-12519. Generate auto-complete script for Ozone commands. [ozone]

Posted by "adoroszlai (via GitHub)" <gi...@apache.org>.
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: issues-unsubscribe@ozone.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@ozone.apache.org
For additional commands, e-mail: issues-help@ozone.apache.org


Re: [PR] HDDS-12519. Generate auto-complete script for Ozone commands. [ozone]

Posted by "nandakumar131 (via GitHub)" <gi...@apache.org>.
nandakumar131 commented on code in PR #8030:
URL: https://github.com/apache/ozone/pull/8030#discussion_r1991497863


##########
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:
   Created [HDDS-12571](https://issues.apache.org/jira/browse/HDDS-12571).



-- 
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: issues-unsubscribe@ozone.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@ozone.apache.org
For additional commands, e-mail: issues-help@ozone.apache.org


Re: [PR] HDDS-12519. Generate auto-complete script for Ozone commands. [ozone]

Posted by "adoroszlai (via GitHub)" <gi...@apache.org>.
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: issues-unsubscribe@ozone.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@ozone.apache.org
For additional commands, e-mail: issues-help@ozone.apache.org


Re: [PR] HDDS-12519. Generate auto-complete script for Ozone commands. [ozone]

Posted by "nandakumar131 (via GitHub)" <gi...@apache.org>.
nandakumar131 commented on code in PR #8030:
URL: https://github.com/apache/ozone/pull/8030#discussion_r1992786032


##########
hadoop-ozone/tools/src/main/java/org/apache/hadoop/ozone/utils/AutoCompletion.java:
##########
@@ -0,0 +1,131 @@
+/*
+ * 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(AutoCompletion::isPublicCommand)
+          .forEach(command -> ozone.addSubcommand(getCommandName(command), command));
+    }
+    System.out.println(AutoComplete.bash("ozone", ozone));

Review Comment:
   The reason for writing the script to stdout is to allows users to install Ozone completion with a single command. The same command can also be added to the `.bashrc`/`.zshrc` file.
   ```
   source <(ozone completion)
   ```



-- 
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: issues-unsubscribe@ozone.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@ozone.apache.org
For additional commands, e-mail: issues-help@ozone.apache.org


Re: [PR] HDDS-12519. Generate auto-complete script for Ozone commands. [ozone]

Posted by "nandakumar131 (via GitHub)" <gi...@apache.org>.
nandakumar131 commented on PR #8030:
URL: https://github.com/apache/ozone/pull/8030#issuecomment-2719932263

   Thanks @errose28 for taking a look at it.
   Before I started working on this, I analyzed few existing scripts/programs that generated auto completion script. As you have pointed out, almost all of them have option to specify the shell type for which the completion should be generated. 
   
   But we don't have that facility in [picocli](https://picocli.info/). Picocli doesn't provide option to generate different completion script for different shells.
   
   It only has support to generate bash-completion which is also compatible with zsh. 
   [picocli.info/autocomplete](https://picocli.info/autocomplete.html)
   > Starting from version 1.0.0, picocli-based applications can have command line completion in Bash or ZSH Unix shells.
   
   We can add an argument to our code which can accept either `bash` or `zsh` as value, but in both the cases the same completion script will be generated. Having option to specify the shell type doesn't add any value to the completion script generation.


-- 
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: issues-unsubscribe@ozone.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@ozone.apache.org
For additional commands, e-mail: issues-help@ozone.apache.org


Re: [PR] HDDS-12519. Generate auto-complete script for Ozone commands. [ozone]

Posted by "adoroszlai (via GitHub)" <gi...@apache.org>.
adoroszlai commented on PR #8030:
URL: https://github.com/apache/ozone/pull/8030#issuecomment-2719937466

   > I analyzed few existing scripts/programs that generated auto completion script.
   
   Thanks to both of you for that.
   
   > Having option to specify the shell type doesn't add any value to the completion script generation
   
   I think it does:
   
   - allows future new shell types that picocli may support 
   - prints usage help on `ozone completion`


-- 
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: issues-unsubscribe@ozone.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@ozone.apache.org
For additional commands, e-mail: issues-help@ozone.apache.org