Check for required options

Project: http://git-wip-us.apache.org/repos/asf/lucy-charmonizer/repo
Commit: http://git-wip-us.apache.org/repos/asf/lucy-charmonizer/commit/3c4bdd89
Tree: http://git-wip-us.apache.org/repos/asf/lucy-charmonizer/tree/3c4bdd89
Diff: http://git-wip-us.apache.org/repos/asf/lucy-charmonizer/diff/3c4bdd89

Branch: refs/heads/master
Commit: 3c4bdd8911ddfce2772312bcbc8cc3a48450e8c4
Parents: 222f0b5
Author: Nick Wellnhofer <[email protected]>
Authored: Sat Dec 27 15:36:14 2014 +0100
Committer: Nick Wellnhofer <[email protected]>
Committed: Sat Dec 27 15:36:14 2014 +0100

----------------------------------------------------------------------
 src/Charmonizer/Core/CLI.c | 9 +++++++++
 1 file changed, 9 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/lucy-charmonizer/blob/3c4bdd89/src/Charmonizer/Core/CLI.c
----------------------------------------------------------------------
diff --git a/src/Charmonizer/Core/CLI.c b/src/Charmonizer/Core/CLI.c
index 4346ac3..1e8b5ed 100644
--- a/src/Charmonizer/Core/CLI.c
+++ b/src/Charmonizer/Core/CLI.c
@@ -354,6 +354,15 @@ chaz_CLI_parse(chaz_CLI *self, int argc, const char 
*argv[]) {
     }
 
     free(name);
+
+    for (i = 0; i < self->num_opts; i++) {
+        chaz_CLIOption *opt = &self->opts[i];
+        if (!opt->defined && (opt->flags & CHAZ_CLI_ARG_REQUIRED)) {
+            S_chaz_CLI_error(self, "Option '%s' is required", opt->name);
+            return 0;
+        }
+    }
+
     return 1;
 }
 

Reply via email to