Minor refactoring.
This commit is contained in:
parent
2b0374d45b
commit
8e77725334
3 changed files with 35 additions and 40 deletions
|
@ -114,7 +114,7 @@ impl Cradle {
|
||||||
|
|
||||||
// Parse command line argument to --command into a vector of strings suitable
|
// Parse command line argument to --command into a vector of strings suitable
|
||||||
// for process::Command::new().
|
// for process::Command::new().
|
||||||
pub fn parse(input: &str) -> Vec<String> {
|
pub fn parse(input: String) -> Vec<String> {
|
||||||
let mut command: Vec<String> = Vec::new();
|
let mut command: Vec<String> = Vec::new();
|
||||||
let mut segment: String = String::new();
|
let mut segment: String = String::new();
|
||||||
let mut quoted = false;
|
let mut quoted = false;
|
||||||
|
|
72
src/lib.rs
72
src/lib.rs
|
@ -17,6 +17,7 @@
|
||||||
|
|
||||||
extern crate signal_hook;
|
extern crate signal_hook;
|
||||||
extern crate termion;
|
extern crate termion;
|
||||||
|
extern crate unicode_segmentation;
|
||||||
mod alarm;
|
mod alarm;
|
||||||
mod buffer;
|
mod buffer;
|
||||||
mod clock;
|
mod clock;
|
||||||
|
@ -362,46 +363,41 @@ impl Config {
|
||||||
};
|
};
|
||||||
let mut iter = args.skip(1);
|
let mut iter = args.skip(1);
|
||||||
|
|
||||||
loop {
|
while let Some(arg) = iter.next() {
|
||||||
if let Some(arg) = iter.next() {
|
match arg.as_str() {
|
||||||
match arg.as_str() {
|
"-h" | "--help" => {
|
||||||
"-h" | "--help" => {
|
// Print usage information and exit
|
||||||
// Print usage information and exit
|
println!("{}", USAGE);
|
||||||
println!("{}", USAGE);
|
process::exit(0);
|
||||||
process::exit(0);
|
}
|
||||||
}
|
"-v" | "--version" => {
|
||||||
"-v" | "--version" => {
|
println!("{} {}", NAME, VERSION);
|
||||||
println!("{} {}", NAME, VERSION);
|
process::exit(0);
|
||||||
process::exit(0);
|
}
|
||||||
}
|
"-p" | "--plain" => config.font = &font::PLAIN,
|
||||||
"-p" | "--plain" => config.font = &font::PLAIN,
|
"-f" | "--fancy" => {
|
||||||
"-f" | "--fancy" => {
|
config.fancy = true;
|
||||||
config.fancy = true;
|
config.font = &font::CHROME;
|
||||||
config.font = &font::CHROME;
|
}
|
||||||
}
|
"-q" | "--quit" => config.quit = true,
|
||||||
"-q" | "--quit" => config.quit = true,
|
"-e" | "--exec" => {
|
||||||
"-e" | "--exec" => {
|
if let Some(cmd) = iter.next() {
|
||||||
if let Some(cmd) = iter.next() {
|
config.commands.add(Cradle::parse(cmd));
|
||||||
//config.command = Some(Config::parse_to_command(&e));
|
} else {
|
||||||
config.commands.add(Cradle::parse(&cmd));
|
return Err(format!("Missing parameter to \"{}\".", arg));
|
||||||
} else {
|
|
||||||
return Err(format!("Missing parameter to \"{}\".", arg));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
any if any.starts_with('-') => {
|
|
||||||
// Unrecognized flag.
|
|
||||||
return Err(format!("Unrecognized option: \"{}\"\nUse \"-h\" or \"--help\" for a list of valid command line options.", any));
|
|
||||||
}
|
|
||||||
any => {
|
|
||||||
// Alarm to add.
|
|
||||||
if let Err(error) = alarm_roster.add(&String::from(any)) {
|
|
||||||
return Err(format!("Error adding \"{}\" as alarm. ({})", any, error));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
any if any.starts_with('-') => {
|
||||||
break;
|
// Unrecognized flag.
|
||||||
} // All command line parameters processed.
|
return Err(format!("Unrecognized option: \"{}\"\nUse \"-h\" or \"--help\" for a list of valid command line options.", any));
|
||||||
|
}
|
||||||
|
any => {
|
||||||
|
// Alarm to add.
|
||||||
|
if let Err(error) = alarm_roster.add(&String::from(any)) {
|
||||||
|
return Err(format!("Error adding \"{}\" as alarm. ({})", any, error));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Ok(config)
|
Ok(config)
|
||||||
}
|
}
|
||||||
|
|
|
@ -15,7 +15,6 @@
|
||||||
// You should have received a copy of the GNU General Public License
|
// You should have received a copy of the GNU General Public License
|
||||||
// along with Kitchentimer. If not, see <https://www.gnu.org/licenses/>.
|
// along with Kitchentimer. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
extern crate unicode_segmentation;
|
|
||||||
use unicode_segmentation::UnicodeSegmentation;
|
use unicode_segmentation::UnicodeSegmentation;
|
||||||
|
|
||||||
pub fn grapheme_truncate(input: &mut String, limit: usize, ellipse: char) {
|
pub fn grapheme_truncate(input: &mut String, limit: usize, ellipse: char) {
|
||||||
|
|
Loading…
Reference in a new issue