This project currently is in .NET 7, so be sure to install that version before execution.
Personally i'm a fan of CLIs, so i decided to build one of them from SCRATCH. By that i mean no external libraries or tools, just pure C# code that i know what it does and how to write it.
-
Windows: In a Windows environment, this project can be run as easily as opening visual studio community and pressing the start button.
-
Linux: In Linux things are done through the terminal, so it is required to open one inside the "CustomCLI" folder and type the following command:
dotnet run --verbosity quiet"--verbosity quiet" silences all warnings in the output.
This CLI simulates the cmd from Windows and Linux, a terminal window that lets the user navigate in the file system (fs). So it can create and remove files and folders, print stuff on the terminal, change directories, edit files, and more. Commands used in this project are a mix of both Windows and Linux, although some command names are different.
The name CustomCLI might make the user think that it activly interact with the real fs of the real PC, but it does not. All actions made inside this programm are objects whose existence is binded to the program itself. In other words, anything created with CustomCLI is NOT created in the real user PC!
This program can also be used to emulate entire folders and their content. This can be usefull for education purpose, testing backup procedures, or simply to get familiar with the CLI without the worry to mess up something important in the user PC. For further information, refer to the Mirror Command
To fullfill a tipical CLI behaviour, the following functionalities are implemented:
-
Create files and folders that are outside the current location.
E.G:
If the user is located inZ:>(the root folder) that contains the "folder1" folder, it is possible to make actions inside it without changing directory.
An example command is as follows:touch folder1/file.txtThe output of the previous command is the creation of the "file.txt" file inside the "folder1" folder.
-
Create multi-word files and folders
E.G.
To create the "text file number 1" file, the syntax would be:touch "text file number 1"WARNING:
Commands that work with files or folders (cd, mv, cp, etcetera) containing spaces do not work.
It is recommended to create folders and files without spaces.
On startup, a terminal appears with a breaf description of the author, the purpose, and what commands are currently available. This section provides larger description of each of every command used in this project and the correct syntax for executing the specific command:
Some commands may have options supported for further functionality. Options can be executed by adding a dash (-) right after the command name.
z:> echo -n Hello World
Hello Worldz:>
Multiple options can be executed by chaining them in a single world.
z:> echo -ne Hello\nWorld\t!!!
Hello
World !!!z:>
Syntax:
z:> help
Prints current commands name and a brief description of them.
Syntax:
z:> cls
Clears the terminal out of all the printed stuff.
Syntax:
z:> exit
Terminates the process.
Syntax:
z:> echo hello world!
z:> echo hello world!
Prints text defined after the echo keyword.
Options:
-
n => Does not print the default new line character '\n'
-
e => Identify special characters like \n, \t and interprets them as their programming definition.
echo -e Hello\nWorld\t!!!
Hello
World !!!
- E => Default echo command behaviour. Read special characters like \n, \t as normal text.
Syntax:
z:> cd folder
z:> cd folder1/folder2
Moves the user up from the current folder to another one if present.
It can be stacked with multiple folders.
Syntax:
z:> fd number
Move the user down from the current folder by a number of directories specified after the fd keyword.
Syntax:
z:> mirror C:\Users\user1\Template
z:> mirror "C:\Users\user1\Template for testing"
Recreates the entire directory structure inside this simulated environment.
It does NOT affect real files and folders in the user PC.
Options:
- f => Mirrors a single provided file.
z:> mirror -f C:\path\to\REAL\file.txt
syntax:
z:> read name
Some name here
Creates the variable called "name" and stores the value inserted afterwads (in this case, "Some name here")
Variables are stored in a virtual Heap memory object.
To print the value stored inside the variable, refer to its name with the $ sign:
z:> echo $name
syntax:
z:> expr 3 + 5
Evaluates the expression and prints the result on the standard output.
Syntax:
z:> touch file.txt
z:> touch folder/file.txt
Creates a file in the current folder and in a different location respectively.
Syntax:
z:> rm file.txt
z:> rm folder/file.txt
Removes a file in the current folder and in a different location respectively.
Syntax:
z:> mkdir folder
Creates a new folder inside the current folder
Syntax:
z:> rmdir folder
Removes the specified folder. If that folder is not empty, a prompt will ask the user for folder content deletion confirmation.
Syntax:
z:> ls
Lists all elements inside the current folder
Syntax:
z:> edit file.txt
z:> edit folder/file.txt
Edit a file in the current folder and in a different location respectively.
Syntax:
z:> cat file.txt
z:> cat folder/file.txt
Prints the content of a file in the current folder and in a different location respectively.
Syntax:
z:> x3i script.x3i
z:> x3i folder/script.x3i
Executes the content of a script file in the current folder and in a different location respectively as commands interpreted by this CLI.
The syntax for the script to work respects the syntax of all other commands
Estear egg
For those who are curious, this command name is inspired by the Organization XIII of the Kingdom Hearts franchise. Because The terminal is a SHELL and Organization XIII members are special empty SHELLs (nobodies).
Syntax:
z:> mv file.txt->folder
z:> mv folder1/folder2/file.txt->folder1/folder3
Moves a file from one location to another. The mv command must be written as a contiguous set of characters without spaces in between. The resulting string is splitted by the string "->", thus permitting to handle the argument as two indipendent strings.
Syntax:
z:> cp file.txt->folder
z:> cp folder1/folder2/file.txt->folder1/folder3
Copies a file from one location to another. The cp command must be written as a contiguous set of characters without spaces in between. The resulting string is splitted by the string "->", thus permitting to handle the argument as two indipendent strings.