1
00:00:01,850 --> 00:00:08,300
So one thing we want to take care of before we can go live with this is to change the hard coded values

2
00:00:08,300 --> 00:00:13,240
we have in our application to be read instead from command line flags.

3
00:00:13,490 --> 00:00:19,400
So instead of running our application, as we do right now, so if we look at our run file, run S.H.,

4
00:00:19,700 --> 00:00:25,010
instead of just running bookings, we're going to pass things like Debe name equals and then the database

5
00:00:25,010 --> 00:00:30,560
name, which would be bookings and user, which would be, in my case, TC's and some other things as

6
00:00:30,560 --> 00:00:30,880
well.

7
00:00:31,460 --> 00:00:33,590
And we're going to do that in our main Dargo.

8
00:00:34,220 --> 00:00:41,090
So for example, right here in the run function of our main Digo, I have app in production equals fault's

9
00:00:41,420 --> 00:00:42,590
with the note to myself.

10
00:00:42,590 --> 00:00:44,990
Changed this to true when in production.

11
00:00:45,020 --> 00:00:46,010
Well I don't want to do that.

12
00:00:46,010 --> 00:00:47,960
I don't want to recompile my application.

13
00:00:48,890 --> 00:00:53,090
One version for local development and another version for production environments.

14
00:00:53,240 --> 00:00:58,610
Instead, I want to read those values from the command line when I start the application and I'm going

15
00:00:58,610 --> 00:01:02,760
to do that right here just after I register things for the session.

16
00:01:02,780 --> 00:01:09,020
So in here I'll say red flags and obviously the first one I want is in production.

17
00:01:09,020 --> 00:01:14,300
So I'll create a variable in production and I'll sign that the value of and this is a built in package

18
00:01:14,300 --> 00:01:16,250
in the standard library Fleg.

19
00:01:17,000 --> 00:01:25,070
And I'm going to read the type of argument I'm going to read from the command line Izabel and the value

20
00:01:25,070 --> 00:01:26,840
I'm going to look for is production.

21
00:01:27,260 --> 00:01:28,970
So that's what I'll be typing with.

22
00:01:28,970 --> 00:01:35,030
A hyphen are like dash production equals true or false from the command line that will have a default

23
00:01:35,030 --> 00:01:36,850
value of true.

24
00:01:36,890 --> 00:01:41,090
So if you don't specify it, it will be set to true to be in production, which is always safe, or

25
00:01:41,100 --> 00:01:45,440
you don't want to accidentally set something into development mode on a live server.

26
00:01:45,830 --> 00:01:51,860
And then just the note that tells the user what the flag is for application is in production.

27
00:01:54,150 --> 00:01:55,650
So that's the first value I want.

28
00:01:55,970 --> 00:01:57,670
The second one is our cash.

29
00:01:57,680 --> 00:01:59,710
Are we going to cash our templates or not?

30
00:01:59,720 --> 00:02:07,010
So I'll just call this use cache and the command line flag will be cache.

31
00:02:07,010 --> 00:02:08,420
The default will be true.

32
00:02:08,900 --> 00:02:14,840
And the note to the user will be cache templates or use template cache.

33
00:02:17,720 --> 00:02:19,720
OK, so we have two variables right now.

34
00:02:19,730 --> 00:02:21,500
One for in production and one for true.

35
00:02:21,930 --> 00:02:26,750
Now, the next thing I want of course, is to specify my database information because again, I don't

36
00:02:26,750 --> 00:02:29,120
want a hard code that into the application.

37
00:02:29,690 --> 00:02:33,680
So we need the DB name, the name of the database.

38
00:02:34,010 --> 00:02:42,310
That will be a flag string and we'll call this one DB name and we'll have no default value for that.

39
00:02:42,320 --> 00:02:50,900
We'll make that a required field and we'll just put the note database name and the database user DB

40
00:02:50,930 --> 00:02:51,500
user.

41
00:02:54,350 --> 00:02:58,790
Database user, the password Debe Pass.

42
00:03:02,680 --> 00:03:11,320
Password, and we also want the port divi port, and I'll use that as a string, even though it's it's

43
00:03:11,320 --> 00:03:14,250
a numeric value is string is fine for this case.

44
00:03:14,740 --> 00:03:17,350
So I call this DB port.

45
00:03:18,070 --> 00:03:21,370
I just to be consistent, I'll make everything lowercase for the flags.

46
00:03:23,260 --> 00:03:29,020
So D.V. Port and I'm going to add one more here as well, which we haven't used yet, but in production,

47
00:03:29,020 --> 00:03:33,790
quite often your connection to the database is using an SSL certificate.

48
00:03:33,790 --> 00:03:40,900
So we'll specify DB, SSL and we'll make that have a default value of disable just so I don't have to

49
00:03:40,900 --> 00:03:42,570
retype it or put a command line.

50
00:03:42,580 --> 00:03:45,400
Feigin So database SSL settings

51
00:03:48,520 --> 00:03:56,020
and for postgrads the possible values are disable, which will be the default prefer using SSL certificate

52
00:03:56,290 --> 00:03:58,780
if it exists or require.

53
00:03:58,840 --> 00:04:02,290
Don't start unless you have an SSL certificate on the database server.

54
00:04:03,430 --> 00:04:08,290
Now other things I'm going to put in here, I'll make the database port default to five, four, three,

55
00:04:08,290 --> 00:04:13,270
two and I'll make the database host, which I didn't specify yet.

56
00:04:13,270 --> 00:04:14,200
So I better do that.

57
00:04:15,070 --> 00:04:19,480
We need to have a DB host, DB host.

58
00:04:20,260 --> 00:04:27,700
I'll just default that to localhost database post because sometimes you don't have the database on the

59
00:04:27,700 --> 00:04:30,280
same machine as your application server.

60
00:04:30,280 --> 00:04:35,860
Actually in production you rarely have the database on the same server as your your web app.

61
00:04:35,950 --> 00:04:39,540
So that would be in a different host and you need to be able to specify that.

62
00:04:39,550 --> 00:04:44,500
So I've got those all specified right now and they exist and they exist as pointers because that's how

63
00:04:44,500 --> 00:04:46,110
things are run from the command line.

64
00:04:46,990 --> 00:04:52,180
But before I can do anything with those at all, I have to call flag dot pers.

65
00:04:53,080 --> 00:04:58,210
Now, these values will actually be passed and they'll be useful to our application.

66
00:04:59,200 --> 00:05:02,020
So now that I have these specified, I can make a few changes.

67
00:05:02,020 --> 00:05:08,020
So for example, instead of saying APTA introduction equals false, I can just say DOT in production

68
00:05:08,590 --> 00:05:17,320
is equal to because it's a pointer pointer in production and I can do the same thing for app to use

69
00:05:17,320 --> 00:05:17,920
cash.

70
00:05:18,890 --> 00:05:24,560
I think it's called use cash, yes, and the variable in this case is use cash.

71
00:05:26,030 --> 00:05:28,280
Now, do I have that anywhere down here?

72
00:05:29,610 --> 00:05:31,260
Yes, so I need to get rid of this.

73
00:05:33,240 --> 00:05:36,400
So those are set up now, what about our database stuff?

74
00:05:36,420 --> 00:05:37,790
Well, that's all right here.

75
00:05:37,800 --> 00:05:42,930
So instead of just passing a string in like this, let's create a new string, a new variable called

76
00:05:42,930 --> 00:05:43,620
connection string,

77
00:05:46,590 --> 00:05:51,660
and that will be assigned the value of the format as predictive.

78
00:05:52,830 --> 00:05:54,720
And it will be the same thing we have here.

79
00:05:54,750 --> 00:05:58,560
So let me just copy this, but with placeholders.

80
00:06:01,730 --> 00:06:10,250
And I guess I got an extra quote in there that looks better and we're going to put in the very first

81
00:06:10,250 --> 00:06:14,210
thing will be a string, which will be TV host.

82
00:06:14,870 --> 00:06:22,340
So I have to use the star because it's a pointer DB host, and the next thing will be the port.

83
00:06:27,870 --> 00:06:31,500
Do you report and then the DB name?

84
00:06:37,010 --> 00:06:38,300
And then the TV user.

85
00:06:43,430 --> 00:06:44,540
And then the password.

86
00:06:49,670 --> 00:06:53,270
And then the one we just added, which is called SSL mode

87
00:06:56,360 --> 00:06:59,350
along the line, but not much I can do about it.

