Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add experimental manual page generation #332

Merged
merged 3 commits into from Jun 6, 2022
Merged

Add experimental manual page generation #332

merged 3 commits into from Jun 6, 2022

Conversation

rauhul
Copy link
Contributor

@rauhul rauhul commented Jun 22, 2021

  • Adds a swift package manager command plugin called
    GenerateManualPlugin. The plugin can be invoked from the command line
    using swift package experimental-generate-manual. The plugin is
    prefixed for now with "experimental-" to indicate it is not mature and
    may see breaking changes to its CLI and output in the future. The
    plugin can be can be used to generate a manual in MDoc syntax for any
    swift-argument-parser tool that can be executed via
    tool --experimental-dump-info.
  • The plugin works by converting the ToolInfoV0 structure from the
    ArgumentParserToolInfo library into MDoc AST nodes using a custom
    (SwiftUI-esk) result builder DSL. The MDoc AST is then lowered to a
    string and written to disk.
  • The MDoc AST included is not general purpose and doesn't represent the
    true language exactly, so it is private to the underlying
    generate-manual tool. In the future it would be interesting to
    finish fleshing out this MDoc library and spin it out, however this is
    not a priority.
  • Next steps include:
    • Improving the command line interface for the plugin.
    • Adding support for "extended discussions" to Commands and exposing
      this information in manuals.
    • Further improve the escaping logic to properly escape MDoc macros
      that might happen to appear in user's help strings.
    • Ingesting external content a-la swift-docc so the entire tool
      documentation does not need to be included in the binary itself.
    • Bug fixes and addressing developer/user feedback.

Built with love,
@rauhul

@rauhul rauhul marked this pull request as draft June 22, 2021 04:46
Package.swift Outdated Show resolved Hide resolved
Package.swift Outdated
name: "roll",
dependencies: ["ArgumentParser"],
path: "Examples/roll"),
name: "MDoc",
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Maybe I should fold this into ArgumentParserGenerators

@rauhul
Copy link
Contributor Author

rauhul commented Jun 22, 2021

@tomerd do you have any ideas on if/how this could work the spm plugin stuff?

@hassila
Copy link

hassila commented Jun 22, 2021

I think splitting out completion script / man page generation to a separate tool would be nice for code size (given the other case about that). Also, are you thinking of DocC style comments inline with the code for the actual man page content? It would be nice if the same syntax could be used?

@tomerd
Copy link
Member

tomerd commented Jun 22, 2021

I assume the desired behavior here would be to create a custom command such as swift package generate-man, if so this needs to wait for additional features in the plugin system which we are considering to add, cc @abertelrud.

@rauhul
Copy link
Contributor Author

rauhul commented Jun 22, 2021

I assume the desired behavior here would be to create a custom command such as swift package generate-man, if so this needs to wait for additional features in the plugin system which we are considering to add, cc @abertelrud.

I'm not exactly sure what the desired UX is, but I think it would be nice to build a package for distribution which would mean creating a layout maybe like this:

package
├── bin
├── lib
└── share

This would be a nice foil to "spm install" which maybe could install any package that is buildable for distribution. Thoughts?

@rauhul
Copy link
Contributor Author

rauhul commented Jul 1, 2021

Also, are you thinking of DocC style comments inline with the code for the actual man page content

I think this would be an excellent future addition, but probably not as inline comments, but instead in the additional articles/tutorials format the DocC supports!

@hassila
Copy link

hassila commented Jul 2, 2021

Also, are you thinking of DocC style comments inline with the code for the actual man page content

I think this would be an excellent future addition, but probably not as inline comments, but instead in the additional articles/tutorials format the DocC supports!

That would be awesome.

@tomerd
Copy link
Member

tomerd commented Feb 20, 2022

@rauhul with swiftpm commands plugins now in place, would be interesting to revisit integration options

@rauhul
Copy link
Contributor Author

rauhul commented Feb 20, 2022

@tomerd I gave a plugin a shot, but I wasn't sure how to fit all the pieces together. Would you mind taking a look at the approach in the most recent commit?

Copy link
Member

@tomerd tomerd left a comment

Choose a reason for hiding this comment

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

