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

echo from scratch #32

Closed
wants to merge 5 commits into from
Closed

Conversation

playerdefault
Copy link

Recreated echo from scratch in Rust. Not feature complete but current PR is for a working MVP. Eventual goal is feature parity with busybox's echo.

@playerdefault
Copy link
Author

My first time ever creating a pull request on an open source project. Not a 100% sure about the contributing and code parity guidelines.

@samuela
Copy link
Owner

samuela commented Jun 19, 2020

Hi @playerdefault, thanks for submitting this! Congrats on your first PR! I'd be happy to merge this as soon it code reviews and passes the test suite.

fn stpcpy(_: *mut libc::c_char, _: *const libc::c_char) -> *mut libc::c_char;
pub fn echo_main() {
let mut output = String::new();
let args: Vec<String> = env::args().collect();
Copy link
Owner

Choose a reason for hiding this comment

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

Instead of doing this manual args parsing, we should probably use SafeStyle instead. Here's an example: https://github.com/samuela/rustybox/blob/master/applets/applet_tables.rs#L2782 and https://github.com/samuela/rustybox/blob/master/coreutils/true.rs.

Copy link
Owner

Choose a reason for hiding this comment

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

There are also a few different args parsing libraries in rust. Thus far rustybox hasn't really settled on one, but we should probably pick one here and stick with it.

Copy link
Author

Choose a reason for hiding this comment

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

@samuela Regarding the question of which argument parser to go with, clap's author has given some suggestions in this Reddit comment: https://www.reddit.com/r/rust/comments/8i5k3l/looking_for_a_tiniest_args_parser/dyp8l13?utm_source=share&utm_medium=web2x. Clap also looks like a good, reliable, and wildly popular choice to go with.

Copy link
Owner

Choose a reason for hiding this comment

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

I've used getopts before, and it seems to be the de facto choice for simple arg parsing, so I say we go with that. clap is a great framework, but it is fairly heavyweight. Clap weighs in at a surprising 202kb, whereas getopts is only 18kb.

Choose a reason for hiding this comment

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

FYI getopts only works for UTF-8 strings, so you can’t process non-UTF-8 filenames with it. It looks like SafeStyle only accepts &str arguments though anyway.

Copy link
Author

Choose a reason for hiding this comment

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

@samuela Just saw the updates on the thread. I am stuck somewhere, plus, I have some questions about the build and test parts of the project that would not be suitable to ask here. Do you have a way I could contact separately like a Slack channel, Microsoft Teams channel, email thread or something else?

Copy link
Owner

Choose a reason for hiding this comment

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

Sure, you can contact me over email at the email listed in my github account, and I'd be happy to answer any questions

Copy link
Author

Choose a reason for hiding this comment

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

Hey @samuela sent you an email! Could you find some time to look at it? Since it's not from Gmail, it might be in your spam.

Copy link

@joshuarli joshuarli Jul 3, 2020

Choose a reason for hiding this comment

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

rust-lang/getopts#97 (comment)

argh is quite small, and there's some traction there to support non-utf8. edit: sorry, meant to link to google/argh#33

There's also pico-args, which to my knowledge is the smallest out there (see comparisons). And it also supports non-utf8. Main downside being the help text isn't autogenerated.

Related discussion here.

Copy link
Owner

Choose a reason for hiding this comment

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

Thanks for the pointers @joshuarli ! I wasn't aware of the argh project. That may be a suitable alternative.

@samuela
Copy link
Owner

samuela commented Jun 21, 2020

Looks like this is moving along nicely! Feel free to ping me once CI passes and you're ready for a code review!

@playerdefault playerdefault marked this pull request as draft July 4, 2020 11:37
@playerdefault
Copy link
Author

playerdefault commented Jun 14, 2023

Stumbed upon my PR from 3 years ago. Never thought I'll be here where I am today when I originally started working on this. Closing this PR for completeness and adding my code to the GitHub void forever.

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.

None yet

4 participants