Let's take a look at the pattern that we're going to use for putting our Klyde together, OK, so we
are only going to have one command instead of our project for now.
But regardless, this is a pattern that I still recommend you try following if you are ever adding in
additional commands to a SEELIE.
So we're going to create a folder called the Commands Folder.
Inside there, we're going to create a variety of different files.
Each of these different files is going to describe exactly what to do when a user runs a very particular
command.
So, for example, you and I are going to create a Servatius file inside there.
We're going to write out some logic that says exactly what we want to do whenever one of our users runs
the book, Serve Commands.
If we had any other commands tied to our Seelie, we don't in our case, but I just have these on here
for demonstration purposes.
So, for example, if we had another command called Publish, then we would create a published its file.
And inside that file once again describe exactly what to do whenever a user runs the book published
Command.
Once we build all these different command files, we'll then import them back into a main index file
and inside is where we will assemble all these commands together and describe in total how our works.
So, again, the pattern that we're going to follow in this course, and I recommend you try this out
on your own as well for any Seelie that you try building.
Let's go back over to our editor and start to create some of these different files and folders.
I'm going to first begin by finding my directory inside there, I'll find the Sarsae folder.
So we've already got index dots right there inside of Sarsae.
I'm going to also create a folder called Commands.
And inside there, I'll make a new file called Serve Dots.
All right, so inside of Servatius, as I mentioned, we're going to create a command in the world of
commander, remember this library we're going to use a command is something that describes, well,
as you'd guess, a command that we can invoke from the command line.
But this is the point where, as I mentioned in the last video, we're kind of just going to write out
a little bit of code here rather than trying to dive too deeply into exactly how commander works.
So at the very top, we're going to import something called command.
From commander.
We will then export a variable called Serve Mant.
That's going to be an instance of command.
And we're going to chain on a couple of different method calls to it, these different methods we're
going to chain on are going to customize the command that we are creating and exporting.
So in our case, the first thing we want to do is describe exactly what command we want to watch for.
So we want to watch for a user running the serve command.
Now, if a user ever runs JDBC serve, it's going to try to execute some logic associated with this
command.
I'll then add on a description.
I'm going to put in a description of open a file for editing, you will see where this description is
used in just a moment.
I'll then put on an action method.
This action right here is going to be called whenever a user runs the Gebo Serve Command.
So inside of this function right here is where we're going to put our actual logic to essentially do
something right now.
We'll just add in the console log of getting ready to serve a file.
OK, so that's pretty much it all we need for right now, we are, of course, going to very quickly
come back into this file and add in a lot more functionality.
But this is pretty much the absolute basics.
So now we're going to go back over to our index file, we're going to import the survey command that
we just created and then assemble the stuff into an actual command line tool.
So back inside of my index file.
I'm going to delete that little bit of code that we had added in there previously.
I'll add in an import for program from commander.
I'll add in an import for the reserve command that we just put together.
Well, then do a program, not add manned serve command, so this is where we would associate a bunch
of different commands together if we had any additional commands such as that publish or the other one
login or whatever else, we would chain these on with additional added command statements.
So we would add in something like add command, login, command or publish command or whatever else.
But again, in our case right now, we've only got one command that we really care about.
So we're going to leave.
Ours is just like so.
Then finally at the bottom, the file will right out program pass process RGV.
So this is what is going to tell Mantar to actually take a look at the command line arguments, try
to pass them, figure out what command a user is trying to run and then execute the appropriate command
that we have put together.
You will notice very quickly that we are getting an error right here from process.
That's just because we need to very quickly install a type definition file that typescript is aware
of all the different types provided in the node environment.
So we'll essentially do that right there.
But just remember, we're not going to run NPM install anymore.
Instead, we're going to rely upon Lernout to do the install for us.
So let's go and install that type definition file very quickly.
Back over at my terminal.
I will do a llena ad.
At Type's node.
Dash, dash, dev, because we want to add this is a development dependency and we'll also add on a
scope of Seelie as well.
It's we'll install that really quickly.
And now if we flip back over in a moment or two of the air should go away.
Yep, very good.
If it doesn't go away, you can always just restart your editor.
All right, so that's all we have to do to get a very basic I put together now to run this, we will
go back over to our terminal.
I'm going to make sure that I still got my script running inside of my separate terminal window.
So here's where I did that run start that has our Seelie typescript compiler and the compiler for our
one, our local API as well.
All that stuff in this window, it's definitely all running right now.
So to mentally test all this stuff out, I'm going to change into my packages.
Zeolite directory.
I'll then change into the dist directory, remember, that is where all of our compiled output is placed.
And inside there, I'm going to run that node indexed JS file and I'm going to try to run the server
command in this case.
So when I run that identity, the council log that we put together inside of our command, getting ready
to serve a file.
So in this case, Commander very correctly interpreted that we wanted to run our search command.
And then executed the associated action with it.
The last thing I wanna show you very quickly is where this description comes into play.
Whenever you make use of commander, it is going to automatically generate a help command for you as
well.
So if a user ever runs node indexed dash dash help, it's going to take a look at all the different
commands we have associated with Commander and then print out some help page like this right here.
You'll notice it has automatically taken our CERV command.
And there's where our description is used so user can run our help command right here or put on the
help option and say, OK, there's a search command and here's what it does.
OK, so this is a good step forward, but of course, we still have a lot of functionality to add in
here.
Let's take a pause and continue in just a moment.