i think in this case a command plugin would be a better choice over builtTool one. the docc plugin is an example of a medium complexity command plugin. feel free to dm for more guidance

Package@swift-5.6.swift Outdated Show resolved Hide resolved
@rauhul rauhul marked this pull request as ready for review April 1, 2022 06:31
@rauhul
Copy link
Contributor Author

rauhul commented Apr 1, 2022

@swift-ci please test

1 similar comment
@rauhul
Copy link
Contributor Author

rauhul commented Apr 1, 2022

@swift-ci please test

@rauhul rauhul requested a review from tomerd April 1, 2022 06:39
@rauhul rauhul changed the title [WIP] Manual page generation Add experimental manual page generation Apr 1, 2022
@rauhul
Copy link
Contributor Author

rauhul commented Apr 1, 2022

@swift-ci please test

- Adds a swift package manager command plugin called
  GenerateManualPlugin. The plugin can be invoked from the command line
  using `swift package experimental-generate-manual`. The plugin is
  prefixed for now with "experimental-" to indicate it is not mature and
  may see breaking changes to its CLI and output in the future. The
  plugin can be can be used to generate a manual in MDoc syntax for any
  swift-argument-parser tool that can be executed via
  `tool --experimental-dump-info`.
- The plugin works by converting the `ToolInfoV0` structure from the
  `ArgumentParserToolInfo` library into MDoc AST nodes using a custom
  (SwiftUI-esk) result builder DSL. The MDoc AST is then lowered to a
  string and written to disk.
- The MDoc AST included is not general purpose and doesn't represent the
  true language exactly, so it is private to the underlying
  `generate-manual` tool. In the future it would be interesting to
  finish fleshing out this MDoc library and spin it out, however this is
  not a priority.
- Next steps include:
  - Improving the command line interface for the plugin.
  - Adding support for "extended discussions" to Commands and exposing
    this information in manuals.
  - Further improve the escaping logic to properly escape MDoc macros
    that might happen to appear in user's help strings.
  - Ingesting external content a-la swift-docc so the entire tool
    documentation does not need to be included in the binary itself.
  - Bug fixes and addressing developer/user feedback.

Built with love,
@rauhul
@rauhul
Copy link
Contributor Author

rauhul commented Apr 20, 2022

@swift-ci please test

Copy link
Member

@natecook1000 natecook1000 left a comment

Choose a reason for hiding this comment

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

This is great stuff, @rauhul! 👏 👏 We do need to add a test harness as a follow-up so that we can make sure we're not breaking this plug-in as we move forward.

@natecook1000
Copy link
Member

@swift-ci Please test

@natecook1000
Copy link
Member

@swift-ci Please test

@natecook1000 natecook1000 merged commit 48a799e into apple:main Jun 6, 2022
@rauhul rauhul deleted the rauhul/manual-page-generation branch June 6, 2022 23:47
leuski pushed a commit to leuski/swift-argument-parser that referenced this pull request Jun 17, 2022
* 'main' of github.com:apple/swift-argument-parser: (114 commits)
  Fix `AsyncParseableCommand` hierarchy (apple#436)
  Add experimental manual page generation (apple#332)
  Improving edit distance string extension (apple#446)
  List valid options in error messages for enum array argument (apple#445)
  Remove LinuxMain.swift (apple#367)
  Hide hidden subcommands from completions (apple#443)
  Update changelog for 1.1.2 release (apple#441)
  Fix error message for @option array without values (apple#435)
  Fix Repeat's endless printing (apple#437)
  build: statically link ArgumentParserToolInfo always (apple#424)
  Update changelog for the 1.1.1 release (apple#428)
  build: complete the changes from apple#423 (apple#425)
  Remove platform requirement from Package.swift (apple#427)
  build: repair the build after apple#404 (apple#423)
  Fix broken links/incorrect variance calculation (apple#422)
  Update changelog for the 1.1.0 release (apple#421)
  Update documentation (apple#420)
  Make `@OptionGroup(visibility:)` a public API (apple#419)
  Support an `async` entry point for commands (apple#404)
  Fix a typo and template links (apple#418)
  ...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants