Тёмный

Parse Rust CLI Args With Clap 🦀 Rust Tutorial 

Trevor Sullivan
Подписаться 17 тыс.
Просмотров 12 тыс.
50% 1

If you want to build a CLI tool with Rust, but don't want to spend lots of time writing argument parsing code, reach for the "clap" crate, which will handle this for you! In this video, we'll take a look at the core functionality of the Clap crate, and how you can build your own tools using it!
🤯 Rust Programming Playlist 🦀 • Rust Programming Tutor...
📖 Clap Docs 📦➡️ docs.rs/clap/l...
Visual Studio Code ➡️ code.visualstu...
Rust Website ➡️ rust-lang.org
Rustup Installer ➡️ rustup.rs
Rust Docs ➡️ doc.rust-lang....
Please follow me on these other social channels!
➡️ trevorsullivan...
➡️ github.com/pcg...
➡️ / pcgeek86
➡️ / trevorsullivan
➡️ / trevorsoftware
➡️ tiktok.com/pcg...
All trademarks, logos and brand names are the property of their respective owners. All company, product and service names used in this website are for identification purposes only. Use of these names,trademarks and brands does not imply endorsement.
#rustlang #rust #rustdev #opensource #software #linux #devops #programming #rusty #dev #coding #codinglife #code #coder #ubuntu #ubuntulinux #appdev #developer

Опубликовано:

 

27 сен 2024

Поделиться:

Ссылка:

Скачать:

Готовим ссылку...

Добавить в:

