Skip to content
This repository has been archived by the owner on Nov 8, 2024. It is now read-only.

Access Custom options in Hooks #215

Open
chrislondon opened this issue Jun 9, 2015 · 5 comments
Open

Access Custom options in Hooks #215

chrislondon opened this issue Jun 9, 2015 · 5 comments

Comments

@chrislondon
Copy link

Unless I'm mistaken I can't seem to find any way to access custom options in my hook file. I would like to use custom options so my hook file is more flexible. Is this possible?

@netmilk
Copy link
Contributor

netmilk commented Jun 9, 2015

Hi @chrislondon, this is unfortunately not possible at this moment. I consider it as very useful future feature.

👍

@netmilk netmilk changed the title Can't access Custom options in Hooks Access Custom options in Hooks Jun 9, 2015
@netmilk
Copy link
Contributor

netmilk commented Jun 17, 2015

Actually, this is maybe even better then I thought initially. This could make possible to do a huge clean-up in Dredd codebase and move lot of stuff under hooks - some kind of plugin architecture.

All this all functionality should be moved under hook architecture:

--dry-run
--names
--only
--header
--sorted
--user
--method

@honzajavorek
Copy link
Contributor

I was able to successfuly use custom options in JavaScript hooks, but it's pretty hidden feature and I don't believe it's possible in other languages as of now:

var hooks = require('hooks');
var userId = hooks.configuration.options.custom.userId || {};
...

Also, I don't know if this is intended or hack, so I'd be cautious when using it. We may rebuild this "feature" in the future.

This was referenced Nov 3, 2016
honzajavorek referenced this issue Jul 25, 2018
- Resolves "CLI options docs out of sync with reality" problem.
- Fixes "hooks should be mentioned in alphabetical order everywhere".
@honzajavorek
Copy link
Contributor

If you're using non-JS hooks, you can load the YAML file in the language of your choice and easily parse out the values yourself.

It's going to take a long time until non-JS hooks will be able to access custom data from Dredd, because it means we'd need to change the protocol how Dredd communicates with the hook handlers and all the hook handlers would need to implement it.

artem-zakharchenko pushed a commit that referenced this issue Oct 9, 2019
Update eslint to the latest version 🚀
@priyanshuwustl
Copy link

priyanshuwustl commented Jul 15, 2020

I was able to successfuly use custom options in JavaScript hooks, but it's pretty hidden feature and I don't believe it's possible in other languages as of now:

var hooks = require('hooks');
var userId = hooks.configuration.options.custom.userId || {};
...

Also, I don't know if this is intended or hack, so I'd be cautious when using it. We may rebuild this "feature" in the future.

This worked for me instead. I was getting undefined for options. I am using dredd v12.2.1.

var userId = hooks.configuration.custom.userId || {};

# for free to subscribe to this conversation on GitHub. Already have an account? #.
Projects
None yet
Development

No branches or pull requests

4 participants