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

Feature: Add Required and Shortcut #14

Open
wants to merge 14 commits into
base: master
Choose a base branch
from

Conversation

deranjer
Copy link
Contributor

This is obviously a large change, but add Shortcuts and Required commands that allow the user to set shortcut commands/flags and to mark a command/flag as required.

CommandRequired()
FlagRequired(flagName string)
CommandShortCut(cmdShortCut string)
FlagShortCut(flagLongName string, flagShortCut string)

A bunch of examples are in the folder (required, shortcut, and advanced). The advanced example just ties a lot of things together showing some advanced usage. I've run a lot of commands through the code and after a few tweaks I think everything is working as expected. Haven't really done testing in golang before but can look at adding some test statements.

To the "main loop" I've added code to convert command and flag shortcuts (runs over ALL args as a precaution for both flags and commands, but perhaps just need to test args[0] for commands)

I then added a function call in the main loop called checkRequired, this checks all of the args to see what flags/commands were specified vs what commands/flags are required. It then prints out the error(s) for missing flags/commands.

No external libraries were added, but "text/tabwriter" was added to format my portion of the help output.

@leaanthony
Copy link
Owner

Wow! I can't believe this has been sat here for so long! 2020 eh? If you think this is still good, I'll spend some time looking at it over the holidays.

@deranjer
Copy link
Contributor Author

deranjer commented Dec 2, 2020

Should be good, I've used it and no problems found so far.

@bh90210
Copy link
Contributor

bh90210 commented May 31, 2021

uh I forgot this existed and just this morning I implement this feature (partially) myself.
my approach was much less involved and because I included 1. a dependency (from Russ Cox but still) 2. it changed the functionality and 3. the usage is not super clear and nice (I went for the simplistic cli.BoolFlag("test", "t", "Some description", &var)) hence I am not even opening a PR but I am leaving it here just for reference
https://github.com/bh90210/clir/tree/feat/flagaliases

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.

3 participants