All right.
So welcome back.
In our previous programs we wrote these values inside the program.
So the value for zero and this value which is the new make.
So these two could be variables in our case.
So let's say you have an other interface which is not named Zero and you want to change the MAC address
for this interface.
And what do you do.
So we want to make this program in a way that it is reliable and it can work with any interface and
it can set any value that we want.
So we will use flags to build a command line application.
And now this command line application will help us to change these values or set these values.
So the first thing we will require is the flag module.
So we will create a new variable called interface and then we will use the flag module so we can say
flag dot string.
And now what I want to do is I want to provide these idiots as you know and the new Mac as a command
line argument so you can see that if you check their documentation and you can see that it has two values
name which is String value which is string and then usage how do you want to use it.
It's it's also a string and it returns a string quintet.
So let's define first to what is our name.
So we want to name our interface as a face.
So this will be the value of variable we will provide in the command line and then the value.
So let's say we have the default value to EDI it's zero.
So that if we don't provide any interface it will take it as you do as a default value for interface
and then we will provide the usage are the health message.
So we can say that this would be the interface for which you want change to Mac.
So now we have one variable called interface.
So now you want to create another form of this MAC address.
So I'm just going to copy and paste this new line and here.
Now let's call this as the new Mac.
So the variable name would be the new Mac and its value.
Let's say we don't provide any default value for this one and then its usage would be the whole wide
the new mac address.
And then since this function returns a pointer.
So actually before going forward let's change this interface into a new Mac and the last thing we will
do is we will pass these flags so we can have flags start bars and it will automatically pass these
values and store these values in these two variables.
Now we have to use these variables here.
So instead of idiots you know we can say that pointer to the pointer to interface because remember this
this returns a pointer.
So we will use if we want to use its value.
So we use a reference operator which is stop and similarly we will call the interface here and interface
here.
And also we will change this value to numeric.
So now if we want to run this program we can simply say go run be to change Mac and let's see what happens
if we don't provide any interface.
You can see that since we did not provide the new mac address.
It says that cannot assign requested address because we did not provide any interface value here
okay so let's uh just for testing purposes let's Subaru the default value as well for this interface.
And let's see what happens and you can see that we've print out an Arab card at our value getting interface
flags so no such device.
Now you can see that it does that.
It knows that we did not provide any interface.
So let's just run this again.
And now we will provide the values.
So the first variable is called interface so we can see Iris equals two.
And then we will write idiot zero.
So this dash interface means that we are providing the value for this variable which is this one.
And then similarly we can write numeric equals to 0 0 1 1 2 2 3 2 4 4 4.
And now instead of 5 5 let's say we want 6 6.
OK so let's press enter and you know you can see that the command ran successfully.
So now if you go to the terminal and rights who do you have config and provide the password.
Now you can see that the value of E3 0 0 1 1 2 2 3 2 4 4.
And then at the end it is 6 6 which means that this come on line perfectly.
So in this way you can provide the command line arguments.
So one further thing we can do is note that this is currently a Go file.
So if I listed you can see we have to go files P1 down in command and then we change.
So we are interested in this.
So what I will do here is that I will try to build an executable.
So we will build an executable for Linux machine and this executable will contain everything bundled
together.
So even let's see if there is no compiler on your copy machine how to go you will still be able to run
this executable because it will have on the dependencies included.
So in order to create an executable we can simply go on go build and then we'll provide the file name
so let's check it and let's list this again.
And now you can see we have a new file called to change Mac.
And now this is an executable so let's clear it.
And if I list minus L you can see that this last tag is X which means that it is an executable.
So in order to run this executable we can write dot slash B2 and you can see that if you press tab it
automatically selects this one and note that there is no dot go extension at the end.
And we have to provide the same commands here.
So let's just copy it from here
and paste it to so now instead of 6 6 I will write it and you can see that it ran successfully.
Now if I run this come on here again you can see that our updated MAC address is 0 0 1 1 2 2 3 2 4 4
and then edit.
So this means that our executive will is standing successfully and now even if we chip this executable
to some other machine which it does not have go installed this will still work because it contains all
the bindings included inside it.
Okay.
So this is how you can create and execute a well and also pass the command line flags.
So I'm going to stop here in the next lecture will proceed for the.