1 00:00:06,300 --> 00:00:11,970 So now let's look at how we can accept and use command line arguments. 2 00:00:12,790 --> 00:00:16,300 The first thing we need to do is bring standard. 3 00:00:17,130 --> 00:00:20,640 In var into our scope. 4 00:00:21,060 --> 00:00:27,120 So inside of Main, let's now create a vector called args. 5 00:00:27,120 --> 00:00:37,290 So let args and then we know it's going to be a vector of string and we can say environment that's what 6 00:00:37,290 --> 00:00:46,380 a short for args and then skip one and I'll explain that in a second and then we have a collect iterator 7 00:00:46,380 --> 00:00:46,980 for us. 8 00:00:48,190 --> 00:00:53,770 So we're going to use Skip one because we run our program. 9 00:00:53,770 --> 00:00:56,530 That is actually the first argument. 10 00:00:56,530 --> 00:00:58,270 But we don't want that one. 11 00:00:58,270 --> 00:01:00,340 We want everything that follows our. 12 00:01:01,600 --> 00:01:02,650 Program name. 13 00:01:02,830 --> 00:01:06,340 And that's going to give us the rest of everything else. 14 00:01:06,640 --> 00:01:10,020 So we also know that we want it. 15 00:01:10,270 --> 00:01:11,560 We want for arguments. 16 00:01:11,560 --> 00:01:12,490 We don't want any less. 17 00:01:12,490 --> 00:01:13,900 And we also don't want anymore. 18 00:01:13,900 --> 00:01:16,540 So we want our length. 19 00:01:18,580 --> 00:01:19,790 Basically two equal four. 20 00:01:19,810 --> 00:01:25,960 So if it does not equal four, then we want to print our help out for us. 21 00:01:25,960 --> 00:01:28,570 So now we can remove this. 22 00:01:29,440 --> 00:01:31,840 And now we can also say. 23 00:01:34,100 --> 00:01:38,840 Frontline and we want to provide them a useful error message. 24 00:01:38,840 --> 00:01:48,110 Wrong number of argument is given expected for. 25 00:01:49,450 --> 00:01:52,030 Got another. 26 00:01:53,290 --> 00:01:54,660 Value pressed in. 27 00:01:54,700 --> 00:01:56,020 So we'll say air. 28 00:01:57,750 --> 00:02:03,660 And then we want it to be read and we also want it to be bold. 29 00:02:04,770 --> 00:02:11,100 And then we want to look at how many argument we actually were printed out. 30 00:02:11,460 --> 00:02:17,220 And then if we get to this point, we don't want our process to continue, so we want it to actually 31 00:02:17,220 --> 00:02:17,760 exit. 32 00:02:17,760 --> 00:02:23,160 And then we wanted to exit with air code one, which signifies. 33 00:02:24,340 --> 00:02:24,940 That are. 34 00:02:26,330 --> 00:02:27,680 Program did not. 35 00:02:29,210 --> 00:02:30,560 Run successfully. 36 00:02:31,910 --> 00:02:33,920 So now let's do a couple of runs. 37 00:02:33,920 --> 00:02:38,210 So we'll say cargo run and let's see what it does. 38 00:02:38,390 --> 00:02:40,820 So we see we have find and replace. 39 00:02:42,020 --> 00:02:42,410 Good. 40 00:02:42,410 --> 00:02:48,950 So that was our print help function being called and then we see error wrong number of arguments given 41 00:02:48,950 --> 00:02:58,580 expected four got zero and now we see also our process didn't exit successfully which is right here. 42 00:02:59,300 --> 00:02:59,930 So great. 43 00:02:59,930 --> 00:03:02,750 So we see that it was running correctly. 44 00:03:02,750 --> 00:03:06,980 So now let's try running it and give it four arguments. 45 00:03:06,980 --> 00:03:14,090 So we'll say ARG one or two, ARG three and ARG four and everything. 46 00:03:15,620 --> 00:03:16,880 Ran correctly. 47 00:03:16,880 --> 00:03:22,760 So obviously we don't have the logic in yet to handle our arguments, but this is a great start to our 48 00:03:22,760 --> 00:03:33,380 program and now we know how we can utilize accepting arguments in from the command line and making sure 49 00:03:33,380 --> 00:03:39,380 that they are being stored correctly inside of our argument, our args vector. 50 00:03:39,380 --> 00:03:48,890 So now let's look at how we can actually structure our program correctly and separate all of this logic 51 00:03:48,980 --> 00:03:50,750 into different files. 52 00:03:50,960 --> 00:03:59,120 That way, we only use Main to run our program and not handle all of our core logic.