Parse Rust CLI Args With Clap 🦀 Rust Tutorial

แชร์
ฝัง
  • เผยแพร่เมื่อ 22 พ.ย. 2024

ความคิดเห็น • 55

  • @ImranKhan-br5dv
    @ImranKhan-br5dv 6 หลายเดือนก่อน +6

    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 7 หลายเดือนก่อน +3

    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  7 หลายเดือนก่อน

      Thanks so much for sharing your thoughts! I'm glad you're benefitting from these videos on Rust! Keep learning! 🦀🧠

  • @HELLOBOYZ-c6o
    @HELLOBOYZ-c6o 11 หลายเดือนก่อน +4

    Awesome job, man! You helped me so much. God bless you my friend! You deserve much more recognition, keep going.

  • @_jdfx
    @_jdfx 11 หลายเดือนก่อน +2

    Great stuff! one small thing though, the VS code type hints are really confusing in white.

    • @TrevorSullivan
      @TrevorSullivan  10 หลายเดือนก่อน

      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 10 หลายเดือนก่อน +1

      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)

    • @qweqwewerwerertert
      @qweqwewerwerertert หลายเดือนก่อน

      At time 14:10, when adding a new position argument, the type hint “Command” looks like it is part of the code. This threw me off so much I went back to the Rust book thinking I missed some builder/macro syntax where chaining doesn’t require a period “.” - hope you can get to update the color/font settings on the type hints but otherwise awesome video!

  • @harikeshranjansinha6939
    @harikeshranjansinha6939 7 หลายเดือนก่อน

    This tutorial is really helpful. I was really having a hard time learning CLAP. You made it very easy. Thanks ❤❤

  • @massimo79mmm
    @massimo79mmm หลายเดือนก่อน

    exactly the video i needed! thank you!

  • @YueZHANG-ev2ss
    @YueZHANG-ev2ss 10 หลายเดือนก่อน

    I have searched for such a good tutorial for a long time, thanks a lot!

  • @Khl8122
    @Khl8122 11 หลายเดือนก่อน

    Derive approach is the declarative way. Builder is imperative.

  • @daque1960
    @daque1960 ปีที่แล้ว +1

    Thanks for the clap tutorial!

  • @BrazenNL
    @BrazenNL 9 หลายเดือนก่อน

    Very tangential, but what is that microphone you're using. I love the way it looks and sounds.

    • @TrevorSullivan
      @TrevorSullivan  9 หลายเดือนก่อน

      Hello! It's the MXL 990. I agree, it sounds great! I do have some EQ settings applied as well.

  • @aurelio_fernam
    @aurelio_fernam 2 หลายเดือนก่อน

    Thank you very much!!!

  • @ihgnmah
    @ihgnmah ปีที่แล้ว

    Great explanation. Do you plan to cover the Derive pattern of clap?

    • @TrevorSullivan
      @TrevorSullivan  ปีที่แล้ว +2

      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 🙂

  • @zubairyahayav5585
    @zubairyahayav5585 5 หลายเดือนก่อน

    Very helpful. Good job.

  • @haydn.murray
    @haydn.murray ปีที่แล้ว

    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  ปีที่แล้ว

      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 ปีที่แล้ว

      @@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();

  • @chonkey
    @chonkey 6 หลายเดือนก่อน

    This is such a well-made video. Keep it up

  • @slamdunksammy
    @slamdunksammy 11 หลายเดือนก่อน

    Seriously amazing tutorial!!

  • @slurpin-tw
    @slurpin-tw 4 หลายเดือนก่อน

    This video is useful.

  • @stephennelson-smith3312
    @stephennelson-smith3312 11 หลายเดือนก่อน +2

    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!

  • @piyushpatil6874
    @piyushpatil6874 7 หลายเดือนก่อน

    Really enjoying your work 😊❤

    • @TrevorSullivan
      @TrevorSullivan  7 หลายเดือนก่อน

      Thank you! ❤️ I'm glad you're learning Rust! 🦀

  • @IsaqueSbr
    @IsaqueSbr 9 หลายเดือนก่อน

    Thanks for the tutorial man! :D

  • @marlonsbardelatti202
    @marlonsbardelatti202 ปีที่แล้ว +2

    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  ปีที่แล้ว +1

      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 ปีที่แล้ว +2

      @@TrevorSullivan ok thx man

    • @marlonsbardelatti202
      @marlonsbardelatti202 ปีที่แล้ว

      @@TrevorSullivan ok now it works, I was trying to use takes_value() which is no longer avaliable, using num_args(0) works fine

  • @fabricehategekimana5350
    @fabricehategekimana5350 ปีที่แล้ว

    Thanks for your video ! It was very useful !

  • @marlonsbardelatti202
    @marlonsbardelatti202 ปีที่แล้ว

    your videos are really helpful, thx my friend

  • @unixtensor
    @unixtensor ปีที่แล้ว +1

    Excellent.

  • @oluwatosinojedapo468
    @oluwatosinojedapo468 9 หลายเดือนก่อน

    Super Solid!!! Thanks a lot man

  • @hansdampf2284
    @hansdampf2284 ปีที่แล้ว +2

    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 10 หลายเดือนก่อน

      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?

  • @raidensama1511
    @raidensama1511 ปีที่แล้ว

    I never did understand making an optional mandatory.

  • @nhwhn
    @nhwhn 8 หลายเดือนก่อน

    thank you

  • @anjonsarker2374
    @anjonsarker2374 ปีที่แล้ว +1

    nice

  • @a13m34
    @a13m34 ปีที่แล้ว

    👏👏👏

  • @newwei2937
    @newwei2937 10 หลายเดือนก่อน

    Which IDE are you used in this video ?
    @TrevorSullivan

    • @TrevorSullivan
      @TrevorSullivan  10 หลายเดือนก่อน

      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!

  • @liminal27
    @liminal27 10 วันที่ผ่านมา +1

    Easily one of the most poorly documented crates I've encountered.

    • @TrevorSullivan
      @TrevorSullivan  10 วันที่ผ่านมา

      @@liminal27 yeah I struggled a lot with it before creating this video. There's documentation, it's just hard to comprehend.

    • @liminal27
      @liminal27 10 วันที่ผ่านมา

      @@TrevorSullivan I started using ChatGPT to help fill in gaps eg. "what does [code snippet] mean?" and it so far it's been great.

  • @shizeeque
    @shizeeque 5 หลายเดือนก่อน

    coding using `root` account? The man has no fear.

  • @EmbeddedSorcery
    @EmbeddedSorcery หลายเดือนก่อน

    Completely glossed over the most important part of this whole tutorial... how did you open up the emoji selector.

    • @TrevorSullivan
      @TrevorSullivan  หลายเดือนก่อน +1

      @@EmbeddedSorcery WIN + PERIOD 😊

  • @Norrun-Dev
    @Norrun-Dev หลายเดือนก่อน

    .arg(Arg::new("fluffy")
    .long("fluffy")
    .help("are they a furry?")