Skip to content

Commit c153293

Browse files
committed
add arg to disable empty line with mutt-query
1 parent 41f26bc commit c153293

File tree

4 files changed

+27
-22
lines changed

4 files changed

+27
-22
lines changed

Cargo.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
[package]
22
name = "mates"
3-
version = "0.3.0"
4-
authors = ["Markus Unterwaditzer <[email protected]>"]
3+
version = "1.0.0"
4+
authors = ["Markus Unterwaditzer <[email protected]>", "Shaleen Jain <[email protected]>"]
55
license = "MIT"
66
keywords = ["vdir", "vcard", "contacts", "addressbook"]
77
readme = "README.md"

src/cli.rs

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -112,9 +112,13 @@ pub fn edit_contact(config: &Configuration, query: &str) -> Result<()> {
112112
Ok(())
113113
}
114114

115-
pub fn mutt_query<'a>(config: &Configuration, query: &str) -> Result<()> {
116-
println!(""); // For some reason mutt requires an empty line
117-
// We need to ignore errors here, otherwise mutt's UI will glitch
115+
pub fn mutt_query(config: &Configuration, disable_first_line: bool, query: &str) -> Result<()> {
116+
// For some reason mutt requires an empty line
117+
// We need to ignore errors here, otherwise mutt's UI will glitch
118+
if !disable_first_line {
119+
println!();
120+
}
121+
118122
if let Ok(items) = utils::index_query(config, query) {
119123
for item in items {
120124
if item.email.len() > 0 && item.name.len() > 0 {
@@ -125,14 +129,14 @@ pub fn mutt_query<'a>(config: &Configuration, query: &str) -> Result<()> {
125129
Ok(())
126130
}
127131

128-
pub fn file_query<'a>(config: &Configuration, query: &str) -> Result<()> {
132+
pub fn file_query(config: &Configuration, query: &str) -> Result<()> {
129133
for path in utils::file_query(config, query)?.iter() {
130134
println!("{}", path.display());
131135
}
132136
Ok(())
133137
}
134138

135-
pub fn email_query<'a>(config: &Configuration, query: &str) -> Result<()> {
139+
pub fn email_query(config: &Configuration, query: &str) -> Result<()> {
136140
for item in utils::index_query(config, query)? {
137141
if item.name.len() > 0 && item.email.len() > 0 {
138142
println!("{} <{}>", item.name, item.email);

src/main.rs

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -19,17 +19,18 @@ fn main() -> Result<()> {
1919
.subcommand(
2020
SubCommand::with_name("mutt-query")
2121
.about("Search for contact, output is usable for mutt's query_command.")
22-
.arg(Arg::with_name("query").index(1)),
22+
.arg(Arg::with_name("disable-empty-line").long("disable-empty-line").help("Disable printing an empty first line"))
23+
.arg(Arg::with_name("query").required(true)),
2324
)
2425
.subcommand(
2526
SubCommand::with_name("file-query")
2627
.about("Search for contact, return just the filename.")
27-
.arg(Arg::with_name("query").index(1)),
28+
.arg(Arg::with_name("query").required(true)),
2829
)
2930
.subcommand(
3031
SubCommand::with_name("email-query")
3132
.about("Search for contact, return \"name <email>\".")
32-
.arg(Arg::with_name("query").index(1)),
33+
.arg(Arg::with_name("query").required(true)),
3334
)
3435
.subcommand(
3536
SubCommand::with_name("add")
@@ -38,7 +39,7 @@ fn main() -> Result<()> {
3839
.subcommand(
3940
SubCommand::with_name("edit")
4041
.about("Open contact (given by filepath or search-string) interactively.")
41-
.arg(Arg::with_name("file-or-query").index(1)),
42+
.arg(Arg::with_name("file-or-query").required(true)),
4243
)
4344
.get_matches();
4445

@@ -50,25 +51,25 @@ fn main() -> Result<()> {
5051
};
5152

5253
match app.subcommand() {
53-
("index", Some(_subs)) => {
54+
("index", Some(_args)) => {
5455
println!(
5556
"Rebuilding index file \"{}\"...",
5657
config.index_path.display()
5758
);
5859
cli::build_index(&config.index_path, &config.vdir_path)?;
5960
}
60-
("mutt-query", Some(subs)) => {
61-
if let Some(value) = subs.value_of("query") {
62-
cli::mutt_query(&config, value)?
61+
("mutt-query", Some(args)) => {
62+
if let Some(value) = args.value_of("query") {
63+
cli::mutt_query(&config, args.is_present("disable-empty-line"), value)?
6364
}
6465
}
65-
("file-query", Some(subs)) => {
66-
if let Some(value) = subs.value_of("query") {
66+
("file-query", Some(args)) => {
67+
if let Some(value) = args.value_of("query") {
6768
cli::file_query(&config, value)?
6869
}
6970
}
70-
("email-query", Some(subs)) => {
71-
if let Some(value) = subs.value_of("query") {
71+
("email-query", Some(args)) => {
72+
if let Some(value) = args.value_of("query") {
7273
cli::email_query(&config, value)?
7374
}
7475
}
@@ -87,8 +88,8 @@ fn main() -> Result<()> {
8788
let index_entry = utils::index_item_from_contact(&contact)?;
8889
index_fp.write_all(index_entry.as_bytes())?;
8990
}
90-
("edit", Some(subs)) => {
91-
if let Some(value) = subs.value_of("file-or-query") {
91+
("edit", Some(args)) => {
92+
if let Some(value) = args.value_of("file-or-query") {
9293
cli::edit_contact(&config, value)?
9394
}
9495
}

0 commit comments

Comments
 (0)