git clone https://github.com/evilcater/pyterm.git
cd pyterm
pip install -r requirements.txt
You also need python 3.7 to run Pyterm
To discover the module, you can use the file test.py
import cmdline
Pyterm is very easy to use. You just need a few lines to deploy a cli app.
x = cmdline.cmd()
x.initsession()
You have now a interactive shell fully functionnal with some pre-built commands ready to go !
You can try them by typing 'help'
As you can see, there are 3 lines displayed for each command :
first line : the command name
second line : the function called by this command
third line : a little description
- Personalize the interface
x.initsession() #has many arguments to personalize your cli !
The ascii art string
The description displayed when you start the cli
The sign after the hostname
The hostname
Edit the colors
Feel free to play around with those options
- How it works ?
After you write the command, you can pass parameter (-parameter) and arguments ("argument")
Try to type
help "dump"
This command will only print the output for the 'dump' command
You can play around with parameters and options with the 'dumpc' command
cli$- dumpc -n "hello world" -cap
dumpcmd ['n', 'cap'] ['hello world']
For the moment you can only pass 2 type of options to a command (parameters beginning with a - and arguments delimited by "")
- Variables
You can set variable with command 'set'
cli$- set -var "hello"
"hello" was assigned to $var
cli$- set -var "world" -var2 "nice"
"world" was assigned to $var
"nice" was assigned to $var2
And dump the content with dump "var"
cli$- dump "var"
$var : hello
You can also dump the content of all variables with 'dump'
Finally you can also add variables before the program starts:
x.setv("var","hello")
- Functions
Now we want to add new commands to our cli :
Let's add the command echo who prints a string or the content of a variable :
def echo(p,a):
Every time you define a new function, you need to pass the options 'p' which stands for the parameter array and 'a' for arguments array.
if "$" in p: #check if we want to output a variable
for i in a:
x.retuv([''],[i]) #We execute the function retuv() used by the command dump
return 0
else:
for i in a:
print(i)
Then we add the function :
x.addc("echo", echo)
First we define the keyword, the command that will call the function. To the second position, we pass the function called by the command, here, echo.
You can also add a descritpion to the command :
x.addc("echo",echo,desc="Print a string or a var")
Now we can test it by launching again the script :
cli$- echo "Hello world"
Hello world
cli$- echo "var" -$
$var : 123
You can import modules with pre-built functions :
import cmdline
x = cmdline.cmd()
x.importm("module_name")
x.initsession()
- Throw more errors with description
if we write dumpc "test"
dumpcmd [''] [''] # <-- current output
Goal :
Error : while parsing argument dump "test
^
- Ability to personnalize colors