Skip to content

Conversation

tuteng
Copy link
Member

@tuteng tuteng commented Nov 25, 2019

Motivation

Currently, the commands on the page http://pulsar.apache.org/docs/en/pulsar-admin/ are all manually added. when the document changes, there are often wrong contents. in order to solve this problem, we expect the commands on this page to be automatically generated. this pr is the first step. If it passes, we will add a new page on the website to show the automatically generated commands later.

Modifications

  • Add a hidden command --generate-doc to automatically generate command line documents
  • Add integration tests

Usage

./bin/pulsar-admin --generate-doc tenants
./bin/pulsar-admin --generate-doc namespaces
.....

The following is what we expect:
image

Verifying this change

Integration test pass

@tuteng tuteng added doc Your PR contains doc changes, no matter whether the changes are in markdown or code files. area/admin labels Nov 25, 2019
@tuteng tuteng added this to the 2.5.0 milestone Nov 25, 2019
@tuteng tuteng self-assigned this Nov 25, 2019
@tuteng tuteng changed the title Support auto generate pulsar admin cli [Pulsar Client Tools]Support auto generate pulsar admin cli Nov 25, 2019
@sijie sijie changed the title [Pulsar Client Tools]Support auto generate pulsar admin cli [Pulsar Client Tools]Support generate documentation of pulsar admin cli automatically Nov 25, 2019
Copy link
Member

@sijie sijie left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@tuteng

Great contribution to automate the documentation generation for admin CLI!

I have one suggestion to current change.

I don't think it is a good idea to add another flag --generate-doc in existing commands. Ideally the doc generator should be done in a separate tool. because you anyway create a PulsarAdminTool in the generateDocument method.

A better approach would be:

  1. create a separate tool for generating documentation.
  2. move generateDocument to the new tool.
  3. in generateDocument, you can get all the commands from commandMap.
  4. looping through the commands in commandMap and generate documentation for each command.

In this way, you don't change any existing commands and you are able to capture all the commands in the command map.

sb.append("`$" + module + "`\n\n");
sb.append("------------\n\n");
setupCommands(adminFactory);
JCommander obj = jcommander.getCommands().get(module);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can move the logic below into a method called generateDocument(JCommander command). Then you can iterate over the commands to generate the documentation for all the commands.

for (JCommander obj : jcommander.getCommands().values()) {
    generateDocument(obj);
}

sb.append("### Usage\n\n");
sb.append("`$" + module + "`\n\n");
sb.append("------------\n\n");
setupCommands(adminFactory);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

when a user is generating documentation, he/she should NOT be required to create a Pulsar admin. So we should provide a mock implementation of adminFactory to return a mock implementation of PulsarAdmin.

@sijie sijie modified the milestones: 2.5.0, 2.6.0 Nov 25, 2019
@sijie
Copy link
Member

sijie commented Nov 25, 2019

removed the milestone for now. If we can make it before releasing 2.5.0, we can mark it for 2.5.0.

@tuteng
Copy link
Member Author

tuteng commented Nov 29, 2019

Thank you for your suggestion. The situation you mentioned is my initial implementation plan. However, when I tested it, I found that different command objects jcommand was used in the PulsarAdminTool and CmdBase.

PulsarAdminTool:
https://github.com/apache/pulsar/blob/master/pulsar-client-tools/src/main/java/org/apache/pulsar/admin/cli/PulsarAdminTool.java#L87
CmdBase:
https://github.com/apache/pulsar/blob/master/pulsar-client-tools/src/main/java/org/apache/pulsar/admin/cli/CmdBase.java#L38

All the child commands were inherited from the class CmdBase. In subclasses such as CmdTopics, we cannot get the commandMap object. Therefore, it may be necessary to pass down the commandmap object and the jcommand object of PulsarAdminTool. therefore, it is necessary to add some logic to the PulsarAdmintool. I am not sure if my understanding is correct. I hope to get your reply, but I will try this implementation as much as possible.

@sijie

@sijie
Copy link
Member

sijie commented Nov 29, 2019

I found that different command objects jcommand was used in the PulsarAdminTool and CmdBase.

The jcommand in PulsarrAdminTool is the root command.The jcommand in CmdBase is for a command group.

All the child commands were inherited from the class CmdBase. In subclasses such as CmdTopics, we cannot get the commandMap object.

You can get the command groups from the commandMap of PulsarAdminTool. Then you can iterate the command group. For each command group, you can get its sub commandMap.

@tuteng
Copy link
Member Author

tuteng commented Dec 12, 2019

run java8 tests

@tuteng
Copy link
Member Author

tuteng commented Dec 13, 2019

run integration tests

@tuteng
Copy link
Member Author

tuteng commented Dec 13, 2019

run java8 tests

@sijie
Copy link
Member

sijie commented Dec 13, 2019

@sijie PTAL

@sijie sijie added this to the 2.6.0 milestone Dec 20, 2019
@sijie sijie merged commit 805a421 into apache:master Dec 20, 2019
@sijie sijie deleted the feature/support-auto-generate-pulsar-admin-cli branch December 20, 2019 05:35
@sijie sijie modified the milestones: 2.6.0, 2.5.1, 2.5.0 Jan 6, 2020
sijie pushed a commit that referenced this pull request Jan 7, 2020
### Motivation

After implementing this tool #5738, we need to use this tool to automatically generate the documentation of pulsar-admin.

### Modifications

* Add a script to automatically generate document pages of pulsar-admin
* Add em tag for markdown file of pulsar-admin

### Verifying this change

![image](https://user-images.githubusercontent.com/1907867/71462733-40707400-27ef-11ea-8dae-dce70783f22f.png)
tuteng added a commit that referenced this pull request Feb 4, 2020
### Motivation

After completing this pull request #5738, it seems that the document was not copied to the correct place to fix the problem.

### Modifications

* Copy the document to the correct place
huangdx0726 pushed a commit to huangdx0726/pulsar that referenced this pull request Aug 24, 2020
…li automatically (apache#5738)

### Motivation

Currently, the commands on the page http://pulsar.apache.org/docs/en/pulsar-admin/ are all manually added. when the document changes, there are often wrong contents. in order to solve this problem, we expect the commands on this page to be automatically generated. this pr is the first step. If it passes, we will add a new page on the website to show the automatically generated commands later.
huangdx0726 pushed a commit to huangdx0726/pulsar that referenced this pull request Aug 24, 2020
### Motivation

After implementing this tool apache#5738, we need to use this tool to automatically generate the documentation of pulsar-admin.

### Modifications

* Add a script to automatically generate document pages of pulsar-admin
* Add em tag for markdown file of pulsar-admin

### Verifying this change

![image](https://user-images.githubusercontent.com/1907867/71462733-40707400-27ef-11ea-8dae-dce70783f22f.png)
huangdx0726 pushed a commit to huangdx0726/pulsar that referenced this pull request Aug 24, 2020
### Motivation

After completing this pull request apache#5738, it seems that the document was not copied to the correct place to fix the problem.

### Modifications

* Copy the document to the correct place
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/admin doc Your PR contains doc changes, no matter whether the changes are in markdown or code files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants