Do dry-cli
support validation on options
?
Something like
option :url, type: :string, format: /^https:\/\/.*/ , ...
Do dry-cli
support validation on options
?
Something like
option :url, type: :string, format: /^https:\/\/.*/ , ...
I wouldn’t embed this into option
, but rather use composition and have a dry-schema
(or dry-validation
) contract instead.
class MyCommand < Dry::CLI::Command
def initialize(contract: MyDrySchemaContract)
@contract = contract
end
def call(**input)
result = @contract.call(input)
unless result.valid?
puts validation.errors.to_h # TODO: pretty print error message
exit(1)
end
# do the rest of the job...
end
end