cloudfoundry-community / node-cfenv

easy access to your Cloud Foundry application environment for node
Apache License 2.0
73 stars 20 forks source link

getServices(spec) ? #7

Closed srl295 closed 8 years ago

srl295 commented 9 years ago

getServices() returns all services.

Could it take an optional spec parameter with a regex?

Then if I bind against a bunch of MyService-abc, MyService-bcd, ... I can do getServices(/MyService-.*/) to use a user-provided service to set a list.

pmuellr commented 9 years ago

That seems like it makes sense; it would be extending the functionality of getServices(), and fills a niche of finding services that match some kind of spec. Should it be the same kind of spec as getService()?

srl295 commented 8 years ago

Yes, I'd think the same kind of spec. Maybe returning a map like { "MyService-abc": { stuff..}, "MyService-bcd": {stuff…}}

pmuellr commented 8 years ago

I guess it would be useful for you to see if just filtering the result is easy enough. See https://tonicdev.com/pmuellr/get-services-spec for an example of filtering the results with underscore.pick().

Here's the code from the tonic:

const us = require("underscore")

const services = {a:"1", b:"2", c:"3"}

console.log(us.pick(services, (val,key)=>key.match(/a|b/)))
console.log(us.pick(services, ["b", "c"]))

I don't really have the cycles for this. If someone does want to add it, submit a PR:

srl295 commented 8 years ago

@pmuellr looks easy enough wiht pick(), thanks.