dbrgn / tealdeer

A very fast implementation of tldr in Rust.
https://dbrgn.github.io/tealdeer/
Apache License 2.0
4.06k stars 123 forks source link

show the subpage hierarchy of a command #370

Closed jgogstad closed 1 month ago

jgogstad commented 2 months ago

Several tldr pages have subpages that form a hierarchy of tldr pages for a single high level command. E.g. one can do tldr git branch to show the tldr page for the git branch subcommand. Show available subpages when viewing pages higher up in the hierarchy. For instance

tldr git
…
available sub pages:
git
├── branch
├── commit
├── push
└── worktree
    ├── add
    ├── list
    └── remove
jgogstad commented 2 months ago

label as feature request obviously

niklasmohrin commented 1 month ago

I thought about this a bit and I think it is not feasible, since this hierarchy is not recognizable for us. The problem is that pages for subcommands like git add are saved as git-add.md, so we cannot easily distinguish between subcommands and commands that have a "-", for example xdg-open

Now, we could open the file and check which version is used in the examples, but that seems like a lot of effort for a very niche use case

jgogstad commented 1 month ago

yeah, analyzing file contents is not the way to go. I think just enforcing the naming standard make sense. That is, xdg-open.md is a subcommand of xdg.md. The logic would be "if the parent exists, print it as the parent, if children exists print the children. If none exists, don't print anything".

That means that if there is a case where there's a binary xdg and a binary xdg-open and they have nothing to do with one another, they will be incorrectly marked as a parent child relationship. That is awfully fringe though, I'm yet to be convinced that a case exists. Worst case you could add a flag to disable relationship printing 🤷‍♂️

dbrgn commented 1 month ago

I concur with @niklasmohrin. First of all, enforcing naming standards is not up to us, it's up to the tldr project. While this might be possible to implement using a set of heuristics and "does this binary exist" file system checks, that would make tealdeer both slower and harder to maintain (because the complexity is increased).

To see subpages, I recommend installing shell completions and pressing the tab key after tying the base command:

image