What Makes A Good Cli Tool | Prime Explains

Поділитися
Вставка
  • Опубліковано 24 сер 2023
  • Recorded live on twitch, GET IN
    / theprimeagen
    MY MAIN YT CHANNEL: Has well edited engineering videos
    / theprimeagen
    Discord
    / discord
    Have something for me to read or react to?: / theprimeagenreact
    Hey I am sponsored by Turso, an edge database. I think they are pretty neet. Give them a try for free and if you want you can get a decent amount off (the free tier is the best (better than planetscale or any other))
    turso.tech/deeznuts
  • Наука та технологія

КОМЕНТАРІ • 156

  • @Anteksanteri
    @Anteksanteri 11 місяців тому +304

    It's weird how many developers don't even know how to use the command line.

    • @CottidaeSEA
      @CottidaeSEA 11 місяців тому +72

      It's nice to be among developers who don't know how to use them, because I can basically be a magician who gets information out of seemingly nowhere in an instant. To those who know, I just used grep.

    • @Beefster09
      @Beefster09 11 місяців тому +37

      it's forgivable coming from a junior dev, but I facepalm in shock when I see it coming from someone who has been in the industry for 20+ years

    • @ardnys35
      @ardnys35 11 місяців тому +13

      we have been spoiled with fancy graphics and it only gets more and more unfamiliar. plus no one really teaches it.

    • @CottidaeSEA
      @CottidaeSEA 11 місяців тому +34

      ​@@ardnys35 I think some people also find it daunting since CLI tools are quite volatile. They do exactly what you tell them to do without questioning anything. That's also why they are great (besides being fast) but you can mess things up if you do the wrong thing.
      Then again, people seem to be less afraid of SQL despite being able to nuke an entire table by forgetting to add WHERE.

    • @Euphorya
      @Euphorya 11 місяців тому +21

      I die a little inside every time my manager says "that's nice, but does it have a GUI?"

  • @livingcodex9878
    @livingcodex9878 11 місяців тому +95

    Well that was an epic nugget of knowledge. Can we get more of that please?

  • @hoimar8710
    @hoimar8710 11 місяців тому +47

    Please do the frontend masters course for writing good unixoid CLI tools! Including golden shower tests!

  • @cg219
    @cg219 11 місяців тому +23

    I want to put in my vote for the Frontend Masters course on this. Thanks!

  • @fennecbesixdouze1794
    @fennecbesixdouze1794 11 місяців тому +17

    @3:25 You can accomplish the same thing with shell redirections, or *gasp* the dreaded cat piping.
    All tools should start with stdin and stdout. If you really wanna build in file handling fine, but you don't have to.

    • @joaomacedo673
      @joaomacedo673 10 місяців тому

      Yeah. Moreover, when I heard him say that using files functionality support is cool for integration tests I was wondering "well, but you are not testing stdin input that way". And with pipe redirection you actually can.

    • @luigidabro
      @luigidabro 4 місяці тому

      Never underestimating the power of piping.
      But specifying stdin to be a file can be useful. On cmd or powershell 1.0, piping removes all non-ascii characters.

  • @Jmcgee1125
    @Jmcgee1125 11 місяців тому +32

    It's called tee because it makes a T. Data flows across the top of the T (from stdin to stdout), but also gets duplicated out the bottom (to a file). Super useful, and not just for :w !sudo tee %

    • @xenio8736
      @xenio8736 11 місяців тому +1

      wait wha's the point of :w !sudo tee % ?

    • @Jmcgee1125
      @Jmcgee1125 11 місяців тому +7

      Save a root-protected file if you opened vim as a normal user.

    • @sempiternal_futility
      @sempiternal_futility 11 місяців тому +1

      very good explanation actually

    • @theodorealenas3171
      @theodorealenas3171 11 місяців тому

      Wait, :w can write into the stdin of a shell command?

    • @Jmcgee1125
      @Jmcgee1125 11 місяців тому

      @@theodorealenas3171 It can! It can even do it for range writes (i.e. writing from visual line mode), if you only want to send a segment.

  • @kc3vv
    @kc3vv 11 місяців тому +3

    Thanks to you I recently came to enjoy gnu parallels to parallelise some build scripts.

  • @notapplicable7292
    @notapplicable7292 11 місяців тому +2

    This is really useful as someone who's recently working on CLI tools.

  • @thingsiplay
    @thingsiplay 11 місяців тому +87

    The Unix philosophy is like functional programming.

    • @simonfarre4907
      @simonfarre4907 11 місяців тому +6

      It's an apt description, indeed of the Unix philosophy.

    • @bitti1975
      @bitti1975 11 місяців тому +5

      If I'd categorize it, I'd file it under 'Dataflow programming' but that's a more or less orthogonal concept.

    • @ripplecutter233
      @ripplecutter233 11 місяців тому +5

      the issue isn't the pipelines, it's all the basic commands you have to learn. takes time to remember them all (the basic ones).
      but once you know em then yeah it's pretty much functional programming

    • @simonfarre4907
      @simonfarre4907 11 місяців тому +9

      ​@@bitti1975 I think you're misunderstanding / misusing the term orthogonal. Because "dataflow programming" is most certainly a core tenet of FP. Clear input and output. Referential transparency and all. These are not unrelated. But I guess you could say it's a simplified description of FP, instead.
      That being said, I don't think anybody had FP in mind when the Unix Philosophy was "created" as it were.

    • @fennecbesixdouze1794
      @fennecbesixdouze1794 11 місяців тому +3

      Yep.
      UNIX's shell redirects and pipes can be derived formally as an I/O monad.
      It's not a matter of opinion: it's exactly, formally, provably like functional programming

  • @barrykp
    @barrykp 11 місяців тому +6

    Would love a course on tooling!

  • @aus10d
    @aus10d 11 місяців тому +2

    very helpful tips. thank you prime!

  • @Omikronik
    @Omikronik 11 місяців тому +1

    this is the kind of advice I love mr prime for.

  • @JordanShurmer
    @JordanShurmer 11 місяців тому +1

    Thanks for sharing this. Imagine reading this tip as an article when you can watch a video instead... oh man

  • @0dsteel
    @0dsteel 11 місяців тому +1

    This casual 4 and a half minute vod has more useful information than hours long tutorials

  • @Luisya14
    @Luisya14 11 місяців тому

    What do I need to do to end up working on stuff like this?
    I'm really bored at my current job (make one webapp finish next, do it super fast so the project is cheap)

  • @Jason_Kang
    @Jason_Kang 11 місяців тому +4

    PLEASE do a course on writing dev tools! 🙏🙏🙏

  • @AloisMahdal
    @AloisMahdal 11 місяців тому +4

    I believe the right way to call tee(1) is `tee hee`.

  • @pbnjdev
    @pbnjdev 11 місяців тому +2

    "Command-line Tools can be 235x Faster than your Hadoop Cluster" -Adam Drake

  • @marlo3898
    @marlo3898 11 місяців тому +1

    The good old Golden Shower Test

  • @laughingvampire7555
    @laughingvampire7555 11 місяців тому +1

    gnu parallel is used a lot in bioinformatics or other scientific computing areas, they make a script in python or perl and then gnu parallel.

  • @sorosborcsi
    @sorosborcsi 11 місяців тому

    Your best video so far ⚒️ thanks

  • @peteradam4740
    @peteradam4740 11 місяців тому +3

    Please do that course :)

  • @McHorsesCreations
    @McHorsesCreations 11 місяців тому +5

    He didn’t said “-agen” 😭😭😭

  • @fuutek9171
    @fuutek9171 11 місяців тому +1

    please do a tips n tricks for common cli tools like grep

  • @nixoncode
    @nixoncode 11 місяців тому +3

    all great developers understand how unix works

  • @dealloc
    @dealloc 11 місяців тому +1

    POSIX compliance is a must.

  • @benjaminemori9089
    @benjaminemori9089 11 місяців тому

    Watching you alone brings me a whole level of inner joy!😂

  • @codedbyshoe
    @codedbyshoe 11 місяців тому +1

    We need a "last cli class you'll ever need"

  • @JoaoJGabriel
    @JoaoJGabriel 11 місяців тому

    I'm glad this became a UA-cam video-AGEN

  • @eloniusz
    @eloniusz 11 місяців тому

    C++ has two stream outputing to stderr "std::cerr" and "std::clog". The latter one really makes it clear that this is where the logs should go to (and not to "std::cout").

  • @markmcdonnell
    @markmcdonnell 11 місяців тому

    tee has been my secret sauce since forever

  • @ShadowKestrel
    @ShadowKestrel 11 місяців тому +18

    I'm a little confused on the inclusion of optional file reading/writing - would it not be simpler to only support stdio at the program level, then use angle brackets or cat/tee for if you want files? To me it seems that would also follow "do one thing and do it well", although with how often I see the pattern it seems more likely I'm just missing something here

    • @kuhluhOG
      @kuhluhOG 11 місяців тому

      speed/throughput
      just go and test the difference of:
      cat some_file | grep some_regex
      vs
      grep some_regex some_file

    • @ShadowKestrel
      @ShadowKestrel 11 місяців тому +2

      @@kuhluhOG that's a useless use of cat - of course it's less performant than redirections. I actually see slightly improved performance with redirections instead of file argument, although it's the difference between averaging 1.21s and 1.23s (maybe zsh caching, maybe some reduced syscalls, don't really know why)

    • @CramBL
      @CramBL 11 місяців тому +3

      @@ShadowKestrel point still stands. Maybe you want to run something multiple times on some compressed data, you could use lz4 -d -c | debug-tool or you could decompress to a file first and then save decompression overhead, piping IO overhead (which is very significant), and you enable some really powerful optimizations such as memory mapping or pre-allocation based on file size etc.

    • @trapexit
      @trapexit 11 місяців тому +15

      Because redirection is a function of the shell and not all usage of the tool is within the shell.

    • @Drummerx04
      @Drummerx04 11 місяців тому +5

      It's useful for a few reasons. Off the top of my head, you can specify multiple input files at once, you give explicit options for anyone using your tool in a script, and the tool would likely behave better when not being launched from a full shell environment.

  • @gamemoves2415
    @gamemoves2415 11 місяців тому +2

    Please do the course. Would be very happy

  • @nomomcarver
    @nomomcarver 11 місяців тому +1

    good advice

  • @EivindGussiasLkseth
    @EivindGussiasLkseth 11 місяців тому

    Do you have a sample repo to look at?

  • @Forquare
    @Forquare Місяць тому +3

    Please can we normalise man pages with CLI tools - I honestly don't think a tool should reach v1 without a man page. I don't want to figure out what your help flags are and have a ton of scollback maybe printed to stdout or maybe to stderr, I just want to write `man ` and use my favourite $PAGER to browse the options, example usage, etc.

  • @NicolasRuizX
    @NicolasRuizX 11 місяців тому +2

    Please do the course!!!

  • @Dev-Siri
    @Dev-Siri 11 місяців тому +1

    My comment is,
    I cannot believe prime made this a youtube video.

  • @mvargasmoran
    @mvargasmoran 11 місяців тому +3

    You said Golden Shower, I google that, it was nothing about software testing. 🥺

  • @ersstuff
    @ersstuff 11 місяців тому

    Amazing diagram!

  • @Anton_Sh.
    @Anton_Sh. 6 місяців тому

    What is that drawing app he is using?

  • @Howtheheckarehandleswit
    @Howtheheckarehandleswit 11 місяців тому +2

    I'm always torn on the file escapes thing. Because it does kinda feel like it violates the UNIX philosophy to integrate that into my program when I could always replace "foo --input ./bar --output ./baz" with "cat ./bar | foo > ./baz", but that does also make it kind of a pain to use on files

    • @joshix833
      @joshix833 11 місяців тому +7

      Cat is for concatinating not for reading single files.
      foo < ./bar > ./baz

    • @Howtheheckarehandleswit
      @Howtheheckarehandleswit 11 місяців тому +3

      @@joshix833 No one ever bothered to teach me the

    • @theodorealenas3171
      @theodorealenas3171 11 місяців тому +2

      ​@@Howtheheckarehandleswitoof. I felt that one, I started using it after a year of using Linux, or more

  • @xybersurfer
    @xybersurfer 11 місяців тому

    but where do status updates fit into this?

  • @trapexit
    @trapexit 11 місяців тому +1

    re: tee... yes! or at least write a script which writes data out if not already stored. Too often people try to consume and process data in the same loop and it puts unnecessary strain on the data source and complicates debugging. Just write it out somewhere and use that.
    I wouldn't call it a "break point" but I understand what is meant by it. It's literally a T... like a pipe T... 1 input and 2 outputs of the same data. The syscall does the same.

  • @gabumon9210
    @gabumon9210 11 місяців тому +2

    hey i work as a web dev with 2 years experience. but i feel, im so lack about how actually that thing work or how to make something other than a web server or web client. maybe because i started learning programming trying to build a website.
    primeagen video appear on my youtube home, and i think he is what we called an engineer or a dev not just 'react dev' or etc.
    What step should i go to learning this kind of thing ? i mean like memory, gc, and many more i hope you know what i mean
    I hope anyone here who have lot of experience as 'software engineer' can tell me what should i learn first and the learning path.

    • @abcdefg-nu4xj
      @abcdefg-nu4xj 11 місяців тому +1

      It all comes down to understanding the fundamentals, understanding c, assembly, memory management, compilers and operating systems, even some hardware and cpu architectures, can give you insights about how your browser and JS engine works (both implemented in c++ utilizing many fundamental concepts mentioned above) that the absolute majority of ‘exclusively web devs’ will never try to begin to understand. It can enhance the quality of your code, broaden the things you can do and make it easier and faster for you to learn new technologies. Those who took a CS degree had to go through a few semesters of learning the fundamentals. Prime has a CS degree so he had to go through that too. However a CS degree is absolutely not mandatory to get a deep understanding of fundamentals since everything exists online

    • @gabumon9210
      @gabumon9210 11 місяців тому +1

      @@abcdefg-nu4xj hey, thanks for the answer !
      I think you are right, i lack everything about computer scince since i learn programming not from cs degree
      I search on youtube and harvard make a video about CS with 24h long. I hope it can help me to learn some computer science.
      Thank you for your answer 😄

    • @abcdefg-nu4xj
      @abcdefg-nu4xj 11 місяців тому

      @@gabumon9210 i would suggest taking it one step at a time, dedicate a few days to learning c well, focusing on pointers and memory. Then maybe try and implement a few data structures (dynamic array, hashtable, red-black tree) and algorithms from scratch with c, then you can go a little lower level and learn assembly , focus on how your C code translates to assembly, this is a great chance to learn about CPU architecture and get a deeper knowledge about memory. The next thing from here is to learn about operating systems, namely linux. First learn how to interact with the OS as a “user” with syscalls to spawn threads, manage memory and IO. Then, with your knowledge of c, data structures and sssembly you can go deeper and learn how central parts of the OS are implemented, how it manages threads, I/O , memory, etc.
      Each step might take you a few weeks or months to get right but once you’re done you will have a strong foundation to learn about things that build on those fundamentals like networking, compilers, virtual machines, web browsers, etc
      Anything that interests you
      Your learning sources should be yt videos, free (or paid) courses and books

  • @ripplecutter233
    @ripplecutter233 11 місяців тому +3

    a good cli tool can easily integrate into a pipeline.

  • @dtomvan
    @dtomvan 11 місяців тому

    damn, i knew about tee but never thought of it as a "pipe-breakpoint" I always have to refetch a big pipeline 😔

  • @chrissaltmarsh6777
    @chrissaltmarsh6777 11 місяців тому

    To learn this, fire up a unix machine from, uh 35 years ago and do some work.
    Those ideas are utter gold.
    And have short options. '-v' is a hell of a lot quicker on a 2400 baud VT100 than '--version'
    (But I am ancient)

  • @adjbutler
    @adjbutler 11 місяців тому

    please do the 'good tools' course... I would pay big dollars for you to do it!!!!

  • @Keversez
    @Keversez 11 місяців тому +1

    make a course on this homie

  • @chrisE815
    @chrisE815 11 місяців тому +1

    Lithium batteries, interchangable heads, pulsing and vibration functions, ....Oh sorry I misread the video title .

  • @TheNewton
    @TheNewton 11 місяців тому

    what kind of football play is that? 0:22

  • @Tetsomina
    @Tetsomina 11 місяців тому

    Someone send this man a weebo tablet for these excalidraw moments 😂

  • @seg_fault_jim
    @seg_fault_jim 11 місяців тому +1

    @primetime do a video showing this in code - that would help people understand

  • @ItaloPenna
    @ItaloPenna 7 місяців тому

    A good CLI tool also must return a signal. Returning a good defined integer is awesome . Sometimes you don't give a 5hit about strings. ( Windows programmers nowadays have no clue about this.)

  • @bicube7529
    @bicube7529 11 місяців тому

    ok, i'm too junior to understand, need some code examples. anyone konws a github repo that shows what he said?

  • @adamgrey268
    @adamgrey268 11 місяців тому

    lessssgoooooooooo!

  • @mvargasmoran
    @mvargasmoran 11 місяців тому

    Teez Nutz

  • @eqprog
    @eqprog 11 місяців тому

    Inversed whiteboard

  • @TorkilZachariassenTZNG
    @TorkilZachariassenTZNG 11 місяців тому

    Jźzz ... programs read stdin/file and output to stdout/file and stderr.
    That's what the professor told is in 1982 teaching Pascal and Fortran simultaneously

  • @yaksher
    @yaksher 11 місяців тому +2

    Why put in all the effort for file inputs and outputs? Isn't that what redirects are for? And like, sure, redirects don't support multiple files for standard in, but you can just use cat for that, no?

    • @joshix833
      @joshix833 11 місяців тому

      Most of the time yes. But e.g. grep needs file arguments to be able to show source files and lines.

    • @pineberryfox
      @pineberryfox 11 місяців тому

      if you only care about using a single file, check the args and freopen the standard streams when appropriate. then you get to pretend like you're only using the standard streams, but you're not inconveniencing your users
      for example, with xargs, you can have a list of files to operate on, one-per line, and say "

    • @billeterk
      @billeterk 11 місяців тому

      Sometimes you do need to seek though

    • @yaksher
      @yaksher 11 місяців тому +1

      ​@@joshix833 Sure, but that's an exception; that's not a reason to bake it into most tools

    • @yaksher
      @yaksher 11 місяців тому

      @@pineberryfox I suppose it's slightly more convenient with xargs but can't you also just do a cat with xargs? But fair enough

  • @uuu12343
    @uuu12343 11 місяців тому

    I use CLI utilities like there's no believing

  • @kj_sh604
    @kj_sh604 11 місяців тому

    pipe is the only way to pipe

  • @NomadSWE
    @NomadSWE 11 місяців тому

    Windows Terminal ftw

  • @SimGunther
    @SimGunther 11 місяців тому +4

    If only there was a language that outlined CLI commands like this drawing...
    bash/zsh/csh/fish do not count in this regard for those wondering

  • @barutaji
    @barutaji 11 місяців тому

    "what is golden shower?" (Bolsonaro, 2020)

  • @Cammymoop
    @Cammymoop 11 місяців тому +1

    I want to write a better cli calculator but i know i shouldn't

    • @user-kc8uh9ve4j
      @user-kc8uh9ve4j 11 місяців тому +4

      Personally I use python for calculations in the cmd just the standard repl/IPython

    • @daleryanaldover6545
      @daleryanaldover6545 11 місяців тому

      Most languages (php, ruby, python) or frameworks (node, laravel artisan) have interactive shells, just input an expression and voila calculation complete

    • @Cammymoop
      @Cammymoop 11 місяців тому

      @@user-kc8uh9ve4j I use the python repl too, I just have the craving to make something with a better interface. auto implied last result, proper juxtaposition multiply, lists and automatic mapping of scalar functions, cli option to output a cleaned version of last session, etc
      Which is why I definitely shouldn't, I don't think I actually have that kind of time

    • @billeterk
      @billeterk 11 місяців тому +1

      Depends on your metrics for good but qalc is pretty awesome for a semi reliable DWIM calculator

    • @Cammymoop
      @Cammymoop 11 місяців тому

      @@billeterk That does look pretty darn good, thanks

  • @Swifter101
    @Swifter101 11 місяців тому

    you look a gta character

  • @joaovmlsilva3509
    @joaovmlsilva3509 11 місяців тому

    I feel like I'm missing 90% of the context here.

  • @thomas-hall
    @thomas-hall 11 місяців тому +1

    File in/out is just duplicating stdin/out

  • @kollpotato
    @kollpotato 11 місяців тому

    potato

  • @eduardocosta9078
    @eduardocosta9078 11 місяців тому +1

    Just dropping a comment to be the first.

  • @DarrenJohn10X
    @DarrenJohn10X 11 місяців тому

    git push faster way of doing things into brain
    MERGE CONFLICT

  • @yusufcansert9276
    @yusufcansert9276 11 місяців тому +3

    You are only talking, code once ıf you can

    • @tropicaldog430
      @tropicaldog430 11 місяців тому +1

      🥴

    • @deistormmods
      @deistormmods 11 місяців тому +2

      those are most of his videos. he doesn't really do programming and if he does, he's constantly talking to the chat. its a different type of channel and it isn't for everyone.

  • @zeyadkenawi8268
    @zeyadkenawi8268 11 місяців тому

    parallel sucks I use xargs

  • @c0ldfury
    @c0ldfury 11 місяців тому

    this is wrong on so many levels. when processing a file, the stdin and stdout IS the file stream. there's no separate channel for files.

  • @4444kik
    @4444kik 11 місяців тому

    Real talk, how many developers watching this video who have a job didn't know and use parallel and tee at least once already (not necessarily together)? As a Linux guy I know my command line like the back of my hand, but not every developer is a Linux guy. I know 2 other developers personally and one of them is really not familiar with it at all and the other knows enough to get the job done but hates using it, or so he tells me. I'm curious what the demographic here is like.