-
Notifications
You must be signed in to change notification settings - Fork 19
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
base: master
Are you sure you want to change the base?
Conversation
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. |
Should be good, I've used it and no problems found so far. |
uh I forgot this existed and just this morning I implement this feature (partially) myself. |
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.