1
00:00:01,310 --> 00:00:06,770
Let's take a look at the pattern that we're going to use for putting our Klyde together, OK, so we

2
00:00:06,830 --> 00:00:09,200
are only going to have one command instead of our project for now.

3
00:00:09,210 --> 00:00:13,550
But regardless, this is a pattern that I still recommend you try following if you are ever adding in

4
00:00:13,550 --> 00:00:15,290
additional commands to a SEELIE.

5
00:00:15,830 --> 00:00:18,200
So we're going to create a folder called the Commands Folder.

6
00:00:18,440 --> 00:00:21,170
Inside there, we're going to create a variety of different files.

7
00:00:21,560 --> 00:00:26,600
Each of these different files is going to describe exactly what to do when a user runs a very particular

8
00:00:26,600 --> 00:00:27,050
command.

9
00:00:27,560 --> 00:00:32,560
So, for example, you and I are going to create a Servatius file inside there.

10
00:00:32,570 --> 00:00:37,040
We're going to write out some logic that says exactly what we want to do whenever one of our users runs

11
00:00:37,040 --> 00:00:38,990
the book, Serve Commands.

12
00:00:39,620 --> 00:00:44,720
If we had any other commands tied to our Seelie, we don't in our case, but I just have these on here

13
00:00:44,720 --> 00:00:46,550
for demonstration purposes.

14
00:00:47,040 --> 00:00:51,620
So, for example, if we had another command called Publish, then we would create a published its file.

15
00:00:51,920 --> 00:00:57,170
And inside that file once again describe exactly what to do whenever a user runs the book published

16
00:00:57,170 --> 00:00:57,590
Command.

17
00:00:58,840 --> 00:01:04,330
Once we build all these different command files, we'll then import them back into a main index file

18
00:01:04,989 --> 00:01:10,750
and inside is where we will assemble all these commands together and describe in total how our works.

19
00:01:11,680 --> 00:01:15,370
So, again, the pattern that we're going to follow in this course, and I recommend you try this out

20
00:01:15,370 --> 00:01:17,980
on your own as well for any Seelie that you try building.

21
00:01:18,850 --> 00:01:22,600
Let's go back over to our editor and start to create some of these different files and folders.

22
00:01:24,030 --> 00:01:28,950
I'm going to first begin by finding my directory inside there, I'll find the Sarsae folder.

23
00:01:29,040 --> 00:01:32,750
So we've already got index dots right there inside of Sarsae.

24
00:01:32,760 --> 00:01:35,160
I'm going to also create a folder called Commands.

25
00:01:37,160 --> 00:01:40,790
And inside there, I'll make a new file called Serve Dots.

26
00:01:43,210 --> 00:01:48,310
All right, so inside of Servatius, as I mentioned, we're going to create a command in the world of

27
00:01:48,310 --> 00:01:53,080
commander, remember this library we're going to use a command is something that describes, well,

28
00:01:53,080 --> 00:01:56,190
as you'd guess, a command that we can invoke from the command line.

29
00:01:56,990 --> 00:02:01,120
But this is the point where, as I mentioned in the last video, we're kind of just going to write out

30
00:02:01,120 --> 00:02:05,590
a little bit of code here rather than trying to dive too deeply into exactly how commander works.

31
00:02:06,430 --> 00:02:09,789
So at the very top, we're going to import something called command.

32
00:02:11,280 --> 00:02:12,390
From commander.

33
00:02:14,980 --> 00:02:18,610
We will then export a variable called Serve Mant.

34
00:02:19,610 --> 00:02:22,100
That's going to be an instance of command.

35
00:02:23,000 --> 00:02:27,320
And we're going to chain on a couple of different method calls to it, these different methods we're

36
00:02:27,320 --> 00:02:31,420
going to chain on are going to customize the command that we are creating and exporting.

37
00:02:31,880 --> 00:02:37,220
So in our case, the first thing we want to do is describe exactly what command we want to watch for.

38
00:02:37,580 --> 00:02:40,330
So we want to watch for a user running the serve command.

39
00:02:40,820 --> 00:02:45,980
Now, if a user ever runs JDBC serve, it's going to try to execute some logic associated with this

40
00:02:45,980 --> 00:02:46,430
command.

41
00:02:47,880 --> 00:02:49,650
I'll then add on a description.

42
00:02:52,520 --> 00:02:59,420
I'm going to put in a description of open a file for editing, you will see where this description is

43
00:02:59,420 --> 00:03:00,340
used in just a moment.

44
00:03:02,360 --> 00:03:04,280
I'll then put on an action method.

45
00:03:06,450 --> 00:03:10,620
This action right here is going to be called whenever a user runs the Gebo Serve Command.

46
00:03:10,930 --> 00:03:15,210
So inside of this function right here is where we're going to put our actual logic to essentially do

47
00:03:15,210 --> 00:03:16,770
something right now.

48
00:03:16,920 --> 00:03:22,110
We'll just add in the console log of getting ready to serve a file.

49
00:03:25,050 --> 00:03:28,740
OK, so that's pretty much it all we need for right now, we are, of course, going to very quickly

50
00:03:28,740 --> 00:03:31,230
come back into this file and add in a lot more functionality.

51
00:03:31,410 --> 00:03:33,300
But this is pretty much the absolute basics.

52
00:03:34,520 --> 00:03:39,020
So now we're going to go back over to our index file, we're going to import the survey command that

53
00:03:39,020 --> 00:03:43,220
we just created and then assemble the stuff into an actual command line tool.

54
00:03:44,880 --> 00:03:47,130
So back inside of my index file.

55
00:03:48,250 --> 00:03:51,310
I'm going to delete that little bit of code that we had added in there previously.

56
00:03:52,970 --> 00:03:56,810
I'll add in an import for program from commander.

57
00:03:57,930 --> 00:04:01,350
I'll add in an import for the reserve command that we just put together.

58
00:04:06,720 --> 00:04:15,390
Well, then do a program, not add manned serve command, so this is where we would associate a bunch

59
00:04:15,390 --> 00:04:21,089
of different commands together if we had any additional commands such as that publish or the other one

60
00:04:21,089 --> 00:04:25,590
login or whatever else, we would chain these on with additional added command statements.

61
00:04:25,890 --> 00:04:31,740
So we would add in something like add command, login, command or publish command or whatever else.

62
00:04:32,040 --> 00:04:35,160
But again, in our case right now, we've only got one command that we really care about.

63
00:04:35,790 --> 00:04:36,510
So we're going to leave.

64
00:04:36,510 --> 00:04:38,190
Ours is just like so.

65
00:04:40,100 --> 00:04:46,160
Then finally at the bottom, the file will right out program pass process RGV.

66
00:04:47,130 --> 00:04:51,620
So this is what is going to tell Mantar to actually take a look at the command line arguments, try

67
00:04:51,620 --> 00:04:56,540
to pass them, figure out what command a user is trying to run and then execute the appropriate command

68
00:04:56,540 --> 00:04:57,340
that we have put together.

69
00:04:58,070 --> 00:05:02,210
You will notice very quickly that we are getting an error right here from process.

70
00:05:02,510 --> 00:05:06,890
That's just because we need to very quickly install a type definition file that typescript is aware

71
00:05:06,890 --> 00:05:09,470
of all the different types provided in the node environment.

72
00:05:10,130 --> 00:05:11,570
So we'll essentially do that right there.

73
00:05:11,570 --> 00:05:14,330
But just remember, we're not going to run NPM install anymore.

74
00:05:14,450 --> 00:05:17,540
Instead, we're going to rely upon Lernout to do the install for us.

75
00:05:18,050 --> 00:05:20,900
So let's go and install that type definition file very quickly.

76
00:05:22,760 --> 00:05:24,020
Back over at my terminal.

77
00:05:25,840 --> 00:05:28,450
I will do a llena ad.

78
00:05:29,540 --> 00:05:31,730
At Type's node.

79
00:05:34,710 --> 00:05:40,710
Dash, dash, dev, because we want to add this is a development dependency and we'll also add on a

80
00:05:40,710 --> 00:05:43,310
scope of Seelie as well.

81
00:05:46,110 --> 00:05:47,550
It's we'll install that really quickly.

82
00:05:49,410 --> 00:05:52,540
And now if we flip back over in a moment or two of the air should go away.

83
00:05:52,630 --> 00:05:53,480
Yep, very good.

84
00:05:53,490 --> 00:05:55,980
If it doesn't go away, you can always just restart your editor.

85
00:05:57,030 --> 00:06:02,190
All right, so that's all we have to do to get a very basic I put together now to run this, we will

86
00:06:02,190 --> 00:06:03,720
go back over to our terminal.

87
00:06:04,360 --> 00:06:08,430
I'm going to make sure that I still got my script running inside of my separate terminal window.

88
00:06:08,430 --> 00:06:15,870
So here's where I did that run start that has our Seelie typescript compiler and the compiler for our

89
00:06:16,200 --> 00:06:18,210
one, our local API as well.

90
00:06:18,210 --> 00:06:20,820
All that stuff in this window, it's definitely all running right now.

91
00:06:21,300 --> 00:06:25,230
So to mentally test all this stuff out, I'm going to change into my packages.

92
00:06:25,620 --> 00:06:26,550
Zeolite directory.

93
00:06:28,960 --> 00:06:34,720
I'll then change into the dist directory, remember, that is where all of our compiled output is placed.

94
00:06:35,600 --> 00:06:41,060
And inside there, I'm going to run that node indexed JS file and I'm going to try to run the server

95
00:06:41,060 --> 00:06:42,130
command in this case.

96
00:06:42,860 --> 00:06:47,360
So when I run that identity, the council log that we put together inside of our command, getting ready

97
00:06:47,360 --> 00:06:48,500
to serve a file.

98
00:06:49,430 --> 00:06:54,740
So in this case, Commander very correctly interpreted that we wanted to run our search command.

99
00:06:57,330 --> 00:06:59,940
And then executed the associated action with it.

100
00:07:00,870 --> 00:07:03,960
The last thing I wanna show you very quickly is where this description comes into play.

101
00:07:04,500 --> 00:07:08,610
Whenever you make use of commander, it is going to automatically generate a help command for you as

102
00:07:08,610 --> 00:07:08,910
well.

103
00:07:09,300 --> 00:07:15,720
So if a user ever runs node indexed dash dash help, it's going to take a look at all the different

104
00:07:15,720 --> 00:07:20,490
commands we have associated with Commander and then print out some help page like this right here.

105
00:07:20,840 --> 00:07:23,280
You'll notice it has automatically taken our CERV command.

106
00:07:24,210 --> 00:07:29,250
And there's where our description is used so user can run our help command right here or put on the

107
00:07:29,250 --> 00:07:33,120
help option and say, OK, there's a search command and here's what it does.

108
00:07:34,890 --> 00:07:39,060
OK, so this is a good step forward, but of course, we still have a lot of functionality to add in

109
00:07:39,060 --> 00:07:39,400
here.

110
00:07:39,780 --> 00:07:41,990
Let's take a pause and continue in just a moment.