88
00:07:03,380 --> 00:07:08,880
All right, so that's our connection string now we'll just replace this with connection string.

89
00:07:09,870 --> 00:07:17,960
OK, so if this works properly, we should be able to specify all of the necessary connection, strings

90
00:07:17,960 --> 00:07:21,220
or command line parameters in our run DSH.

91
00:07:21,890 --> 00:07:23,060
So let's put those in there.

92
00:07:23,060 --> 00:07:28,220
So we have D.V. name, we have DBI user will say cache equals fault's.

93
00:07:28,580 --> 00:07:32,810
There's no Comus will say production equals faults.

94
00:07:33,890 --> 00:07:37,250
And we have the DB name, we have the user.

95
00:07:37,610 --> 00:07:38,780
That should be enough.

96
00:07:38,810 --> 00:07:44,510
Now there's one other thing I want to add here, and that is what if you try to start the application

97
00:07:44,510 --> 00:07:49,070
but you haven't specified all of the necessary required parameters?

98
00:07:49,100 --> 00:07:52,640
Well, we can do that right here after we pass our flag.

99
00:07:53,660 --> 00:07:56,150
So DB Pass looks like I missed something here.

100
00:07:56,160 --> 00:07:59,090
Do user to be poor TB's so password's.

101
00:07:59,090 --> 00:08:02,570
So one, two, three, four, five.

102
00:08:02,750 --> 00:08:05,840
One, two, three, four, five.

103
00:08:05,860 --> 00:08:09,740
Oh should be do doing pass by.

104
00:08:09,740 --> 00:08:11,990
Idy helpfully told me that I missed a variable.

105
00:08:11,990 --> 00:08:12,970
So that's those.

106
00:08:13,220 --> 00:08:14,750
Those should all be correct now.

107
00:08:14,750 --> 00:08:20,360
But after we pass the flag right here, let's make sure that they've specified all of the necessary

108
00:08:21,650 --> 00:08:22,790
required flags.

109
00:08:22,790 --> 00:08:31,220
So if you need to have DB name, so DB name is equal to nothing or.

110
00:08:31,610 --> 00:08:33,030
And what are the required flags.

111
00:08:33,050 --> 00:08:36,320
Do we have here db user DB pass.

112
00:08:36,320 --> 00:08:40,520
We can leave empty because we don't have a password in our production environment or development environment.

113
00:08:41,410 --> 00:08:45,590
I think the only other one we need is our DB user.

114
00:08:48,950 --> 00:09:00,050
If that's equal to nothing, then format that print line missing, required flags and then will just

115
00:09:00,050 --> 00:09:00,440
exit.

116
00:09:05,890 --> 00:09:08,330
With a code of one that should stop the application.

117
00:09:08,800 --> 00:09:13,300
So if I try running this right now, first of all, let's just get rid of these parameters that we specified

118
00:09:13,310 --> 00:09:14,440
and we'll see what happens.

119
00:09:14,470 --> 00:09:15,520
So let me cut those.

120
00:09:15,550 --> 00:09:17,320
So they're on the clipboard and I won't lose them.

121
00:09:17,770 --> 00:09:18,910
And let's try running this

122
00:09:22,540 --> 00:09:23,230
in the right direction.

123
00:09:23,260 --> 00:09:24,310
I am so run.

124
00:09:26,740 --> 00:09:29,530
And it should say missing required flags, and it does.

125
00:09:29,680 --> 00:09:31,090
Now let's go paste them back in

126
00:09:35,080 --> 00:09:39,040
and try writing it again and there it is running.

127
00:09:39,310 --> 00:09:41,770
We're all connected in the database, so let's make sure it works.

128
00:09:49,160 --> 00:09:54,630
And go to localhost 80, 80, and it works.

129
00:09:54,650 --> 00:09:55,460
Can I log in?

130
00:10:01,540 --> 00:10:07,500
And I can and I should see things on the dashboard, and I do perfect.

131
00:10:07,810 --> 00:10:15,310
OK, so now we can just by changing our run script, we can have our product or our code run in properly

132
00:10:15,310 --> 00:10:18,760
in production, and we can have our code run properly in our development environment.

133
00:10:18,940 --> 00:10:22,930
And that makes a lot more sense than hard coding things into our source code.
