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

refactor args parsing with go-arg library #73

Merged
merged 1 commit into from
Feb 5, 2021
Merged

refactor args parsing with go-arg library #73

merged 1 commit into from
Feb 5, 2021

Conversation

mattlqx
Copy link
Collaborator

@mattlqx mattlqx commented Feb 4, 2021

This pull refactors all command argument parsing so that flags can be mixed with positional arguments in commands.

  • implement go-arg for parsing in main
  • convert all commands to use go-args for arg parsing
  • add descriptions to commands
  • dynamically populate auto-complete with commands and usage info
  • removes the need to modify completer.go when adding or updating commands

Screen Shot 2021-02-04 at 22 35 37

Fixes #71

This will also allow me to be able to take a string argument for #72

Zero maintenance help for both main and subcommand completion.

➜ build/vsh_darwin_amd64 -h    
vsh - Shell for Hashicorp Vault
v0.7.2-10-g3ad5080
Usage: vsh_darwin_amd64 [--cmd CMD] [--disable-auto-completion] [--log-level LEVEL]

Options:
  --cmd CMD, -c CMD      subcommand to run
  --disable-auto-completion
                         disable auto-completion on paths
  --log-level LEVEL, -v LEVEL
                         DEBUG | INFO | WARN | ERROR - debug option creates vsh_trace.log [default: INFO]
  --help, -h             display this help and exit
  --version              display version and exit
➜ build/vsh_darwin_amd64 -c 'append'                                              
source is required
appends the contents of one secret to another
Usage: append [--force] [--skip] [--rename] SOURCE TARGET

Positional arguments:
  SOURCE
  TARGET

Options:
  --force, -f            Overwrite key if exists
  --skip, -s             Skip key if exists (default)
  --rename, -r           Rename key if exists
  --help, -h             display this help and exit

@mattlqx mattlqx marked this pull request as ready for review February 5, 2021 05:36
escaped := false
arg := ""

for _, c := range line {
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I should've just looked for a library in the first place rather than spending a night trying to implement this. 😎 But I learned I guess.

cli/cat.go Outdated Show resolved Hide resolved
this implements go-arg and argv to handle argument parsing from the command line and go-arg in each command to handle any command specific arguments passed to it.
Copy link
Owner

@fishi0x01 fishi0x01 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is amazing work @mattlqx
I will restructure the documentation tomorrow accordingly.
Again, thank you so much for your contribution 🙇

@fishi0x01 fishi0x01 merged commit 5ed1676 into fishi0x01:master Feb 5, 2021
@mattlqx mattlqx deleted the 71_args branch February 5, 2021 22:55
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.

Use an arg parsing library for main and subcommands
2 participants