1
00:00:01,200 --> 00:00:05,130
We've now got a pretty reasonable set up with Lerner inside of a project, so we're not going to turn

2
00:00:05,130 --> 00:00:08,810
our attention back over to actually implementing different portions of our app.

3
00:00:09,630 --> 00:00:14,850
The first portion that we're going to focus on is the so remember, our Seelie is going to be a program

4
00:00:15,120 --> 00:00:17,280
that we want a user to run from their terminal.

5
00:00:17,610 --> 00:00:22,350
So at some point in time, we're going to expect user to run a command like daybook server or something

6
00:00:22,350 --> 00:00:22,950
very similar.

7
00:00:23,340 --> 00:00:28,560
When a user runs this command, we're going to run the code inside of our CLIA package.

8
00:00:28,950 --> 00:00:32,549
And inside that package, we're going to have some amount of code that is going to start up our local

9
00:00:32,549 --> 00:00:33,330
API.

10
00:00:34,230 --> 00:00:39,870
Now, you might recall that whenever we run JDBC Reserve, we might also want to allow a couple of optional

11
00:00:39,870 --> 00:00:41,950
arguments to be passed along with his command as well.

12
00:00:42,510 --> 00:00:47,880
So, for example, remember, we have said that whenever a user starts to change some cells inside the

13
00:00:47,880 --> 00:00:52,950
browser, we want to somehow take that information, take that text, take that code and persistent

14
00:00:52,950 --> 00:00:54,590
to a file on the user's hard drive.

15
00:00:54,900 --> 00:00:59,610
And we have said specifically that we want to save it into a file so the user can very easily share

16
00:00:59,610 --> 00:01:02,700
that file with other people or committed to get or whatever else.

17
00:01:03,540 --> 00:01:08,820
So as a part of our Seelie, we might want to allow a user to specify exactly what file they want to

18
00:01:08,820 --> 00:01:12,740
open up to get a list of cells from or to save cells into.

19
00:01:13,440 --> 00:01:18,660
So we might want to allow a little variance on this command, maybe something like JDBC serve and then

20
00:01:18,660 --> 00:01:21,390
some file name like say, maybe notebook.

21
00:01:22,830 --> 00:01:27,870
So if a user ran this command, that would mean that we would want to open up the notebook as file inside

22
00:01:27,870 --> 00:01:31,230
the current directory, see if there is already a list of cells saved in there.

23
00:01:31,500 --> 00:01:36,900
And then otherwise, if a user ever changes any code or text inside the browser, we're going to save

24
00:01:36,900 --> 00:01:39,810
the list of cells back into this notebook as file.

25
00:01:40,440 --> 00:01:43,490
And remember, there's nothing special about the name notebook's.

26
00:01:43,860 --> 00:01:47,150
This can be any JavaScript file name that we can possibly imagine.

27
00:01:47,160 --> 00:01:51,060
So it can be notebook or book or my notes or whatever else.

28
00:01:53,050 --> 00:01:58,330
In addition, there's another variant to the book of command that we might want to enable whenever we

29
00:01:58,330 --> 00:01:59,150
run this command.

30
00:01:59,170 --> 00:02:03,580
We're going to start up that local API, which is going to be the server that is going to actually save

31
00:02:03,580 --> 00:02:10,479
information into this my notes file or whatever we end up calling it, that local API has to be running

32
00:02:10,479 --> 00:02:13,840
or listening for traffic on a very specific port on the user's machine.

33
00:02:14,200 --> 00:02:16,900
And maybe we want to allow a user to customize that port.

34
00:02:17,320 --> 00:02:23,910
So maybe another variant of this book server command would be something like my notes, James Dash Dash

35
00:02:23,920 --> 00:02:28,000
Port and then the port that the user wants to run the local API on.

36
00:02:28,090 --> 00:02:34,210
So in this case, we would start up the local API on 30 50 instead of whatever default we decide to

37
00:02:34,210 --> 00:02:34,600
use.

38
00:02:35,670 --> 00:02:40,380
So at this point time, I'm trying to kind of communicate here is to say there are several different

39
00:02:40,380 --> 00:02:44,250
variants of the books of command that we eventually want to implement.

40
00:02:44,620 --> 00:02:50,760
We want to allow Gebo excerpt to be ran by itself with a file name, with a file name and a port, and

41
00:02:50,760 --> 00:02:52,860
maybe also with just a port by itself.

42
00:02:53,200 --> 00:03:00,060
So something like daybook serve Port 30 50 so that we've got many different variants of this command.

43
00:03:00,720 --> 00:03:05,520
So whenever we start to run our Seelie, we need to figure out how to read in these different command

44
00:03:05,520 --> 00:03:08,970
line arguments and then customize our program in a very specific way.

45
00:03:10,100 --> 00:03:13,940
So to understand how to read in command line arguments, this might be something you are already familiar

46
00:03:13,940 --> 00:03:16,490
with, but let me just give you a very, very quick reminder.

47
00:03:16,850 --> 00:03:23,080
We're going to do a very quick little test here back inside of my coat, Ed. I'm going to find my route

48
00:03:23,090 --> 00:03:24,110
project directory.

49
00:03:24,110 --> 00:03:27,300
And inside there, I'm going to make a new file called Test.

50
00:03:29,490 --> 00:03:39,180
Inside this file, I'm going to add in one line of code UNCLOG process, dot RGV process is an array

51
00:03:39,180 --> 00:03:39,870
of strings.

52
00:03:40,170 --> 00:03:45,120
Inside of that array is a list of all the different options that are provided to our program whenever

53
00:03:45,120 --> 00:03:46,250
we run this test.

54
00:03:46,290 --> 00:03:51,600
JS file process is automatically provided to us by node itself.

55
00:03:52,430 --> 00:03:57,110
Let's save this file very quickly and then going to go back over to my terminal and try to run this

56
00:03:57,110 --> 00:03:59,000
file with a couple of come in line arguments.

57
00:04:01,090 --> 00:04:10,510
OK, so there's the test case file, I'll do a node asks and I'm going to add in my notes and dash dash

58
00:04:10,510 --> 00:04:12,730
port 30 50 like so.

59
00:04:14,460 --> 00:04:21,510
Now, when I run this, I'll see the contents of that process array, the first line right here is the

60
00:04:21,510 --> 00:04:23,760
path to the node executable on your machine.

61
00:04:24,370 --> 00:04:30,630
The second element, I should say, the first element, the element at index one is the path to the

62
00:04:30,630 --> 00:04:31,710
file that we executed.

63
00:04:32,400 --> 00:04:35,930
And then we were given a list of all the other command line arguments that are provided to us.

64
00:04:36,540 --> 00:04:41,310
So you and I could try to write out a little bit of code that takes a look at these different elements

65
00:04:41,310 --> 00:04:45,180
right here and then use these different elements to customize how our program works.

66
00:04:45,630 --> 00:04:50,930
So if we have some file mentioned right here, clearly that would mean that we want to open up the my

67
00:04:50,940 --> 00:04:54,600
notes, not just file and find a list of cells in there or something like that.

68
00:04:55,080 --> 00:04:59,790
And then if we see the dash dash port, we could try to find the number right after it and make sure

69
00:04:59,790 --> 00:05:01,750
that our API listens on that port.

70
00:05:02,550 --> 00:05:07,440
Now, we could definitely try to write out all this logic ourselves to look at this process, the array.

71
00:05:07,680 --> 00:05:10,230
But we would very quickly get into a little bit of trouble.

72
00:05:10,740 --> 00:05:16,350
Remember that in general, there are several different kind of assumed variations of many different

73
00:05:16,350 --> 00:05:19,590
commands that a lot of different engineers are going to assume just work.

74
00:05:19,950 --> 00:05:28,830
So, for example, many engineers would assume that Dashty support space 30 50 is equivalent to 40 equals

75
00:05:29,010 --> 00:05:29,760
30 50.

76
00:05:30,620 --> 00:05:35,110
But if I run that, that dramatically changes the process, aragvi array.

77
00:05:35,680 --> 00:05:40,370
So if we were going to manually process this array right here, we would have to kind of accommodate

78
00:05:40,370 --> 00:05:44,590
or write out some logic to accommodate for the two different variations of providing aiport option.

79
00:05:45,320 --> 00:05:50,300
In addition, many engineers generally assume that you might be able to provide different options in

80
00:05:50,300 --> 00:05:52,460
any order when you are running a command.

81
00:05:52,850 --> 00:05:57,920
So, for example, another engineer might assume that they could put in a dash dash port right there

82
00:05:58,370 --> 00:06:01,520
of 30 50 and then the name of the file they want to open.

83
00:06:02,710 --> 00:06:09,460
Well, if we run that once again, the order of the process RGV array has changed and again, we probably

84
00:06:09,460 --> 00:06:13,840
don't want to have to write out really exhaustive logic to figure out all these different variations

85
00:06:13,840 --> 00:06:20,650
of order rather than trying to write out our own custom man line implementation and try to read in all

86
00:06:20,650 --> 00:06:23,740
the different variations of mainline arguments.

87
00:06:23,770 --> 00:06:26,170
We're going to instead use a library to do it for us.

88
00:06:26,900 --> 00:06:31,210
The library we are going to use is called Commander and we actually already installed that into our

89
00:06:31,210 --> 00:06:33,850
Seelie project a little bit ago using llena.

90
00:06:35,510 --> 00:06:40,150
So let's go take a look at some documentation around, Commander, very quickly, back inside my browser,

91
00:06:40,580 --> 00:06:44,750
I'm going to go to NPM Jase's Dotcom and search for commander.

92
00:06:49,120 --> 00:06:54,220
This is a library that is all about helping you build out command line interfaces, so pretty much doing

93
00:06:54,220 --> 00:06:57,020
exactly what we just described, reading in different commands.

94
00:06:57,040 --> 00:07:00,010
We're trying to run and then reading in different options we might provide.

95
00:07:00,520 --> 00:07:03,340
If you want to, you can take a quick look at the documentation here.

96
00:07:03,370 --> 00:07:08,020
But I'm going to be honest with you, there is a tremendous amount of documentation and it's rather

97
00:07:08,020 --> 00:07:10,390
challenging to read through all of it in one go.

98
00:07:10,840 --> 00:07:15,370
So this is one of those scenarios inside this course where we're going to come back the next video and

99
00:07:15,370 --> 00:07:18,300
we're pretty much just going to say, hey, here's how you make use of commander.

100
00:07:18,340 --> 00:07:20,410
So we're not really going to focus too much on the documentation.

101
00:07:20,440 --> 00:07:24,130
I'm just going to give you a very direct explanation of do exactly this.

102
00:07:24,130 --> 00:07:27,670
Here's a good pattern to follow, and we're pretty much going to run with that.

103
00:07:28,600 --> 00:07:33,640
OK, so the last thing I want to do is just very quickly go back over to my editor and delete that test

104
00:07:34,240 --> 00:07:34,570
file.

105
00:07:36,200 --> 00:07:37,580
All right, so let's take a pause right here.

106
00:07:37,580 --> 00:07:41,690
When we come back in just a moment, we'll start writing out some code inside of our Seelie package.

