-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
Add chapter on commandline arguments #76
Conversation
fn main() { | ||
let args = os::args(); | ||
println!("My path is {}.", args.get(0)); | ||
println!("My arguments are {}.", args.slice(1, args.len())); |
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.
I believe we could use tail()
instead.
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.
I didn't know about tail
, thanks!
(I'm surprised that this is in the standard library, seems very specialized to me. Do you know whether it was ever considered to add something more generic like Python's slicing syntax?)
Thanks for sending a PR! This is a very succinct chapter :P. I would like to see more things (if you have the time, otherwise I can take over):
(^ that should be a second example)
|
Thanks for the feedback! I made some according changes. The second example became a bit long. I accidentally committed changes to |
I think we should put this on hold, until #80 is finished. After that lands, we should split this chapter like this:
(name subject to changes) What do you think about the split? We could leave the |
I think the split makes sense. More structure is good. 2014-06-07 12:12 GMT-04:00 Jorge Aparicio notifications@github.com:
|
This needs a rebase EDIT: I just had an idea, maybe we can make a "CLI" chapter, and include "args" as a subchapter, and the subchapters could be: "exit code", "stdin", "stdout" and "stderr". What do you think? |
cc #106 |
Rebased and split into subchapters. I added an implementation of There seems to be an issue with the syntax highlighting of the last example. Also it breaks the playpen, probably because it uses I would love to have some input on the second example, I'm not very happy with it yet. @japaric I agree about the CLI chapter, especially since my last example ( |
@@ -0,0 +1,71 @@ | |||
/* | |||
* For the full copyright and license information, please view the LICENSE |
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 would look odd, because none of the other examples include a header comment. Maybe we can add a note after the example to indicate that this example is based on coreutils's echo code.
Sorry for procrastinating this for so long :-(.
Yes, this is related to issue #2. This problem doesn't happen with the live code editor.
Your original program works fine in the playpen.
Except for the code style issues, I think the coverage of features is good. Does something else bother you?
We can merge this as a chapter for now, and later move it into the CLI chapter as a subchapter. |
@japaric I think I addressed all of your comments.
I think the coverage is fine, I'm just not a big fan of the silly example, but I don't have a better idea so far. Currently there is a very strange bug, where the getopts chapter shows up as a subchapter of the random chapter. |
@@ -0,0 +1,64 @@ | |||
extern crate getopts; | |||
extern crate libc; |
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.
We don't need this anymore, right?
|
||
use std::os; | ||
use std::io::{print, println}; | ||
use std::io::stdio::flush; |
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.
The idiomatic way to use functions from other modules is to import the module use std::io::stdio
, and call the function using the path: stdio::flush()
.
Sorry, I have more comments :P
It just occurred to me (although it may be too late) that you could do use First example: just "connect" all the arguments, and print the result. No flag parsing. Of course, this is more work, and the current examples are already good.
You are right, I see the same thing. That's really weird! I'll have to investigate. |
This would be a nicer example but cover less:
2014-06-30 21:25 GMT-04:00 Jorge Aparicio notifications@github.com:
|
Oh well, at least I tried :P |
@vks Can
|
Yes, that'd be awesome. BTW, the weird bug ( |
I might add an example for optional options, but this will be in a separate pull request, because I need to think of a new example ( |
@japaric What's the status on this? Anything that still needs to be addressed? |
@vks in general, I am interested in adding a chapter like this, but this PR is very old. Do you have any interest in modernizing it? If so, let's get it finally shipped. |
@steveklabnik I will rebase and update the code. |
@steveklabnik This should work with a current version of Rust now. I think japaric reviewed everything except for the |
I think that overall this looks great, but I'm loathe to add another license. If we address that and squash this up, r=me :) |
I'll ask the uutils maintainers just to be sure. Do you want me to squash On Wed Dec 10 2014 at 2:10:23 PM Steve Klabnik notifications@github.com
|
Yes please. |
This is out of date already O_O |
Should be fixed now. (The conflict was a good thing, because I forgot to remove the special mention of the license from the readme.) Regarding the license, we got green light by Seldaek, who is the copyright holder in uutils' license. |
Add chapter on commandline arguments
Thank you! |
Please let me know if you think the example should be more verbose.