-
Notifications
You must be signed in to change notification settings - Fork 7
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 REQ: concatenate fields #17
Comments
oh f..k, it looks like have done it, and it survives make test, and seemingly it works, But i did not done a fork, and i dont know how to make a pull request for my changes. also i added a nev generator for enabling hungarian name order, and changed the dict.go to contain hungarian first and lastnames |
Created #18 but seems that with editing here on github, i could not to resolve the gofmt -s problem, that is reported by travisCI. |
@gnanet first of all, thank you very much for the feature request! It's really I'm very grateful you started working on a PR but somehow sad I couldn't manage I've been thinking about a way to provide a
Given these points, I suggest we try something like: $ fakedata composed,"TEMPLATE" Where
Of course, the hardest part is the syntax. My first suggestion would be taking $ fakedata email composed,"server{int,1..5}.{domain}"
test@example.com server3.test.com I feel that requiring users to use quotes and surround fields with Personally, I'm not really happy with my own proposed syntax (sigh!) and I hope |
I thought about this for a while after working on the validations and I believe the most dynamic/open way would be to add template support where users could actually write a template file and we parse it. Go has a great standard template engine which isn't too complex to get into (from a users point of view). By adding template support we could also add custom function for joining generators and then people could use these functions inside the templates to generate whatever type of datasets they want and join generators as needed. I guess this is harder to implement but - in my opinion - brings the most flexibility in the long term. |
Without deep knowledge about the mentioned template engine of Go, i would say that we should not re-implement the wheel, if we can build the data template syntax on top of it, then we should do it so. Btw, i for at least 1,5 hours i was not aware what the purpose of generators.golden was, i just simply followed the information it contained, and while extending generators.go, i also added the relevant information. I did not know that this is the intergration test, that said long time i just could not understand why make test fails at that diff part, until i done the diff myself for the -g output and understood that a newline on the end of generators.golden made my test fail so much hours.... :) I will continue thinking about the above mentioned points of the custom/complex/freeform generator (just to add some extra name ideas ;) ) and get back to you if i have useful to write. |
@gnanet it's a good point you raised with the names. Names are hard to get right because there are so many different formats (like you said, in Hungarian it's |
@gnanet also in case you want to read up on Go templates here's the package documentation: https://golang.org/pkg/text/template/ |
@KevinGimbel yesterday i tried to be smart by reading the docs, but the golang docs seem dry to me like the data descriptions from the RFC about any internet protocol. I think i can learn better trough examples, but i will surely find my way ;) Right now an idea also came into my mind, that a separate ticket should be opened about the functionality and purpose of .fakedatarc |
@KevinGimbel I'm not sure I understand how your suggestion would work in practice. I don't have a strong opinion on the syntax we use but I'd like to keep the API on the commandline as simple as possible. If what you're proposing is harder to implement but easier to use for the end user then we shouldn't care it's harder to do :) Do you mind sharing some example of how your proposal would look like? As far as I understand, it would be something like: $ fakedata --input=template.txt which is different from what I have in mind but I see the point. We could still provide a shortcut for that with an @gnanet I wrote about integration tests here. There's a short explanation of what Golden files are too. |
@lucapette I made a quick-n-dirty go snippet to showcase the template approach. https://play.golang.org/p/5qQYBqnWax The todos would basically be:
The CLI usage would still stay the same because the template feature builds upon but does not change the existing generators (at least I believe it's that way). People who just need a quick set of data can still run {{ range . }}
{{- $name := printf "%s %s" .Lastname .Firstname -}}
{{- $orderItems := RandomInt 10 15 -}}
<order orderid="{{ RandomInt 10000 99999 }}">
<customer>
<name>{{ $name }}</name>
<email>{{ .Email }}</name>
</customer>
<items>
{{ range loop $orderItems }}
<item>
<name>{{ ProductName }}</name>
</item>
{{ end }}
</items>
</order>
{{end}} Go Playground: https://play.golang.org/p/3j_fcdi7XW Templates probably need the most planning and the most work but long term they are the most flexible. Theoretically they could be written inline but it's a lot of stuff to write. Maybe we can allow every generator to use a template inline like so |
@KevinGimbel thank you for the example. It does look like a lot of work but if we can justify it I don't mind. I do like the idea of providing a more powerful API for those that need to create more complex random data set while keeping the everyday usage of the CLI as easy as today. Anyway, I'm still not sure how you'd like users to use templates from a CLI perspective. What do you have in mind? |
About the ability to inline generators. I wasn't thinking about rewriting the existing API. I really like the simplicity of the current approach: |
I, too, would like to keep For this reason I would introduce a sub-command, The "workflow" would be: $ cat user.tmpl
<users>
{{ range . }}
<user>
<name>{{ .Name }}</name>
<age> {{ Int 18 99 }}</age>
<email> {{ .Email }}</email>
</user>
{{ end }}
</users>
$ fakedata compose --in user.tmpl --out user.xml --limit 1
$ cat user.xml
<users>
<user>
<name>Kevin Gimbel</name>
<age>23</age>
<email>catchall@nota.website</email>
</user>
</users> The names ( As for inline, it will get quite messy IMO. We need another separator or keyword to assign templates "on the fly", e.g.
Introducing a new separator like When I find the time I'll do some prototyping and see what I can come up with as I work. Maybe it's becoming clearer to me then. |
@KevinGimbel ok you convinced me :) I like the workflow too. A few notes:
As a side note, I'd keep in mind that it would be good user experience if I think this feature + some more generators and minor gardening can give us a proper
I'm very happy about this conversation and the feature we're designing. Thank you everyone for the awesome help! |
Looks good to me! I'm a huge fan of piping output on the CLI, so As for the output redirection with I'd love to work on the templating functions, I wanted to learn more about Go templates anyway and having a real use case makes it "easier" because I don't need to think of a project of my own. 😄 |
@KevinGimbel I've looked into detecting stdin a while ago but I don't remember the details right now, we can do it in a separate PR once we've got the feature. I think you have a good point about the error. I'll do some research about how other CLI handle the issue, right now it's not a big issue as I think it'll take a while before we land the feature in master. I'm very happy to hear you'd like to give it a try. I'll focus on the issues/milestone then! @gnanet do you like where we're heading with the feature? In the end you requested it, your feedback is more than welcome! |
Guys, as you may see i do lot more at night/evening at least in CEST zone. I will have to read all trough, but the idea to keep things still simple, while adding a lot more complex templating feature. This goes beyond my simple expectations, but i find, it will be good adventure into golang for me. |
@gnanet would you like to give templates a try? Otherwise I'll start working on it in the coming days. :) |
The subject of my issue got far from to what it is evolved, do you think it would be wise to change the subject at least to better reflect the changes it started in the project? |
@KevinGimbel @gnanet I'm closing this one as we're discussing it in #45 |
I know the name generators do only english names, but i wanted to generate a hungarian name order with "lastname firstname" into one field, and found out that this is currently not possible.
This also leads to a possible new feature, that a language specific dict map may be loaded run-time with a parameter :) But let me go back to the original idea
The enum function allows freely definiable datasets, but sometimes it would be desired to combine at least two fileds into one, with a separator (that may also be empty)
I am in no means a programmer, but can read code and found there are working examples that already do this kind of data generation:
domain => domain.name,domain.tld,"."
email => username,domain,"@"
name => name.first,name.last," "
Maybe a generator similar to enum could implement the withSep function as a field definition, that is able to understand the 3 parameters, but the splitting of the parameters would need a bit thinking...
Anyway, thank you for this great tool, and that you in advance, if you find the time and motivation to work on this feature.
The text was updated successfully, but these errors were encountered: