 All right, I think I'm all set. Let's start. So, welcome everyone. My name is Rui Adorno, whoa. So, I'm a local from Montreal. I've been living here for almost 11 years now. So, it's one of my greatest accomplishments of my life, like becoming a Canadian citizen. So, yeah, I really love the people here, really love the country. Just the weather at this time of the year starts. It's not so great, but yeah. And I recently, it's been three months now, almost four. I joined NPM, so now I work at the open source team with Darcy, you might have seen his talk yesterday. Yeah, so you can find me at these places and I have, before anything, I have to also thank Joel because I totally just stole his CLI slide, so that little guy there is actually Joel over there. Thank you so much. All right, so we're here today to talk about CLI, right? I hope everyone here loves CLI, right? Quick show of hands. Who uses CLI on a day-to-day basis? Okay, it's off, yeah, okay. It is the right crowd. So, yeah, this is a quick talk and the goal here is just like for people to start, people that are not doing yet, start creating their own common lines, people who maybe are already doing, maybe you learn about a thing or two. So, yeah, let's get to it. Quick overview, so we're gonna go through understanding CLI commands, just a quick basic of how to define a reusable command, how to compose commands using UNIX pipelines, and then add interactivity, like let's sprinkle a little magic on top of it and then go, like, of course, let's use Node.js we did. So, yes, this quick disclaimer, you're about to see a graphic designer by formation giving a talk about the common line interface, which, yeah, and I think it makes a lot of sense. It is a great user interface and there's something that maybe sometimes people don't realize because our very communication is word-based, right? We think in word terms, word they link into things in our minds, right? So, and developers are always looking to reuse things, right? And words are really key words in our minds and we're gonna map them into things we wanna do, right? So, that's what makes the CLI, the command line interface so powerful because basically the commands, they're reusable stuff, right? We love to reuse stuff. And basically, we're storing commands, we're doing our workflow and these commands is just something that, okay, oh, yeah, now I need to do this thing. Oh, yeah, so maybe it's, maybe the command is run, maybe the command is like run my project. It's gonna map to something in your mind, it's gonna make sense to you and it's going to be reusable. So, all right, we're gonna go through a bunch of quick examples. So, very adventurous here, gonna do a lot of live coding stuff, but it's gonna be fun, yeah, it's fun stuff. So, huh, so not gonna jump into node yet. So, quick thing, like basically here, we're gonna use the cat command, basically that prints out contents of a file, right? So, here I'm just going to define, like, okay, I wanna create a new command. It's gonna be full, like for now, it's only gonna be catting things, like just like printing it out. So, that's like step one, the very most basic thing, like defining an alliance is one of the ways to create your own command. In this case, doesn't do much because, well, that's already a building thing. So, but sometimes, you wanna maybe use a variation of a command, right? Command that takes a flag, like, okay, like git status. So, like, git status usually, it's gonna print all this info, right? And let's say you like the s flag, which turns into this more pretty printed things, way of displaying your status of a git repo right now. So, yeah, okay, let's make, okay, status. Okay, that's gonna be my new command, like, I like that thing, like, I wanna be reusing that. So, from now on, every time, okay, now I wanna do status, but the way I like it. So, you basically, like, git status, like, you have that alliance is a new command you can use and reuse. And you can also, like, make it more versatile, like, there is also the function, the bash function way of defining it. So, basically, this one over here, I'm just going to, hey, git status, and then I'm just basically gonna be setting a parameter. So, now I can send down the s flag or some other ones, like, not, yeah, so it's going to do the very same thing that the other one did, right? But, basically, just to showcase the bash functions too, is also something we can do. So, yeah, using node, like, fun thing I did too, like, I just went on NPM real quick, let's find a useful library we could use to do something fun, right? So, basically, in this case, I'm just using some load library, I'm just invoking the node runner itself, and I'm recriting right away, right from bash, that command, and what it does is that, okay, if there is an offensive word there, it returns true, then it's gonna print block. Otherwise, it's just gonna print whatever was it, right? So, let's try it out, that starts to be more fun, right? So, I already, for the sake of, like, making sure it doesn't derail too much, it's already NPM installed. So, let's just create this new command here. So, okay, node, gonna print that, and it's gonna require offensive words, filter. Thank you so much, whoever did this command. And, it's going to take the word as an argument, I'm gonna use that, and then, if it's blocked, which is true, I wanna show anything, and otherwise, let's print whatever was that there, and then I close this thing, and then I close my function. So, let's print safe, oh, hi, yay, there's nothing offensive in this word, it works well. So, let's print safe. Oh, fuck, oh, blah, yeah, amazing. So, yeah, basically just quick demo on how to use a node module, like, even within Bash itself. Yes, so, moving on. Yeah, I think this is an interesting thing, like, took me a while to realize, as a designer, like, I've been learning these things on my own for a long time. So, basically, yeah, and you can also just define any file, any file that is in your path environment variable is going to be available as a command, as long as that file is executable. So, you can even, like, from the local installed modules, like, usually they're not available as a command line, right, even though if they provide command line interfaces, let's say, Joel's thing over there, CLI slides, it is a command line thing, but right now it's not available at all. So, if I go on and just, like, export my path, and I'm gonna contact, like, here I'm concatenating it with whatever was already there, getting my current directory here, and, like, okay, let's get everything that is in node modules bin, that'll be part of the path. So, now, the command slides thing that I have, it's available, it's not gonna work because it takes some other arguments, it's not the point, the point is that, now your internal node module bin, like, whatever local modules we have installed, they're available as a command for this prompt now, like. And it's very, very useful too, like, you can define your own path, like, you can have your own bin in your user local folder and be dropping your reusable commands there. It's something I do a lot, yeah. Yes, also, any, yeah, package JSON scripts. This is a super handy way of, like, just project base. I know, here's, the crowd is most node.js, so probably you all know this one already, but it's a mandatory one I had to mention, right? So, in your package JSON, you can define scripts, and those scripts, they can be run anytime later. So, NPM run, you can NPM run, hello, as long as hello is available as a script for that package JSON, it is going to run, you can reuse, a handy thing is that, this way you can even reuse CLI tools that are local to that project, without having to do the path thing, like NPM does it for yourself, basically. So, package JSON also supports the bin property, so basically this allows you, this is what we know the publisher, the maintainers of module, that's what we use when we want to distribute command line tools on NPM, right? Then people can just NPM install it and conveniently reuse it. So, I tend to try to share all the things that I do when I find it a little bit useful, I'm going to make it a quick node module, push to NPM, then myself I'll be reinstalling that later, whenever I switch computers, whenever something happens, and other people can reuse, right? You can share to your coworkers, oh yeah, I have a script for that, just NPM install this thing, it's going to do it. So, and here we get to the composing commands, yeah, which is the powerful thing about Unix, like the idea, Unix has this idea where every command is its own thing, and it tries to be like really specific, some of them are really not, like some of them get really busy with all the kinds of arguments and powerful things it does, but the idea is that you're gonna run LAS, it's going to list the files that are in that folder, right? You're gonna run cat, it's going to print the contents of that file, so you can actually combine those together and start creating like, okay, now I'm creating my own stuff, I'm reusing the basic commands that are available, you might be reusing some other commands that you installed from some other open source projects, and you can be combining them together and create your own workflow, and you can share it to people. So, basically yeah, a couple more examples, and this is where things start to get more risky because this might fail, anyhow, let me see, yeah, I think last time I had to delete this one. So, let's just say find, find is a command that allows you to list all the files, it's going to be recursively traversing all the folders and printing all the files, and you can specify arguments to start filtering out, like in this case, I'm filtering, okay, just files that has the name that ends in .js, so it's going to print all the files, oh, surprise, there's a lot of .js files in my node modules. So, let's say, okay, I want to get word file, I think I make sense of a command that I can reuse later where I could like, oh, let's get all these files, and then I want to grab, grab is one very handy command that allows you to filter items, so in this case, yeah, I want to, I want to be able to just like filter out one of these, so get word file, it's going to traverse all these files, and I want to just like, oh, just give me the ones that has CLI on it, so you see the other one is gone, and if I just, okay, no, actually just word, so all the CLI stuff is gone, it just prints the one that has words word on it, which is offensive word filter there, so this is like very basic first example of using the UNIX pipeline, right? So, the idea here is basically like the pipelines, you're combining the output coming from a command and to the second command, right? So this is, it kinds of connecting pipelines, and then the stream of information flows through them, and this is like, this is the origins of the stream library in module in Node.js, which I always had a hard time with, and I wish I didn't miss the other talk from Mateo about it, but anyways, so all these concepts could actually come from the UNIX pipelines, where you can connect the commands together, right? So, XR is handy utility that helps out because when you're connecting those pipelines, you're connecting the standard output into the input of the next one, so when you have a command like cat that wants to receive an argument, XR is going to help you out, it's going to, okay, okay, not connecting the standard input, I'm gonna read that thing as an argument. So in this case, let's make another handy command, print file. So, again, the same recite we had last time with the name and filter in JS, then let's just select one, so basically continue from the idea of the last command, but this time let's print the contents of the file with just select, right? So, print file, and okay, I want that word file again, but this time, print it, ah, it failed. Yeah, not going to debug that one, but let's just do it this way. I'm gonna do it manually because I probably just got something wrong here, and I'm just gonna manually, like instead of using the argument, I'm just gonna hard type the word here, where the argument usually goes, and let's cat that, and there you go. Like my word file, like I can see that that module is actually very simple, very simple, it's just like reading from a term to block JSON, and like, and it does the logic, oh yeah, should I, does it match anything in there, return true, otherwise false. Oh no, what happened? Oh no, is it rebooting? It was going wow. Okay, oh good, oh good. Let me move on. Yes, so, continue. Yes, you can also write down files from the pipelines, they have more operators, and this is the only one I'm gonna be showcasing, like basically the greater than sign, or smaller than, anyways. It's going to get that stream and dump it into a file. So like very handy too, in this case, oh yeah, this is a fun one, yeah. So let me get back my demo.js. Yeah, so basically this one, let's build a command that's going to, okay, print out from the file I'm gonna send in, and then it's going to replace anything like sad, SED, I call it sad, not sure, probably not the right way to call it. It is going to replace things, like in place, so it's basically just a string replacement, right? So I'm going to swap log for error in any of the stream of data that's flowing through here. And number two is going to be the second argument of my command, so I'm gonna save it, write it to a second file. So let just quick show what's going on here. Demo.js is basically doing the same thing that other command was doing using the library, but this time is a JavaScript file itself. So it's just console log. So what I want with this is just, okay, let's replace log with error for any file that I send into this thing. So make error, and I send in demo.js, and okay, and I wanna save an error.js from that. So I run it, and now I can see error.js has the same thing, but replace log with error. So basically showcasing the writing to a file operator using the greater than operator and multiple arguments with the number two there. So yes, I hope we have seen the light. Like, okay, okay, this is good. This is good, I can actually reuse this. It's not rocket science, right? Hopefully you're all good to go, like composing new workflows from the basic Unix commands that you already know. And then you're probably gonna be interested in learning about some other more, like because the more you know, the more commands you start learning about, the more ideas you're gonna have, oh yeah, this can actually be automated like that because it could use that other tool that I just learned about, yeah. So, and I like to introduce like a very, very cool handy feature, basically a Unix command that just allows you to turn any of this stream input, like into interactive interfaces. So you can like just build things that are gonna turn into interactive lists and you can select one and you can do whatever you want with the output of that stream. So yeah, basically, I call it I pipe to, the interactive pipe to thing, but the command is IPT. So given any list in the shell, you can like, okay, listen to files there. So I can pipe that list of files into I pipe to and it's going to be the interactive interface of it. Oh, nice. And then I can just like select one and what it does is just prints whatever you select. So it's going to allow you to connect that to some other stuff. Then you can start creating really handy work flows right with that. So in this case, yeah, I've just selecting, oh yeah, I have this other handy command here that, okay. Let me just like interactively, oh nice, oh cool, cozy mood. Oh no, what is going on? Anyway, so yeah, you're used to like CD, like in order to navigate, but it would be handy if you could just like, oh yeah, now I can see the list of files. I can just like select the folder in it and like, oh yeah, it's kind of cool. Very basic, just like showcase some examples. Another, yeah, another very basic one. You can have like a list of branch for a git, git also like because it has so many lists, right? It has lists of branches, lists of comments, lists of remote repos you might point into. So you can do all sorts of like crazy ideas. Okay, let me connect the list of branch, then I pipe that into the interactive thing and then I can like, whoa, why not? I can check out into a different branch, right? So yeah, okay, yeah, I didn't check out, but like in this case it failed because I had some modified files, but you can get the idea. And yeah, it has some handy options too, like in this case, I have this command for printing files and it's going to be listing all the files in the folder and I'm gonna use this multiple argument, dash m, that is going to allow me to select multiple items on that list. So instead of being just like selecting one, it's going to be like more like filtering out the unselected files. So, oh yeah, let's print all of the things that I selected in there. So print files is going to show me a handy list. There is now a checkbox sort of and I can go and like, oh yeah, let's select the demo and the error and it's gonna pipe that info into cat that is going to print both of them and we've seen that earlier and you can see this is the same thing. So handling file names, basically, it also has like this very handy thing when you're dealing with get that when you're doing like get status, in this case that same fancy view with the notification in there like showcasing the status for each file, right? I'm gonna use this handy dash p option that is going to just try to parse the file path out of the item itself so that I get rid of like the d's and m's and question marks so that I can actually reuse that path right away and I can like, I can just print the info for that one. So as you can see, the list still has the metadata in the beginning but as soon as I select one, the next command works because the dash p command like get rid of all the things that are not part of the file path there, the file name. Yeah, and the last thing to showcase is the fuzzy finder auto complete mode. So basically I can like, you know, I'm also going to take out the opportunity here to show that you can also send in as a file name. So like I can like, send in just IPT and like the package JSON. So it's going to explode like the file into mode, like for each line is going to become an item. And then the argument is actually dash a, this is wrong in the slider. Sorry about it. But then it's just like, it's just going to filter out basic, based on what you're typing like an auto complete kind of thing. You can like, oh, description. So, oh yeah, setting that line. So we're gonna output this. So yeah, all crazy ways to like, do cool commands, like interactive commands with it. Just throwing out like a real quick thing I put together for the demo. How many of you know about the Pocoche CLI? Like it was recently released as a known CLI. So basically it's one of the NPM internals. So allows you to like get fetch metadata, fetch maybe just like the tar ball, but not NPM installing everything that goes with it. So basically I did like this NPM install version command here that is going to use a metadata from the NPM to basically build a list of all the versions, list them. And when you select one is going to NPM install that exact version. So real quick, NIV. And then I'm gonna NPM install. In this case over here, I'm kind of hard coding the name of the package, but the idea is kind of argument. And then gonna be sending it into node because I wanna be able to parse that metadata to retrieve just the result of that Pocoche call and that thing over there. Yes. I'm gonna get only the versions. And then I'm going to turn this into a string. And then I'm going to pipe that into IPT. This one is too complicated. I should have saved it for this. But anyways, let me showcase like Pocoche Pacument what it's going to do. Then you're gonna get the idea of it. So basically I'm fetching the metadata for a specific package. In this case, I pipe to itself. Then I can get like a list of versions. Oh no, I didn't touch anything. And I was about to demo the cool NPM stuff. Oh, what do I do? Oh, it's coming. Yeah. Okay. You just need to walk in. Yeah, yeah. Thank you. So yes. So basically over here, I'm going to filter just the versions. So what I was doing with it is that I was going to use node here real quick to just like get the keys of the version names, of the version there so that becomes more usable. Yeah, so I have a list of all the versions. So this list, what I was doing after that was like concatenating them, like making them a string of like, just like we had the LS in other commands, right? And those I can like pipe into I pipe to and then we can select one. And then with that selected one, I can just like pipe that into NPM install and do like the name of the thing at that result. That thing is not, don't think it's gonna work. I had to do that all that other complex crazy way like this. And then like this. And then I could like NPM install and then module name at specific version. So NPM install 1.0. Woo. So yes, interactive commands are fun. And as the last one I wanted to showcase is the no-test list is when I start digging into these, like sometimes it gets out of hand. So this one became like a kind of larger project. Like there's a lot of interest from the community, people that just jumped in and start contributing more. So it became kind of like larger package because it has like many features around it. It's just not the basic thing for my pipe to, but it uses I pipe to provide the same interface, right? So basically NGL is going to list all the scripts you have in that package JSON. And once you select any of them, you just hit enter, it runs. So that's the basic idea of it, right? At that point it's just like the basic I pipe to kind of thing, but then it does all sort of thing. Like in this comes from the community contributions like keep track of the last run command. So then you run it again, like it's already selected, right? Super handy if you're like using it day to day basis. And also if you're just like, if you're just maybe it's a task you're running all the time then you can remove the L so it's not no task list, it's just run the no task. Like it just runs the latest ones so you can just like be running them again. And whatever you want to switch, you can like go back to the L, you can select multiple items. So like, okay, let's run both of them. Like same thing with the multiple, you still have them selected by default. So yeah, yeah, it's also available on NPM. You can NPM install NTL, NPM install I5 too. Yeah, and I hope you all feel really confident about creating all these workflows. I'm gonna make sure these lights are available so that you can use as a reference to start creating your own, right? Yeah, so thank you very much. Yeah.