Giter Site home page Giter Site logo

ishell's Introduction

ishell

PyPI version Downloads

Create interactive shell with Python.

ishell helps you easily create a interactive shell to your application. You can complete commands hitting TAB on your keyboard.

Cisco like console

Instalation

You can install ishell using pip:

pip install ishell

Basics

Console

When building your first application you can start with one console. You can specify the prompt and prompt delimiter:

from ishell.console import Console
console = Console(prompt="someone@someplace ", prompt_delim="#")
console.loop()

Then you have:

Console

Command

The next step is to create a new command and attach to the console:

from ishell.console import Console
from ishell.command import Command
console = Console(prompt="someone@someplace ", prompt_delim="#")

class UsersCommand(Command):
    def run(self, line):
        print "Showing all users..."

users_command = UsersCommand("users", help="Show all users")

console.addChild(users_command)
console.loop()

With the users_command attached to the console you can just hit ENTER and a help message will be printed, if you press TAB the users command will be entered and you can hit ENTER again to execute the command:

Users Command

Command Arguments

You can complete commands with dynamic arguments:

from ishell.console import Console
from ishell.command import Command
console = Console(prompt="someone@someplace ", prompt_delim="#")

class UsersCommand(Command):
    def args(self):
        return ['online', 'offline']

    def run(self, line):
        last_arg = line.split()[-1]
        print "Showing all users %s..." % last_arg

users_command = UsersCommand("users", help="Show all users", dynamic_args=True)

console.addChild(users_command)
console.loop()

Users arguments

Conecting Commands

You can connect commands with each other to build a more verbose command line: (Press TAB to complete)

from ishell.console import Console
from ishell.command import Command
console = Console(prompt="someone@someplace ", prompt_delim="#")

class UsersCommand(Command):
    def args(self):
        return ['online', 'offline']

    def run(self, line):
        last_arg = line.split()[-1]
        print "Showing all users %s..." % last_arg

users_command = UsersCommand("users", help="Show all users", dynamic_args=True)

show = Command("show", help="Show command helper")
console.addChild(show).addChild(users_command)
console.loop()

Example: show users [online|offline]

Show Users

  • Check examples directory for cisco like terminal and a linux minimal shell.

ishell's People

Contributors

italorossi avatar svenchmie avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.