-
-
Notifications
You must be signed in to change notification settings - Fork 203
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
How to create required CLI config options? #828
Comments
If the solution in the linked issue is not sufficient, then it seems you're asking a slightly different question. Specifically, whether there's some way to mark configurable traits in such a way that they will be treated as With that said, I don't think it would be especially difficult to allow for this. Before jumping to any particular implementation it would be useful to get some input from other maintainers, but my approach would be as follows... instead of adding more metadata to interpret, we could simply handle a generic class App(Application):
optional_arg = Int(config=True)
req = Unicode(config=True).tag(argparse_kwargs={"required": True}) |
First thing is that the concept of required is not just for the CLI: it also applies to simply making objects programmatically. Next, I find the syntax The class App(Application):
optional_arg = Int(config=True)
req = Unicode(config=True)
@default('req')
def _default_req(self):
raise TraitError('value must be set on CLI or at object construction time') |
Another thing regarding this sample - class MyS3Class(HasTraits):
s3_bucket_name = Unicode()
@validate("s3_bucket_name")
def _validate_s3_bucket_name(self, proposal):
if not proposal.value:
raise ValueError("S3 bucket name cannot be empty.")
def __init__(self, s3_bucket_name, **kwargs):
super().__init__(**kwargs)
self.s3_bucket_name = s3_bucket_name The positional argument to |
FYI unfortunately this is not possible with the current implementation, there are no arguments added to the Regarding the original issue, using
(Using a positional argument in |
I really like
Then we could just go:
|
In #490 this issue was raised and then closed by @rmorshea.
However,
So:
Here is a code sample for you to elide with what is necessary to make the
req
attribute mandatory:I'm expecting an exception to be thrown when I invoke this app without providing req:
The text was updated successfully, but these errors were encountered: