dredd icon indicating copy to clipboard operation
dredd copied to clipboard

Access Custom options in Hooks

Open chrislondon opened this issue 9 years ago • 5 comments

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?

chrislondon avatar Jun 09 '15 13:06 chrislondon

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

:+1:

netmilk avatar Jun 09 '15 14:06 netmilk

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

netmilk avatar Jun 17 '15 14:06 netmilk

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.

honzajavorek avatar Nov 03 '16 15:11 honzajavorek

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.

honzajavorek avatar Aug 06 '18 16:08 honzajavorek

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 || {};

priyanshuwustl avatar Jul 15 '20 16:07 priyanshuwustl