From 048c97adcedab552e8c5b33567a06de4cb5c0f81 Mon Sep 17 00:00:00 2001 From: Robin Krahl Date: Tue, 18 Dec 2018 00:39:24 +0100 Subject: Port argument handling to argparse This patch replaces the macro for argument parsing with `argparse::ArgumentParser` from the argparse crate. It moves the application logic to the `commands` module and the argument parsing to the `options` module. An enum is used to represent the available commands. The code is based on the `subcommands.rs` example shipped with argparse. --- nitrocli/src/error.rs | 2 ++ 1 file changed, 2 insertions(+) (limited to 'nitrocli/src/error.rs') diff --git a/nitrocli/src/error.rs b/nitrocli/src/error.rs index d755cac..d86a635 100644 --- a/nitrocli/src/error.rs +++ b/nitrocli/src/error.rs @@ -23,6 +23,7 @@ use std::string; #[derive(Debug)] pub enum Error { + ArgparseError(i32), IoError(io::Error), Utf8Error(string::FromUtf8Error), Error(String), @@ -43,6 +44,7 @@ impl From for Error { impl fmt::Display for Error { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { match *self { + Error::ArgparseError(_) => write!(f, "Could not parse arguments"), Error::Utf8Error(_) => write!(f, "Encountered UTF-8 conversion error"), Error::IoError(ref e) => write!(f, "IO error: {}", e.get_ref().unwrap()), Error::Error(ref e) => write!(f, "{}", e), -- cgit v1.2.1