Skip to content
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

Merged
merged 2 commits into from
Oct 8, 2024
Merged

Conversation

theihor
Copy link
Contributor

@theihor theihor commented Oct 7, 2024

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/

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>
Copy link
Contributor

@d-e-s-o d-e-s-o left a 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.


#[arg(short = 'C', long = "demangle",
help = "Demangle function names. \
Specifying a specific demangling style (like GNU addr2line)is not supported.")]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Specifying a specific demangling style (like GNU addr2line)is not supported.")]
Specifying a specific demangling style (like GNU addr2line) is not supported.")]

}
}
#[arg(short = 'p', long = "pretty-print",
help = "Make the output more human friendly: each location are printed on one line.")]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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.")]

}
#[arg(short = 'p', long = "pretty-print",
help = "Make the output more human friendly: each location are printed on one line.")]
pretty: bool,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indentation seems off.

@@ -38,7 +38,7 @@ fn parse_query_line(string: &str) -> QueryType {
}

enum Addrs<'a> {
Args(Values<'a>),
Args(std::vec::IntoIter<String>),
Copy link
Contributor

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 {


let config = Config::load(&matches);
let path = matches.value_of("exe").unwrap();
let path = take(&mut config.exe);
Copy link
Contributor

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>
@theihor
Copy link
Contributor Author

theihor commented Oct 7, 2024

@d-e-s-o Thank you for review. I am a newbie at Rust, so your suggestions are greatly appreciated, thanks!

@anakryiko anakryiko merged commit 16347f7 into anakryiko:master Oct 8, 2024
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

RFC: port from clap 2 to clap 4
3 participants