Skip to content

Commit

Permalink
Merge pull request #3 from expobrain/linter
Browse files Browse the repository at this point in the history
Fixed linter warnings
  • Loading branch information
phsym authored Aug 9, 2018
2 parents 0424647 + efff62f commit 9146ba5
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 25 deletions.
4 changes: 2 additions & 2 deletions examples/map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ fn main() {
map.insert(try!(usize::from_str(args[0])), args[1].to_string());
Ok(())
});
shell.new_command("get", "Get a value", 1, |mut io, map, args| {
shell.new_command("get", "Get a value", 1, |io, map, args| {
match map.get(&try!(usize::from_str(args[0]))) {
Some(val) => writeln!(io, "{}", val).unwrap(),
None => writeln!(io, "Not found").unwrap()
Expand All @@ -24,7 +24,7 @@ fn main() {
map.remove(&try!(usize::from_str(args[0])));
Ok(())
});
shell.new_command("list", "List all values", 0, |mut io, map, _| {
shell.new_command("list", "List all values", 0, |io, map, _| {
for (k, v) in map {
writeln!(io, "{} = {}", k, v).unwrap();
}
Expand Down
6 changes: 3 additions & 3 deletions examples/socket.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@ fn main() {

let mut shell = Shell::new(map);

shell.new_command("put", "Insert a value", 2, |_, map, args| {
shell.new_command(&"put", &"Insert a value", 2, |_, map, args| {
map.lock().unwrap().insert(try!(usize::from_str(args[0])), args[1].to_string());
Ok(())
});
shell.new_command("get", "Get a value", 1, |mut io, map, args| {
shell.new_command("get", "Get a value", 1, |io, map, args| {
match map.lock().unwrap().get(&try!(usize::from_str(args[0]))) {
Some(val) => writeln!(io, "{}", val).unwrap(),
None => writeln!(io, "Not found").unwrap()
Expand All @@ -30,7 +30,7 @@ fn main() {
map.lock().unwrap().remove(&try!(usize::from_str(args[0])));
Ok(())
});
shell.new_command("list", "List all values", 0, |mut io, map, _| {
shell.new_command("list", "List all values", 0, |io, map, _| {
for (k, v) in &*map.lock().unwrap() {
writeln!(io, "{} = {}", k, v).unwrap();
}
Expand Down
40 changes: 20 additions & 20 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,13 @@ use ExecError::*;

impl fmt::Display for ExecError {
fn fmt(&self, format: &mut fmt::Formatter) -> fmt::Result {
return match self {
&Empty => write!(format, "No command provided"),
&Quit => write!(format, "Quit"),
&UnknownCommand(ref cmd) => write!(format, "Unknown Command {}", cmd),
&InvalidHistory(i) => write!(format, "Invalid history entry {}", i),
&MissingArgs => write!(format, "Not enough arguments"),
&Other(ref e) => write!(format, "{}", e)
return match *self {
Empty => write!(format, "No command provided"),
Quit => write!(format, "Quit"),
UnknownCommand(ref cmd) => write!(format, "Unknown Command {}", cmd),
InvalidHistory(i) => write!(format, "Invalid history entry {}", i),
MissingArgs => write!(format, "Not enough arguments"),
Other(ref e) => write!(format, "{}", e)
};
}
}
Expand Down Expand Up @@ -133,7 +133,7 @@ impl <T> Shell<T> {
let mut sh = Shell {
commands: BTreeMap::new(),
default: Arc::new(|_, _, cmd| Err(UnknownCommand(cmd.to_string()))),
data: data,
data,
prompt: String::from(">"),
unclosed_prompt: String::from(">"),
history: History::new(10),
Expand Down Expand Up @@ -199,7 +199,7 @@ impl <T> Shell<T> {
for cmd in self.commands.values() {
table.add_row(cmd.help());
}
return table.print(io).map_err(|e| From::from(e))
return table.print(io).map_err(From::from)
}

/// Return the command history
Expand All @@ -212,7 +212,7 @@ impl <T> Shell<T> {
let mut splt = line.trim().split_whitespace();
return match splt.next() {
None => Err(Empty),
Some(cmd) => match self.commands.get(cmd).map(|i| i.clone()) {
Some(cmd) => match self.commands.get(cmd).cloned() {
None => self.default.clone()(io, self, line),
Some(c) => c.run(io, self, &splt.collect::<Vec<&str>>())
}
Expand All @@ -235,7 +235,7 @@ impl <T> Shell<T> {
let stdin = io::BufReader::new(io.clone());
let mut iter = stdin.lines().map(|l| l.unwrap());
while let Some(mut line) = iter.next() {
while line.len() > 0 && &line[line.len()-1 ..] == "\\" {
while !line.is_empty() && &line[line.len()-1 ..] == "\\" {
self.print_prompt(io, true);
line.pop();
line.push_str(&iter.next().unwrap())
Expand All @@ -244,7 +244,7 @@ impl <T> Shell<T> {
match e {
Empty => {},
Quit => return,
e @ _ => writeln!(io, "Error : {}", e).unwrap()
e => writeln!(io, "Error : {}", e).unwrap()
};
} else {
self.get_history().push(line);
Expand Down Expand Up @@ -294,7 +294,7 @@ impl History {
fn new(capacity: usize) -> History {
return History {
history: Arc::new(Mutex::new(Vec::with_capacity(capacity))),
capacity: capacity
capacity
};
}

Expand All @@ -319,7 +319,7 @@ impl History {

/// Get a command from history by its index
pub fn get(&self, i: usize) -> Option<String> {
return self.history.lock().unwrap().get(i).map(|s| s.clone());
return self.history.lock().unwrap().get(i).cloned();
}
}

Expand All @@ -340,10 +340,10 @@ mod builtins {
impl <T> Command<T> {
pub fn new(name: String, description: String, nargs: usize, func: CmdFn<T>) -> Command<T> {
return Command {
name: name,
description: description,
nargs: nargs,
func: func
name,
description,
nargs,
func
};
}

Expand All @@ -369,9 +369,9 @@ mod builtins {

pub fn history_cmd<T>() -> Command<T> {
return Command::new("history".to_string(), "Print commands history or run a command from it".to_string(), 0, Box::new(|io, shell, args| {
if args.len() > 0 {
if !args.is_empty() {
let i = try!(usize::from_str(args[0]));
let cmd = try!(shell.get_history().get(i).ok_or(ExecError::InvalidHistory(i)));
let cmd = try!(shell.get_history().get(i).ok_or_else(|| ExecError::InvalidHistory(i)));
return shell.eval(io, &cmd);
} else {
shell.get_history().print(io);
Expand Down

0 comments on commit 9146ba5

Please sign in to comment.