Skip to content

Commit

Permalink
v0.4.1
Browse files Browse the repository at this point in the history
  • Loading branch information
ksk001100 committed Feb 15, 2020
1 parent 555c557 commit a1af6a0
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 6 deletions.
3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
[package]
name = "seahorse"
version = "0.4.0"
version = "0.4.1"
authors = ["ksk001100 <[email protected]>"]
edition = "2018"
keywords = ["cli"]
repository = "https://github.com/ksk001100/seahorse"
readme = "README.md"
license-file = "LICENSE"
description = "A minimal CLI framework written in Rust"
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ A minimal CLI framework written in Rust

```toml
[dependencies]
seahorse = "0.4.0"
seahorse = "0.4.1"
```

## Example
Expand Down
2 changes: 1 addition & 1 deletion example/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use std::env;
use seahorse::{App, Action, Command, color, Flag, FlagType, Context};
use seahorse::{App, Command, color, Flag, FlagType, Context};

fn main() {
let args: Vec<String> = env::args().collect();
Expand Down
12 changes: 10 additions & 2 deletions src/context.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::{Flag, FlagValue};
use crate::{Flag, FlagValue, FlagType};

pub struct Context {
pub args: Vec<String>,
Expand All @@ -8,17 +8,25 @@ pub struct Context {
impl Context {
pub fn new(args: Vec<String>, flags: Option<Vec<Flag>>) -> Self {
let mut v = Vec::new();
let mut parsed_args = args.clone();
let flags_val = match flags {
Some(flags) => {
for flag in flags {
if parsed_args.contains(&format!("--{}", flag.name)) {
let index = parsed_args.iter().position(|arg| *arg == format!("--{}", flag.name)).unwrap();
parsed_args.remove(index);
if flag.flag_type != FlagType::Bool {
parsed_args.remove(index);
}
}
v.push((flag.name.to_string(), flag.value(args.clone())))
}
Some(v)
}
None => None
};

Self { args, flags: flags_val }
Self { args: parsed_args, flags: flags_val }
}

fn option_flag_value(&self, name: &str) -> Option<&FlagValue> {
Expand Down
2 changes: 1 addition & 1 deletion src/flag.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ pub struct Flag {
pub flag_type: FlagType,
}

#[derive(Clone)]
#[derive(PartialOrd, PartialEq, Clone)]
pub enum FlagType {
Bool,
String,
Expand Down

0 comments on commit a1af6a0

Please sign in to comment.