Skip to content

Conversation

@snoopdougiedougie
Copy link

The original code would always print "Unknown program name!".

The original code would always print "Unknown program name!".
@snoopdougiedougie
Copy link
Author

Note that this allows multiple commands, and prints the message for each. So you can run:

cargo run rm mv

@mgeisler
Copy link
Collaborator

mgeisler commented Jan 4, 2023

Hi @snoopdougiedougie, thanks for spotting this.

The original code would always print "Unknown program name!".

Yeah, I think I didn't pick a super good example to be honest. Perhaps we can rework it to something which lends itself better to an interactive class.

When teaching the class, I live code using the code on the slides (pages). Here it would be great to have a code snippet which both

  1. Is easy to modify in front of a class (std::env::args() is not easy to modify in a playground environment 🙂)
  2. Shows off the expression part. That is, I would like to assign the value of match to something.

Perhaps we can stay in the same theme and hard-code the arguments. We could then use match to determine the expected number of arguments... A problem with this is that all of these classical Unix programs take one or more arguments.

Perhaps we can find a better program name to match against — perhaps we say that we're reimplementing git instead and want to match its subcommands?

@snoopdougiedougie
Copy link
Author

Yeah, it's hard to find a good example for a class. You want something "real-world", but not too difficult. The problem with parsing the command line to show how match works isn't how you usually accept command-line options in Rust--you usually use Clap.

@mgeisler
Copy link
Collaborator

mgeisler commented Jan 4, 2023

works isn't how you usually accept command-line options in Rust--you usually use Clap.

True 😄 but I hope the students who take the class will forgive us for this. It would be cool to explain how to actually do it in a speaker note — I've just put up #107 which should help with that.

@KunleWire8148
Copy link

KunleWire8148 commented Jan 4, 2023 via email

Copy link
Collaborator

@mgeisler mgeisler left a comment

Choose a reason for hiding this comment

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

Please update it to use a fixed vector instead — make pattern matching the focus, not command line shenanigans 😄

The call to as_deref is also something which raises questions every time I teach the class. We can either leave it and explain what it does in a note, or we can rework the example to make it unnecessary.

@mgeisler
Copy link
Collaborator

mgeisler commented Jan 6, 2023

Please update it to use a fixed vector instead — make pattern matching the focus, not command line shenanigans smile

I'm of course also fine doing this myself, just let me know. We can close this PR and I'll put something else up eventually.

@mgeisler
Copy link
Collaborator

Let's close this for now — I think the example should be rewritten to not use the arguments at all since that's just extra noise.

@mgeisler mgeisler closed this Jan 27, 2023
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.

3 participants