-
Notifications
You must be signed in to change notification settings - Fork 16
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
Introduce (optional) categories to group subcommands #3
Conversation
Looks pretty great to me! I'd love you to provide an example code listing of this PR in use, so I could test it out locally and look for possible improvements? |
Sure thing. Here's an example based on your official example: https://gist.github.com/sahib/c7d141a5d467450c78ad I also changed it a bit: It uses slices now to remember the order categories (and commands) were inserted - I guess, mostly you do not want I guess the templating could be a bit prettier (first time I had to look a it...). |
I am really into what you've done here, but I am still not sure how this generally fits the feel of the tool itself. I am kind of antagonistic to the whole caps thing, it just looks a little bit alien to me. Aaand I haven't got a chance to deeply look into the code so far. Wouldn't you mind if I take some time on reviewing this? |
Take your time. The caps are not necessary to be honest, but were kinda convenient. |
Here is a draft diff (against b236233) I hacked a while ago: https://gist.github.com/tucnak/ef17042fa1b5a9d2363b That's how I see it, but I am totally open to discussion. The diff above is just a draft, sort of PoC implementation. Code listing https://gist.github.com/tucnak/6ac7fd3dce564b21a8fb produces:
|
Btw, don't you know, am I anyhow able to push into your PR? |
I like your draft better - I was afraid to add more API (like the extra
I don't think that's possible directly. Usually you would add my forked repo as origin, $ git remote add sahib https://github.com/sahib/climax.git
$ git fetch sahib
$ git checkout -b feature/groups
$ git merge sahib/master
$ # play around and review it, possibly push it for others.
$ git checkout master && git merge feature/groups (Sorry if I re-iterated on something you already knew) |
Fork-remote & fetch is exactly the way I'm doing this now. I was just wondering if it's possible to push to refs/pull/id/head, turns out it's not. Anyway, looking forward to hearing some feedback on patch from you! |
I like it. One thing I'd like to change is the formatting of the group headers, i.e. I would just let the user define how it's formatted. I could use caps ( So basically, as some sort of mini-patch: 😄 - # {{.Name}}
+{{.Name}} P.S: |
Didn't touch tests at all so far. I believe you'd be able to tweak it, wouldn't you? Regarding the caps: I just don't think it fits the feel. Using caps'ed section names kind of pushes us towards using caps everywhere (e.g. Why don't you like approach I proposed? I am asking cos it looks perfectly fine and just right to me. |
I added the patch to my pull request and fixed the tests in the same run. Regarding caps: I guess that's a bit subjective - I like the look, since it separates the groups nicely. (Current PR includes the version with no formatting (like |
Alright, we could define some sort of a struct with a list of preferences. type Preferences struct {
// Defaults to false => weak separation, while
// true breaks it into separate top-level sections.
HardGroupSeparation bool
// Allows to replace # with .e.g "//", which looks funky :)
GroupSeparationSign string
} So in case of hard group separation, What do you think? |
That would work out too, but is somewhat less simpler and is probably not be in the scope of this PR. |
Sorry, couldn't get in touch these days. Yuppy yeah, I love your current implementation, but it misses some documentation. Can you please add some so I could merge it in? |
Aye, updated. See 0a8f769. |
Introduce (optional) categories to group subcommands
For some larger programs it's sometimes useful to group commands into categories.
This patch should not alter normal output, but when filling out
Command.Category
,it will be grouped accordingly.
Here's an example from ipfs: