 Hello, everybody. Thank you for coming. It's great to see so many of you here. To say a little bit more about myself, I am a software engineer working at Red Hat. However, you can see me as more as an open source enthusiast right now, and of course, a scripting fan. So what can you expect to get to learn when you leave? So nowadays, we still write batch scripts. There is still a huge interest to write them. However, let's say the means how to write them, they almost haven't changed. So in the beginning, I will kind of try to get us on the same page. What does a good script mean in practice? How a script that meets expectations should look like. Then I will propose some theoretical way how to do it. And finally, we will have an exciting live demo. So it will hopefully convince you that writing is 20th century and generating is the way to go. So to summarize, we all use those command line apps because they are easy to script. It's very fast to execute what you want. So let's check out how can we use command line utilities. So we all use, for example, the LS command. And what is the difference between the first, second and third invocation here? The answer is there is no difference for the command itself. The forms are different, but LS does always the same thing. So we can say dash L, space, dash A, space, dash W, space 10, which means long output, ignore obvious files that are there in the listing that LS does. Limit the width of the output to 10 columns. And then list contents of directory dash X, directory full, directory bar. The green arguments are called optional because it's usually an option, which is like this dash something. And option might or may not be succeeded by a value. Like dash W10, it's an optional argument with value 10. And there are positional arguments that follow. On the second invocation, we see that we can connect two optional arguments into, let's say, one group. And we can glue the value to the option. So the parsing logic of LS is supposed to handle this. And we kind of use it. Some of you definitely do. Finally, in the last row, we see that we can limit or we can terminate the optional part of the script. And what follows will not be interpreted as options. So if we want to list the directory dash X, we don't have to escape it anymore. And again, when you write some scripts that are supposed to be used by command line, of course, then good-behaved scripts is supposed to behave that way. How is it called? It is called POSIX standard, which is a little bit old. However, if you managed to get your hands on some books that are depicted here, I got them via the humble bundle. So it was not so expensive. Then this is what you will learn. That the good command line interface looks like this. And you are supposed to use utilities. Get up, get up to implement it. However, the world has changed since then quite significantly, I would say. And there is one more standard that is shaping how we use base scripts. And this is called the GNU standard. And what it introduced. It introduced long options. So you write dash dash and something descriptive. Something what people can read and what helps the readability of what goes on when the script is executed. Moreover, you are now allowed, which the POSIX standard doesn't allow that. But GNU standard allows mixing of positional and optional arguments, which means that the LS command will interpret who as a directory and bar also as a directory and it won't complain. So this is the GNU standard. This is not like what the POSIX standard says. So what can I do? I can specify this dash dash long option equals something, dash dash long option space, something. And I can all do the stuff, which is defined by POSIX, which means gluing arguments with values together. So if you write a well-behaved shell script, now we know that it means some hard data that a good-behaved script confirms to the GNU standard, which means that it also confirms to the POSIX standard, let's say, in some ways. So in other languages, we have like a supportive network of tools that will help us to implement this logic. And Bech is not here on the list. So what do we do when we want to learn how to write good Bech scripts that are so nice to use? Well, we ask, of course. And this is a slide from 2017. We see that the question of Stack Overflow is quite popular. And now we have 2019. And the amount of upvotes went up almost like by the days, almost two times as much upvotes as there was. So this is a very good question, apparently. What is the answer? It has even more upvotes, or it had even more upvotes in 2017. And the accepted upvoted answer said, write the parsing logic of your script in pure Bech. What has changed? Changed that 1,000 of upvotes actually were added, let's say, which means that it's topic which is live, it's relevant, and people somehow are satisfied with that answer, which is totally crazy. Because why should you write something in Bech if you can generate it? If you check out other resources, they will tell you the same. This is not some cherry-picked example. It's really what you will find on, like, knowledge basis. So why is it? Why is the answer in such a way? So other languages have modules. Bech doesn't have any standard library. Bech doesn't have packaging. So if you have a parsing module, like a parsing library, you would have to bundle it with your script. So you have 10-line script and 1,000-line library bundled with that. How does it sound? Terrible, right? So this is why we don't use modules. Yeah, over there are modules, of course, but they are poorly documented, and sometimes they are not portable. Big problem. Built-ins. What is a built-in? This is get-opt. If you write Bech scripts, you probably know that such a tools exist. So get-opt is Bech built-in. It's okay to use it, but it provides you only these capabilities to have a POSIX interface, not the GNU interface. So it means that it's not so convenient to use your script if you use get-opt. If you use get-opt without S, then it might work nicely, and it might not work nicely because get-opt is not portable. It has different versions on different platforms. You never know what will happen. So, yeah, and, moreover, you have help message in your script. You have one page. You have mesh completion. All somehow reflects the interface that your script has, like what arguments it accepts, and you have to repeat it all over again. So don't repeat it. Generate it. This is what I would say. So why people don't like generators? You have to install them. They might have dependencies. Difficult to uninstall. Your system is tainted after you try to remove them, and you don't know that everything got removed successfully. Then, of course, you generate something, but then the generator is updated. You change your mind. You need to regenerate again. And the question is, do you really need to save your template with the source that you fed to the generator? What if you don't have it? What if it's not compatible anymore? Et cetera. This is the worry number two that people have when talking about generators. And worry number three is generated code. It's usually bad code. You can't read it. If it's not good, you can't just go into it and fix it because it's complicated and minified sometimes if you talk about JavaScript generators. So this is concern number three. And concern number four might be I don't want to use a module. I don't want a thousand-line module to bundle this might in line script. So the code generator should do a good job. It should not produce a thousand-line generated code. Otherwise, I would use the module and there is not a big deal. So this is why the ErgMesh project started. And it has, it addresses those concerns quite robustly, I would say. So it works in such a way that the generated script is a template by itself. So you can use a generated script to generate new script out of it. It's in-potent, of course. So if you have generated script, you can generate with the same ErgMesh. It's the same. But you can, of course, generate when ErgMesh is upgraded. You can generate when you change your mind about some, let's say, options of your script. Then you can install it if you are lucky enough to have Fedora. ErgMesh is in AUR in Arch Linux. And it has auto-conf as a dependency so you can even the RISC GitHub install. Aside from that, there is a bi-popular demand, the rocker image of ErgMesh. It's quite crazy, but people seem to like it. I don't understand that, but why not? And there is also a web interface for the generator. Apart from that, of course, I already mentioned some possibilities for the generator could do. So ErgMesh has quite some features and they are documented, which is very nice, I would say. So what are the features when we speak about that? So ErgMesh supports batch scripts that are well-behaved. And it supports POSIX-only scripts that people seem to like. So batch scripts, of course, you need a new compliant shell script. It needs a lot of code to achieve the compliance. But POSIX is like very, very short and you could probably craft it by hand. You just get up some arguments, stuff like that. But why to write anything when you can have a generator? Then you can generate batch completion. Wonderful, right? And you can generate main page. And is there anybody who has heard of docopt? Nobody? Okay. So I will touch it in the most section. It's basically a standardized help output. Yes, standardized help message. So it can generate that for your script. It works on the demand principle, which means if there is no demand, there is no code. Your script is simple, low amount of generated code. Your script is complex, then high amount of generated code. Simple as that. And it supports kind of commented mode, which means that the generated code contains comments which enable you to like orient in the generated code and maybe fix something by yourself. That's it. And demo time. I hope the font is not too big and you will still be able to see something. So let's say we want to make a script which mimics LS that it accepts the with argument, dash w, dash dash with, with one value. It accepts almost all argument which is optional, it's either on or off. And it accepts a directory as a positional argument. So let's generate. In the Arbash package, there is a tool called Arbash in it. And I tell it that I want a positional argument directory, optional argument with and optional argument, almost all. Then I want hints to be present in my first generated output, let's say. And the output will be script dash m4. So let's do it. And let's see what we have generated. The font is too big. So I have to make it a little bit smaller. So 26. So let's make it 2032 and regular. Let's see. So still it's pretty big. Okay. But at least you can see it. So this is actually quite simple. In the bottom, there are three print fs which are the script body. And they are supposed to print values that were supplied on the command line. So there is Eric underscore with, Eric underscore almost all, Eric underscore directory. Makes sense. And then we have the template section of the script. So let's edit it so we can generate an actual script out of it. So this looks like a line for the option with. So the hints tells us here should go short option character. And short option character for width is w. So I will write w there. So there is a help message. I will leave that. Leave that b. And then there is default option. And I will say that the width option won't have any default. Then we have the almost all option. So this has small a. And the default is off. It's off by default. Yeah. Almost all you have to specify in order to do something. Then we have the position argument directory. Again, the help we will leave it. And default will be the current directory. So that's it. So this is how we used arg bash init to generate like a kickstart. And then we generate the script out of our template. So the script is generated. Let's try to execute it. It prints the default basically, right? There is nothing else there. So let's try the help message. And yeah, looks quite nice. So let's use it and supply some arguments. With 80 dash a, we specify this time. And we want to list the directory home. And it works. Yeah. Almost all is on. With 80, everything kind of works. So let's produce the standardized help message, the docopt.txt. And let's check it out how it looks like. So this is what is the standardized help message. And I will tip out a little bit because I will copy it and paste it to a website which consumes standardized help messages. So control C. And let's see. So I will paste the standardized help message. And press run. And the website parses the help message. And it parses also the command line on the website that you give it. So if I say dash w 80, almost all home, it picks things up. What does it mean for you? It means that there is something that you were not aware of before. There is standardized help message which can be used to define argument parses in various languages. And argmesh is interoperable with that. Anyway, back to the core of the matter. Let's check out the main page output. So I again call argmesh. And I use the script, the generated script, script.sh as a template. If you can see. So I will generate the template for the main page. And let's see how it looks like. So it includes some file. And then it generates some information which can be partially obtained from the script. Like the help message which the script knows what help it has. And then it has some templating functionality that you can extend the contents of the manual with some other content that you know, but they are not part of the script. And now we generate additional definitions for the manual. This is another output that argmesh has. And then again, we check that out. And here we can define things that the script doesn't know. So for example, my name is Mahj. And the version, let's say, will be 0.1 description. And the description with, I will say, use 80 when in doubt. Good. And now I will use the rst2man utility, which is part of the Sphinx. This is a Python documentation system. Part of the Sphinx ecosystem. And let's generate the main page. And let's see the main page. Magic. One page. Use 80 when in doubt. How long it took to generate the main page? It took five minutes from the get go. What next? What next? Completion. And that's it. There will be questions. So I generate completion. And then I execute the completion. So script.sh. And when you generate a completion file, basically, you have to source it to test it immediately. Otherwise, you place it to some directory and it gets sourced automatically. So I have sourced it. And now I should get completion for my script. So this just offers me files. This is not interesting. But if I enter like dash, it offers me long option. If double dash, it offers me long options. So it works. Good. So this was the demo. I haven't shown you the documentation and other features, of course, because of the limited scope. However, if you search for it for ArchBash in Google, you should see the read the docs website with documentation examples. You don't have to worry. If you didn't photograph that, there is plenty of more. And I believe some quick start tutorials. And of course, you can visit the ArchBash.io website. And that's it. That's what I wanted to tell you. So if there are any questions, we have like three, four minutes to handle them. Oh, question. Great question. If I want to add another argument, I will quickly show a script modification. So script.sh. So I will modify the script. I will say that the width will be 80. Yeah. So now when I execute the script with the help option, it says that there is no default. And now I regenerate the script. So I say ArchBash script.sh output script.sh. Execute again. And now it accepts default 80. Yeah. So the script itself is a template. You modify the section in the tab, you modify the content in the template section of the script. And it's reflected in the result. We have three more minutes for questions. So please, if you could leave later. Yeah, another question. So the question was about auto completion. What shells are supported? So it's only the bash auto completion, which is supported at the moment. Yeah. And for requests, welcome. Okay, seems that there is no other question. So thank you for your attention. And enjoy the rest of the conference.