spf13 / cobra

A Commander for modern Go CLI interactions
https://cobra.dev
Apache License 2.0
37.63k stars 2.83k forks source link

bug: cobra doc generator fails when command contains path separators #1616

Open jimschubert opened 2 years ago

jimschubert commented 2 years ago

Due to this line: https://github.com/spf13/cobra/blob/178edbb247f35e466578211dcf5f4892dbbd369b/doc/md_docs.go#L140

I'm unable to generate docs for one of my more complex commands. My subcommands directly match a string value known to my users which contains /. For instance:

cli run job/first [args]

cobra doc generation occurs for the run command, but fails for the job/first subcommand with a message such as:

open docs/cli_run_job/first.md: no such file or directory

I think a simple fix would be to include replacement of / with _ when determining the filenames.

johnSchnake commented 2 years ago

If commands can have the slash in them I agree the doc gen should work as well.

It sounds like you've already done some digging into it so if you want to put up a PR and tag me I can review it.

Thanks for the issue!

jimschubert commented 2 years ago

@johnSchnake unfortunately, I'm not able to contribute the change as I've found this at work, and I'd have to go through a whole legal process to gain approval for the contribution.

marckhouzam commented 2 years ago

Apologies for the error in transferring this issue to spf13/cobra-cli. The issue is about documentation generation, not code generation. I have transferred it back.

I just found out about GH's ability to transfer issues and I was trying to cleanup a bit.

jimschubert commented 2 years ago

@johnSchnake my rules at work changed such that I can contribute without legal approval as long as it's from my personal machine and on my own time.

I've added the support for markdown, manpages, rest, and yaml outputs in #1675.