Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

update commander

  • Loading branch information...
commit 1fd1a8ff2a1fea911e5eabf9a9c0a3a9554b5f1a 1 parent be2836a
TJ Holowaychuk authored
Showing with 24 additions and 1 deletion.
  1. +20 −0 deps/commander.c
  2. +4 −1 deps/commander.h
20 deps/commander.c
View
@@ -70,6 +70,26 @@ command_init(command_t *self, const char *name, const char *version) {
}
/*
+ * Free up commander after use.
+ */
+
+void
+command_free(command_t *self) {
+ for (int i = 0; i < self->option_count; ++i) {
+ command_option_t *option = &self->options[i];
+ free(option->argname);
+ free(option->large);
+ }
+
+ if (self->nargv) {
+ for (int i = 0; self->nargv[i]; ++i) {
+ free(self->nargv[i]);
+ }
+ free(self->nargv);
+ }
+}
+
+/*
* Parse argname from `str`. For example
* Take "--required <arg>" and populate `flag`
* with "--required" and `arg` with "<arg>".
5 deps/commander.h
View
@@ -74,6 +74,9 @@ void
command_init(command_t *self, const char *name, const char *version);
void
+command_free(command_t *self);
+
+void
command_help(command_t *self);
void
@@ -82,4 +85,4 @@ command_option(command_t *self, const char *small, const char *large, const char
void
command_parse(command_t *self, int argc, char **argv);
-#endif /* COMMANDER_H */
+#endif /* COMMANDER_H */
Please sign in to comment.
Something went wrong with that request. Please try again.