summaryrefslogtreecommitdiff
path: root/argparse/src/action.rs
diff options
context:
space:
mode:
Diffstat (limited to 'argparse/src/action.rs')
-rw-r--r--argparse/src/action.rs33
1 files changed, 33 insertions, 0 deletions
diff --git a/argparse/src/action.rs b/argparse/src/action.rs
new file mode 100644
index 0000000..c3a0aff
--- /dev/null
+++ b/argparse/src/action.rs
@@ -0,0 +1,33 @@
+use std::cell::RefCell;
+use std::rc::Rc;
+
+pub enum ParseResult {
+ Parsed,
+ Help,
+ Exit,
+ Error(String),
+}
+
+
+pub enum Action<'a> {
+ Flag(Box<IFlagAction + 'a>),
+ Single(Box<IArgAction + 'a>),
+ Push(Box<IArgsAction + 'a>),
+ Many(Box<IArgsAction + 'a>),
+}
+
+pub trait TypedAction<T> {
+ fn bind<'x>(&self, Rc<RefCell<&'x mut T>>) -> Action<'x>;
+}
+
+pub trait IFlagAction {
+ fn parse_flag(&self) -> ParseResult;
+}
+
+pub trait IArgAction {
+ fn parse_arg(&self, arg: &str) -> ParseResult;
+}
+
+pub trait IArgsAction {
+ fn parse_args(&self, args: &[&str]) -> ParseResult;
+}