From 311cb9fbe94fe09c0dc08a52f5bff169529960ba Mon Sep 17 00:00:00 2001 From: William Woodruff Date: Fri, 29 Sep 2017 18:31:28 -0400 Subject: Support for required options This commit introduces support for required options, which are options that cause the parser to raise a `MissingRequiredOption` exception if not present. Options can be marked as required by passing `required: true` in their configuration, and any errors caused by missing required options can be suppressed via `suppress_errors: true`. --- README.md | 2 ++ 1 file changed, 2 insertions(+) (limited to 'README.md') diff --git a/README.md b/README.md index 505d4c5..4d686ce 100644 --- a/README.md +++ b/README.md @@ -20,6 +20,7 @@ Usage opts = Slop.parse do |o| o.string '-h', '--host', 'a hostname' o.integer '--port', 'custom port', default: 80 + o.string '-l', '--login', required: true o.bool '-v', '--verbose', 'enable verbose mode' o.bool '-q', '--quiet', 'suppress output (quiet mode)' o.bool '-c', '--check-ssl-certificate', 'check SSL certificate for host' @@ -197,6 +198,7 @@ Slop will raise errors for the following: * An option used without an argument when it expects one: `Slop::MissingArgument` * An option used that Slop doesn't know about: `Slop::UnknownOption` +* An option marked as `required` when not provided: `Slop::MissingRequiredOption` These errors inherit from `Slop::Error`, so you can rescue them all. Alternatively you can suppress these errors with the `suppress_errors` config -- cgit v1.2.1