lucapette / fakedata

CLI utility for fake data generation
MIT License
200 stars 7 forks source link

WIP: bash/zsh completion #53

Closed KevinGimbel closed 7 years ago

KevinGimbel commented 7 years ago

This is a pull request for feature #25

Synopsis

bash/zsh completion gives the user a way to tab through available generators and options/arguments when using fakedata.

A user can type fakedata i[TAB] to get a list of available arguments and generators.

$ fakedata i
 -- arguments --
int   ipv4  ipv6

How to enable

At the moment the completion functions needs to be added to the .zshrc or .bashrc file. Using eval() does not work yet.

# zsh
$ fakedata --completion zsh >> ~/.zshrc

#bash
$ fakedata --completion zsh >> ~/.bashrc

Here's an asciinema showing the current implementation: https://asciinema.org/a/lpxxldZqyTnbUoeR3aKnO2kHt

This is a work in progress as I'd like to get the eval $()-thing to work. It's easier to use/maintain then adding the function to bashrc/zshrc.

Todo

lucapette commented 7 years ago

This is a fantastic addition ❤️. Thank you so much for taking care of it. Sadly, I'm a bit short on time today so I can't properly test it before merging.

All my comments are minor stylistic nuances and I can take care of them when I find a minute to test if you don't have the time for it. We'd need a mention in the docs but I can add that when we release it (v1.1.0 maybe?)

Anyway, the builds are failing because of the "personal import" which is somehow a nice test of the CI system :)

lucapette commented 7 years ago

Sorry! I completely missed the comments about the feature being a WIP! Well then we just give the PR some time. Thank you again for taking care of this. I can't wait to ship it!

KevinGimbel commented 7 years ago

@lucapette I fixed the issues beside the use of flag.StringVarP. I'm not too familiar with the pflag package (or Go in general 😄) so I'm not sure how to handle this.

I could remove the switch in findCompletionTemplate and handle the switching in another way that supports type *string.

KevinGimbel commented 7 years ago

@lucapette Travis builds are green again but AppVeyor fails with "Specify a project or solution file. The directory does not contain a project or solution file." - do you know what's the issue? I haven't worked with AppVeyor yet.

KevinGimbel commented 7 years ago

@lucapette I fixed the StringVarP thing. Not sure what I was doing yesterday but it's working now and inline with the other flags.

lucapette commented 7 years ago

@kevingimbel this looks awesome! I'll do some testing and merge as soon as I can. I didn't know appveyor was already trying to run tests. I would ignore it for now (but I do want to run tests in a windows env!)

lucapette commented 7 years ago

@kevingimbel awesome work! Minor adjustments here. Probably the only thing worth noticing is the usage of a fakedata_test package for tests so we're sure we test the public interface of the package (which I like a lot)