ava icon indicating copy to clipboard operation
ava copied to clipboard

Separate config keys from CLI flags

Open novemberborn opened this issue 10 years ago • 19 comments

Currently the config object in the package.json is passed as-is to meow, providing default values for the CLI flags. This means that config keys need to match the CLI flags. CLI flags are singular, but sometimes config keys are better when pluralized. E.g. sources versus source, and the suggested extension flag in #631 versus extensions.

@avajs/core how about we change some of the config keys to be plurals and map them to meow's default in cli.js?

novemberborn avatar Sep 21 '16 16:09 novemberborn

Sounds good.

This would also be a good opportunity to document the package.json options separately instead of just referring to the CLI flags and show a JSON config dump.

sindresorhus avatar Oct 03 '16 16:10 sindresorhus

Hey guys, I'd like to do it but need further depiction.

omerbn avatar Nov 24 '16 15:11 omerbn

@omerbn AVA loads config from package.json here: https://github.com/avajs/ava/blob/262911f02b0857ce3873e353a547bf009bf4e795/lib/cli.js#L24

It is passed to meow here: https://github.com/avajs/ava/blob/262911f02b0857ce3873e353a547bf009bf4e795/lib/cli.js#L74

The goal is to pass a different object to meow where the keys match the long option names in the meow configuration, so that we can change the package.json config to use different key names. E.g. pass source to meow but use sources in package.json.

novemberborn avatar Dec 03 '16 18:12 novemberborn

@novemberborn what keys in particular are to be mapped in configuration object? Like the keys we want to be used as plurals.

yatharthx avatar Jan 24 '17 03:01 yatharthx

Hi @yatharthk. There've been a few developments since I started this issue. We won't have an extensions flag, the require flag has been removed, and we're looking to remove the source flag (#937).

I think a good place to start would be to stop passing default: conf in the call to meow. We could then merge the resulting cli object with conf. Hopefully that leads to the same behavior. It'll then allow us to decouple the config keys from the CLI flags where needed (though I don't think there are any such cases at the moment).

novemberborn avatar Jan 25 '17 10:01 novemberborn

@novemberborn Thanks. Shall I pick up the task of pulling out the default: conf when calling meow? Is there a relevant issue or we need to create one?

yatharthx avatar Jan 25 '17 11:01 yatharthx

Hey @yatharthk,

Is there a relevant issue or we need to create one?

This would be the one.

Shall I pick up the task of pulling out the default: conf when calling meow?

Thanks for volunteering!

Could you check in with @ThomasBem first? He's running into an issue for which this would be the solution, though there's a workaround available to him as well. See discussion in https://github.com/avajs/ava/pull/1198#issuecomment-275073726.

novemberborn avatar Jan 25 '17 18:01 novemberborn

@novemberborn Thanks for pointing that out for me. 👍

yatharthx avatar Jan 26 '17 13:01 yatharthx

@yatharthk looks like @ThomasBem is working around the issue. Do you want to take this then?

novemberborn avatar Jan 30 '17 09:01 novemberborn

@novemberborn Would love to. Can you please guide me with proceeding on this? Thanks.

yatharthx avatar Jan 31 '17 05:01 yatharthx

@yatharthk sure, feel free to post your questions here.

novemberborn avatar Jan 31 '17 09:01 novemberborn

@ThomasBem I'm planning to pick this issue for removing the default: conf from call to meow. Would that be fine or you are doing that? Also, we aren't going to deal with any cli flags here, for now; if I'm not wrong. Please correct my knowledge if I'm wrong over here. @novemberborn

yatharthx avatar Jan 31 '17 11:01 yatharthx

You're correct, and go ahead.

novemberborn avatar Jan 31 '17 11:01 novemberborn

@novemberborn I'm working on this now. Would be great if you could hint me on the right approach to merge cli object with conf. What I can understand is default creates flags on the cli object. Is it something like we merge conf into cli.flags or something? I tried this but I don't think this is something we need to do!

yatharthx avatar Jan 31 '17 18:01 yatharthx

I think pick the correct default values out of conf, to pass to meow. Then read either from cli.flags or conf when passing values to the Api constructor etc.

novemberborn avatar Feb 01 '17 13:02 novemberborn

@novemberborn So here's what I think: Instead of passing conf to meow as default, let's keep it separate and override it's properties with those of cli.flags, maybe something like Object.assign(conf, cli.flags) and then we can use conf in place of cli.flags everywhere. If this makes sense, I'll go ahead and make the changes.

yatharthx avatar Feb 04 '17 15:02 yatharthx

You still need to provide default values based on conf to meow. I'm OK with copying the resulting cli.flags back into conf.

novemberborn avatar Feb 05 '17 17:02 novemberborn

Okay I got your point here. The thing that's bit tricky for me here is understanding what you talk about picking default values out of conf. As I understand, it already contains all the default values. Shouldn't we be picking the entire conf? How do I approach the picking of defaults from conf? 🤔

yatharthx avatar Feb 06 '17 03:02 yatharthx

The thing that's bit tricky for me here is understanding what you talk about picking default values out of conf.

Ah! I mean when providing default to meow, we should only pass those values that meow uses. So in https://github.com/avajs/ava/blob/b886c5b25ae54430f908c49f9932d8f998c41702/lib/cli.js#L73 change to default: { failFast: conf.failFast, serial: conf.serial } and so forth.

novemberborn avatar Feb 06 '17 10:02 novemberborn