8000 GitHub - rea1bacon/pyterm: A module to create easy cl tool with python.
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

rea1bacon/pyterm

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

38 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Pyterm (in dev)

Easily create command line tools with python

image

Installation

    git clone https://github.com/evilcater/pyterm.git
    
    cd pyterm

    pip install -r requirements.txt

You also need python 3.7 to run Pyterm

Usage

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'

image

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 !
title

The ascii art string

desc

The description displayed when you start the cli

inp

The sign after the hostname

name

The hostname

To-do

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

Import module

You can import modules with pre-built functions :

import cmdline
x = cmdline.cmd()
x.importm("module_name")
x.initsession()

TO-DO

  • Throw more errors with description

if we write dumpc "test"

dumpcmd [''] [''] # <-- current output

Goal :

Error : while parsing argument dump "test
			            ^
  • Ability to personnalize colors

About

A module to create easy cl tool with python.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

0