Skip to content
This repository has been archived by the owner on Sep 16, 2022. It is now read-only.

LightningV1p3r/console-engine

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

97 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

PyPI status PyPI version GitHub license Python application

!!!DISCLAIMER!!!

⚠️ This tool is experimental ⚠️ : This project was a personal experiment, to learn how a parser works, by building one myself. Usage is not recommended

Installation

pip3 install console-engine

Usage

You will have to pass a configuaration as Dictionary into the Shell instance. In the configuration you define the commands and their needed arguments.

Example config:

config = {
    'keywords': {
        'help': 'help_menu',
        'exit': 'exit',
        'commandone': 'method1',
        'commandtwo': 'method2',
    },
    'methods': {
        'help_menu': {
            'arguments': None
        },
        'exit': {
            'arguments': None
        },
        'method1': {
            'arguments': {
                'flags': {
                    'i': {
                        'type': 'IPADDR',
                        'idx': 'target_ip'
                    }
                }

            }
        },
        'method2': {
            'arguments': {
                'values': {
                    'STR': 'text'
                }
            }
        }
    },
}

After having made the config implement console engine into your script like in this:

import cengine

if __name__=='__main__':

    shell_ = cengine.Shell(config, header='>> ')

    while True:

        inst, count = shell_.prompt()
        
        #IF None is returned skip iteration
        if not inst:
            continue

        res = inst[0]
        
        if res['idx'] == 'help_menu':
            print("""
    command1 - returns given ip
    command2 - echos given str
    help - diplays this msg
    exit - terminates script    
    """)
        elif res['idx'] == 'exit':
            exit()
        elif res['idx'] == 'method1':
            print(res['data']['target_ip'])
        elif res['idx'] == 'method2':
            print(res['data']['text'])

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages