-
Notifications
You must be signed in to change notification settings - Fork 34
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
sidecar: migrate from clap 2 to clap 4 #83
Conversation
Use "derive" features of clap 4 to declare and parse addr2line command line arguments. Link: https://docs.rs/clap/latest/clap/_derive/_tutorial/index.html Link: https://simoncw.com/posts/learning-rust-from-clap2-2-clap4/ Signed-off-by: Ihor Solodrai <ihor.solodrai@pm.me>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Haven't tested it or anything, but overall this conversion seems reasonable to me. Thanks! Left a few suggestions for improvement. Let me know what you think.
sidecar/src/main.rs
Outdated
|
||
#[arg(short = 'C', long = "demangle", | ||
help = "Demangle function names. \ | ||
Specifying a specific demangling style (like GNU addr2line)is not supported.")] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Specifying a specific demangling style (like GNU addr2line)is not supported.")] | |
Specifying a specific demangling style (like GNU addr2line) is not supported.")] |
sidecar/src/main.rs
Outdated
} | ||
} | ||
#[arg(short = 'p', long = "pretty-print", | ||
help = "Make the output more human friendly: each location are printed on one line.")] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
help = "Make the output more human friendly: each location are printed on one line.")] | |
help = "Make the output more human friendly: each location is printed on one line.")] |
sidecar/src/main.rs
Outdated
} | ||
#[arg(short = 'p', long = "pretty-print", | ||
help = "Make the output more human friendly: each location are printed on one line.")] | ||
pretty: bool, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Indentation seems off.
sidecar/src/main.rs
Outdated
@@ -38,7 +38,7 @@ fn parse_query_line(string: &str) -> QueryType { | |||
} | |||
|
|||
enum Addrs<'a> { | |||
Args(Values<'a>), | |||
Args(std::vec::IntoIter<String>), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This replacement doesn't seem particularly elegant to me. Now you are forced to take
from config
below, which is error prone, because subsequent code may expect the addresses to be still available. In my opinion the following would be better:
--- src/main.rs
+++ src/main.rs
@@ -38,7 +38,7 @@ fn parse_query_line(string: &str) -> QueryType {
}
enum Addrs<'a> {
- Args(std::vec::IntoIter<String>),
+ Args(&'a mut dyn Iterator<Item = &'a str>),
Stdin(Lines<StdinLock<'a>>),
}
@@ -432,11 +430,13 @@ fn main() {
let dwarf = Arc::new(dwarf);
let ctx = Context::from_arc_dwarf(Arc::clone(&dwarf)).unwrap();
+ let mut addrs;
let stdin = std::io::stdin();
let queries = if config.addrs.is_empty() {
Addrs::Stdin(stdin.lock().lines())
} else {
- Addrs::Args(take(&mut config.addrs).into_iter())
+ addrs = config.addrs.iter().map(String::as_ref);
+ Addrs::Args(&mut addrs)
};
for addr_or_cunit in queries {
sidecar/src/main.rs
Outdated
|
||
let config = Config::load(&matches); | ||
let path = matches.value_of("exe").unwrap(); | ||
let path = take(&mut config.exe); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This seems unnecessary. Just pass &config.exe
to File::open
?
Signed-off-by: Ihor Solodrai <ihor.solodrai@pm.me>
@d-e-s-o Thank you for review. I am a newbie at Rust, so your suggestions are greatly appreciated, thanks! |
Use "derive" features of clap 4 to declare and parse addr2line command line arguments.
Resolves: #77
Link: https://docs.rs/clap/latest/clap/_derive/_tutorial/index.html
Link: https://simoncw.com/posts/learning-rust-from-clap2-2-clap4/