Member-only story
Building your command line interface (CLR) tool with vlang on Windows
When I am a student, I like the Linux course. The teacher teaches us how to type commands in a black screen. There is no colorful icons. Just boring text and black screen. We have to login into a remote Linux server in a terminal . Trying many commands. Afterward I know Linux equals these commands. Although there is a X Window, the teacher doesn’t teach that. I think it’s so simple, a mouse can easily use it.
Today I will make my mkdir
command line interface tool with vlang. The command style likes GNU mkdir
command. I will reference the common module. It contains many useful utility for building a GUI like's command. My mkdir
command named md has been distinguished from the built-in mkdir
command. Merely creating a folder is boring. The folder name can contains emoji. If I type and execute the Github emoji shortcode on the command line, it will convert this shortcode to an emoji unicode text. For example, the command is md :stuck_out_tongue:_Hello
. After executed, it will create a folder named 😛_Hello.
Topics
- Prepare vlang environment
- Development
Prepare vlang environment
Download v_windows from V Programming Language. Extract the zip file. Go to the directory v_windows. Use the command v up
updates source code to latest version. If it doesn't work, clone source code from the vlang repositoy. Afterward execute make.bat
.
Development
Create our project folder using command mkdir md
. Change the directory to the directory cd md
. Initial our project via executing the command v int
. It creates a md.v file automatically. This is our main source code file. Downland common.v to current directory.
The emoji character 😛 is utf8 encoding. The code file md.v
must save as utf8 file encoding. Otherwise the emoji character will be changed to the question mark character. Let’s add some code tomd.v
. We need to import os module to use mkdir function. And import common module we mentioned before. Then define constant name and description of the program. The Settings structure contains verbose and dirnames variables. When we use the command with option verbose, it will print “created directory ‘??’” on the command line. The message tells us that we just created a directory. If we want to a respond, the verbose option is useful. The value of the option verbose…