kcl-lang / kcl-lang.io

KCL Website and Documentation Repo: https://kcl-lang.io
https://kcl-lang.github.io
Apache License 2.0
13 stars 35 forks source link

[FAQ] option usage #316

Closed reckless-huang closed 5 months ago

reckless-huang commented 5 months ago
image

This is the option prompt in the IDE, but it seems that the required and default here are not working properly. Also, is this writing method the same as defining a default value with option() or xxx?

reckless-huang commented 5 months ago

What are the differences between ‘option(key, type, required, default, help) ’ and 'option("aaa") or defaut'

Peefy commented 5 months ago

The IDE will automatically complete all keyword parameters, and you can use the parameters you need to delete other unnecessary parameters.

The function of option ("key") or "value" is greater than that of option("key", default="value"). The latter indicates that when the user does not set -D key= by the CLI, the value is taken as "value". The former takes the value of both and use or to calculate them, for example, even if the key is set, but the value of the key is empty e.g., "", False, None, etc, the value will still be taken as "value".

reckless-huang commented 5 months ago

Got it. Can required and optional parameters be defined within the option?

Peefy commented 5 months ago

Do you mean a = option("key", default="value", required=True)?