If you made it this far, props to you! This was a lot of work, celebrate with some drinks🍻🍻!
In this final project, we will create a personalized terminal command using multiple files, functions, and lots of fun!
To start, create a new project folder with:
glang new final_program
Create a new file inside the src/ folder titled "command.glang".
In the main file, delete all the contents and import the command file:
fetch "src/command.glang";
Add a basic loop to get user input and validate it:
# ...
while true {
obj text = chew("Enter a command: ");
if text == "exit" { # or any command to exit the loop
leave;
}
}
The command file will be used for command functionality such as displaying information, reading and writing files, etc.
Let's add the new_file function to get the user input and create a new file:
func new_file() {
obj name = chew("Enter the file name: ");
bury(name, ""); # use the 'bury' builtin to write files and contents
}
What about a welcome message? Add that too!
func show_welcome() {
bark("*** Welcome to my terminal command! ***");
bark("Type 'exit' to exit this command");
}
Now let's combine it all together in our main file:
fetch "src/command.glang";
show_welcome();
while true {
obj text = chew("Enter a command: ");
if text == "exit" {
leave;
} alsoif text == "newfile" {
new_file();
} # add as many commands as needed!
}
# show_goodbye(); maybe an exit message too?
You have successfully completed GLang. Now get busy creating!