Мой плейлист
Посмотреть позже
Комментарии : 48   
@ImranKhan-br5dv
@ImranKhan-br5dv 4 месяца назад
i have watched so many courses on rust but no one gives the refrence of the topic and explanation but you explain well , thanks you men
@sval4020
@sval4020 5 месяцев назад
I am just getting started with the clap crate and your video is very educative! Keep up the great work! Actually I very much like the approach you take in all of your videos where you basically walk us through the crate docs, then continue with a couple of examples and at the same time explaining and showing specific functions used in that crate. Then repeat all of this back and forth until you get your result - that is what real world programming is! Even in the AI era where people start to rely more and more on copilots for autocompletion without having a look at the docs, I firmly believe that if one wants to keep up with latest and greatest versions of most of the packages, he/she needs to have this fundamental skill. Thank you for being here for all of us, I am enjoying your style and videos a lot!
@TrevorSullivan
@TrevorSullivan 5 месяцев назад
Thanks so much for sharing your thoughts! I'm glad you're benefitting from these videos on Rust! Keep learning! 🦀🧠
@HELLOBOYZ-c6o
@HELLOBOYZ-c6o 9 месяцев назад
Awesome job, man! You helped me so much. God bless you my friend! You deserve much more recognition, keep going.
@harikeshranjansinha6939
@harikeshranjansinha6939 6 месяцев назад
This tutorial is really helpful. I was really having a hard time learning CLAP. You made it very easy. Thanks ❤❤
@stephennelson-smith3312
@stephennelson-smith3312 10 месяцев назад
Fantastic content, and I've enjoyed some of your other tutorials too. One thing: please don't be running as the "root" user and installing stuff as the "root" user. Even if this is a throw away VM only ever used for this exercise, it's very bad practice, and I wouldn't want any other viewers/subscribers to think this is an ok thing to do. It's not. Other than that grumble, this was just what I was looking for and you've earned another subscriber - thank you for all your work!
@_jdfx
@_jdfx 9 месяцев назад
Great stuff! one small thing though, the VS code type hints are really confusing in white.
@TrevorSullivan
@TrevorSullivan 9 месяцев назад
Agreed, that does look confusing. It's just indicating the closing line for a particular block. They should highlight that differently. Might be good feedback for the Rust Analyzer extension.
@Hellbending
@Hellbending 9 месяцев назад
It may be your theme that does it - you should be able to tweak it if you pull up the json for that specific theme and have a poke around (most colours are in groupings etc) and they’d be inlay hints or something along those lines. (I use them via rust and have turned them on for Python recently too with strict typings, they come up as a grey for me after some tweaking (a little lighter than commented code)
@aurelio_fernam
@aurelio_fernam 19 дней назад
Thank you very much!!!
@daque1960
@daque1960 Год назад
Thanks for the clap tutorial!
@marlonsbardelatti202
@marlonsbardelatti202 11 месяцев назад
is there a way to declare a flag for example: -s. Without needing to add some value to it? When i pass the -s in my program i just need to show all infos so i dont need a variable assigned there. I just can do it with -s show for example
@TrevorSullivan
@TrevorSullivan 11 месяцев назад
Great question, it looks like there is a way to do that. Check out this link stackoverflow.com/questions/60458705/how-do-i-specify-a-boolean-command-line-flag-using-clap
@marlonsbardelatti202
@marlonsbardelatti202 11 месяцев назад
@@TrevorSullivan ok thx man
@marlonsbardelatti202
@marlonsbardelatti202 11 месяцев назад
@@TrevorSullivan ok now it works, I was trying to use takes_value() which is no longer avaliable, using num_args(0) works fine
@slurpin-tw
@slurpin-tw 2 месяца назад
This video is useful.
@slamdunksammy
@slamdunksammy 9 месяцев назад
Seriously amazing tutorial!!
@Khl8122
@Khl8122 9 месяцев назад
Derive approach is the declarative way. Builder is imperative.
@piyushpatil6874
@piyushpatil6874 6 месяцев назад
Really enjoying your work 😊❤
@TrevorSullivan
@TrevorSullivan 6 месяцев назад
Thank you! ❤️ I'm glad you're learning Rust! 🦀
@IsaqueSbr
@IsaqueSbr 7 месяцев назад
Thanks for the tutorial man! :D
@BrazenNL
@BrazenNL 7 месяцев назад
Very tangential, but what is that microphone you're using. I love the way it looks and sounds.
@TrevorSullivan
@TrevorSullivan 7 месяцев назад
Hello! It's the MXL 990. I agree, it sounds great! I do have some EQ settings applied as well.
@ihgnmah
@ihgnmah 11 месяцев назад
Great explanation. Do you plan to cover the Derive pattern of clap?
@TrevorSullivan
@TrevorSullivan 11 месяцев назад
Thank you!! That's not necessarily a high priority topic for me, but I can add it as an idea to my backlog! I appreciate the suggestion 🙂
@Norrun-Dev
@Norrun-Dev 2 часа назад
.arg(Arg::new("fluffy") .long("fluffy") .help("are they a furry?")
@unixtensor
@unixtensor Год назад
Excellent.
@haydn.murray
@haydn.murray 10 месяцев назад
Awesome video! - Is there a way to reuse an arg without redefining it twice. Let’s say both person and pet require an address. Can I make one address argument and attach it to both register-person and register-pet?
@TrevorSullivan
@TrevorSullivan 10 месяцев назад
Thanks Haydn, and great question! I'd have to test to see if you can assign an argument configuration to a variable and reuse it. If you try this and find out, please do share!
@haydn.murray
@haydn.murray 10 месяцев назад
@@TrevorSullivan yes - it does work! let first_name_arg = Arg::new("firstname"); let m = Command::new("My Program") .about("Explains in brief what the program does") .arg(&first_name_arg) .subcommand(Command::new("subcmd") .about("This is a sub command") .arg(&first_name_arg) ) .get_matches();
@nhwhn
@nhwhn 6 месяцев назад
thank you
@raidensama1511
@raidensama1511 10 месяцев назад
I never did understand making an optional mandatory.
@shizeeque
@shizeeque 3 месяца назад
coding using `root` account? The man has no fear.
@hansdampf2284
@hansdampf2284 Год назад
You’re rust videos are really awesome. Do you have a patreon or can I donate to you in another way? Also regarding topics for future videos, I would like to propose “how to build your application to please the borrow checker” As a beginner I often ended up in situations where I didn’t know how to design something in rust to please the borrow checker. E.g. in C I just declare some global variables to Hold my command line arguments. In rust you have clap and you have the command line arguments in a struct most oft the times in the scope of the main function. How to you make the argument struct available to all functions? I use to pass it to every function at least as a borrow. But that seems kind of unelegant.
@TrevorSullivan
@TrevorSullivan Год назад
Thank you very much! I do have a PayPal page, and any donations would be graciously accepted! This content isn't sponsored or compensated, other than Google's tiny ad revenue. paypal.me/pcgeek86 As far as passing arguments to functions go, I would think that borrowing the arguments from your main function makes sense. That would be a good topic for end-to-end application building someday!
@Hellbending
@Hellbending 9 месяцев назад
I imagine part of the point of having to pass everything around is to sort of force people to use dependency injection instead of having little factories everywhere?
@newwei2937
@newwei2937 8 месяцев назад
Which IDE are you used in this video ? @TrevorSullivan
@TrevorSullivan
@TrevorSullivan 8 месяцев назад
It's VSCode with the Rust Analyzer extension! Check out my first video in the Rust playlist, on my channel. It covers my environment setup!
@anjonsarker2374
@anjonsarker2374 Год назад
nice
@YueZHANG-ev2ss
@YueZHANG-ev2ss 8 месяцев назад
I have searched for such a good tutorial for a long time, thanks a lot!
@fabricehategekimana5350
@fabricehategekimana5350 11 месяцев назад
Thanks for your video ! It was very useful !
@zubairyahayav5585
@zubairyahayav5585 3 месяца назад
Very helpful. Good job.
@marlonsbardelatti202
@marlonsbardelatti202 11 месяцев назад
your videos are really helpful, thx my friend
@chonkey
@chonkey 5 месяцев назад
This is such a well-made video. Keep it up
@a13m34
@a13m34 11 месяцев назад
👏👏👏
@oluwatosinojedapo468
@oluwatosinojedapo468 8 месяцев назад
Super Solid!!! Thanks a lot man
Далее
Writing a CLI App in Rust! - Part 1
17:44
Просмотров 77 тыс.
ДЕНЬ УЧИТЕЛЯ В ШКОЛЕ
01:00
Просмотров 763 тыс.
You Should Really Know These Traits in Rust
18:36
Просмотров 14 тыс.
Why does this Rust program leak memory?
35:24
Просмотров 58 тыс.
Decrusting the tokio crate
3:31:48
Просмотров 98 тыс.
Andrew Kelley   Practical Data Oriented Design (DoD)
46:40
Rust Functions Are Weird (But Be Glad)
19:52
Просмотров 136 тыс.
Rust: When C Code Isn't Enough
8:26
Просмотров 166 тыс.