[Autogenerated] Hello and welcome, welcome to this demonstration,
a demonstration where we're really going to see the power of AK by
implementing an arc script to convert our power W D file into YAML.
Come on, this is going to be really useful.
Now, we have got a little bit of work to do,
but thank you so much in joining me at the command line.
You are really going to thank yourself for putting the effort in now.
But here we are.
Anyway, let's get started.
We are at our pixel playground and we want to convert
our password file through to YAML.
Now, if you have got the co repository,
you can go through and grab the file from your ed an org directory.
And if we look at then our password to YAML dot org, that's about ready for you.
But the problem is if you just copy the file across without any typing,
then you don't really know what's going on.
So let's take a look at at least starting on some of that typing.
Now, you can use any text editor that you want.
You are free.
It is your choice.
I'm just going into VM here and we can go through there and
then create our pass W D two YAML dot A W K.
Now it's a script.
So the first thing that we're going to have in a
script should be really our she.
So let's go through and put forward slash bin arc minus F.
There you go.
Now, we're going to have a begin block in our begin blog.
We open up our brace brackets, we can write it tidally on multiple lines,
but let's indent it for readability.
So we've got our field separator,
our input field separator being the good old colon.
Now, we've used that a lot now.
So we should know the semicolon at the end of the line and then we
can go through and have our print statement.
So this is really header information that we are printing
and it's going to be our users dictionary.
So in quotes, users colon followed by a space,
close off our quotes and close off our brace brackets.
Now, we're ready to dive into uh maine block again, indenting.
And we're going to go into a four loop something we
haven't looked at before within AK,
but we have a condition and we put this with our parentheses and we've got a
variable that we are going to call I I just for an integer.
So whilst I begins on the value of one,
we're going to start with our first field,
ah its a great place to start, isn't it?
And we're going to continue until we don't have any fields left.
So I is less than or equal to the number of fields,
another internal variable that we can use.
Now, we know we have seven fields, but we might as well make use of the,
your variable N F.
In upper case semicolon separates our arguments inside of four.
And then its importantly here, we have to increment our I variable each time.
So we start on field, one field, two, field three and so forth,
close off our parentheses and open up a block of code.
So a new left brace bracket again, indenting just for our readability.
And we're going to go through and put in a switch statement.
We're going to be examining the value of our variable I,
so that goes inside of our parentheses.
But the switch statement itself is a block of code.
So another opening brace bracket indenting just for readability,
we can go through then and start putting the case the value of I,
if that has a value of one, then we can do a whole load of code.
We can write multiple lines of code that we want to do when we're on field one.
Now field one is going to be our list item.
So we use print F and opening up our double quotes.
We follow the double quotes with two spaces.
We want to be indented here two spaces followed by ID dash
indicating this is a list item space and user colon.
This then becomes our list item.
But we want to put a value after this.
So we can go through and start populating that with their
placeholder per percent lowercase S and then a new line
close off our double quotes.
So once we've closed off our double quotes,
we separate our argument with a comma and we read in the value of
our current field that we're working with field one and don't forget
the semicolon at the end of the line.
So this is going to give me my first user that I find from
our password field and it's going to be the user name that's
going to be in the variable.
Now, if we've already matched on field one,
we don't need to process field two or field three in this iteration of our loop.
So we can go through and break.
So we jump out of the switch statement, we'll continue with our four loop.
And then of course, we can interrogate the case of the next field.
If it has a value of two, then we can go through and of course,
print more detail.
So we've got our print F opener quotes and this time it's going to be one,
234 spaces followed by the key.
So that's going to be the password for the second field.
Again, we have our placeholder.
So percent s followed by a new line to populate the placeholder.
Then we go through and specify are comma and dollar I and semicolon.
Now it's hard work.
But at least typing it.
We're getting the understanding of the code that we're writing again,
we can issue the break command to leave the case statement.
Now, we've done everything that we want for field two,
we'll resume then on the next field.
Now I could go through and actually start cutting and pasting data down.
So I could take case two, print F and break and paste it again.
That would then change to case three and being our user ID field.
However, if we've got the idea of our typing,
we can jump out and we can do a slight cheat by
copying across the existing center, an arc file.
I really want you to get some hands on of typing.
That's why we started.
But now we copy that and replace the existing one.
Let me quickly go in and edit it.
We're at the final stage which we don't really need to be.
At the moment.
I'm just going to clear the pattern that I have in front of my brace brackets.
We're going to come back and look at that in a few moments in the next clip.
But for the moment,
we've got everything that we could have typed but would have taken a long
time and will be laborious for you to watch in the video.
But now that we've got everything that we,
we want, we can go through and do you know what we're going to do,
we're going to save our changes.
But this will be printing out all seven of our fields.
We access it with our arc command and the lowercase F to
specify the arc script that we want to read in.
And now we just reference our forward slash E T C and pass W D file,
hit the big entity a hole and look at this glorious YAML data.
That is very easy for us to be able to see the indentation is working for us.
And we can see then that we've got our different users.
But of course,
it's printing their complete file and it's not allowing me to search.
But that's really the idea of the pattern that we can
put in front of our main block.
We're going to come back and take a look at that.
But for the moment,
let's just enjoy our heavy lifting that we've done
so far and enjoy our org file.
Don't think of how much typing there was to it,
think of how much it's creating a glorious report
that you're going to be able to use.