WELCOME TO EHOST.COM.NP

Monday, September 10, 2018

NUBIA- A Command-line And Interactive Shell Framework

ads space




 





NUBIA- A Command-line And Interactive Shell Framework


Nubia is a lightweight framework for building command-line applications with Python. It was originally designed for the “logdevice interactive shell (aka. ldshell)” at Facebook.


Since then it was factored out to be a reusable component and several internal Facebook projects now rely on it as a quick and easy way to get an intuitive shell/cli application without too much boilerplate.


Nubia is built on top of python-prompt-toolkit which is a fantastic toolkit for building interactive command-line applications.



Key Features



  • Interactive mode that offers fish-style auto-completion

  • CLI mode that gets generated from your functions and classes.

  • Optional bash/zsh completions via an external utility ‘nubia-complete’ (experimental)

  • A customisable status-bar in interactive mode.

  • An optional IPython-based interactive shell

  • Arguments with underscores are automatically hyphenated

  • Python3 type annotations are used for input type validation



Interactive mode


The interactive mode in Nubia is what makes it unique. It is very easy to build a unique shell for your program with zero overhead. The interactive shell in its simplistic form offers automatic completions for commands, sub-commands, arguments, and values.


It also offers a great deal of control for developers to take control over auto-completions, even for commands that do not fall under the typical format. An example is the “select” command in ldshell which is expressed as a SQL-query. We expect that most use cases of Nubia will not need such control and the AutoCommand will be enough without further customisation.


If you start a nubia-based program without a command, it automatically starts an interactive shell. The interactive mode looks like this:





Non-interactive mode


The CLI mode works exactly like any traditional unix-based command line utility.






Examples



It starts with a function like this:


import socket


from termcolor import cprint
from nubia import argument, command, context


@command
@argument(“hosts”, description=”Hostnames to resolve”, aliases=[“i”])
@argument(“bad_name”, name=”nice”, description=”testing”)
def lookup(hosts: typing.List[str], bad_name: int):
    “””
    This will lookup the hostnames and print the corresponding IP addresses
    “””
    ctx = context.get_context()
    print(f”hosts: hosts”)
    cprint(f”Verbose? ”.format(ctx.verbose), “yellow”)


    for host in hosts:
        cprint(“ is ”.format(host, socket.gethostbyname(host)))


    # optional, by default it’s 0
    return 0




Requirements


Nubia-based applications require python 3.6+ and works with both Mac OS X or Linux. While in theory it should work on Windows, it has never been tried.


Installing Nubia
If you are installing nubia for your next project, you should be able to easily use pip for that:


pip3 install python-nubia




Building Nubia from source


Ensure is pipenv installed:


pip3 install pipenv



You can either setup.py to build a tarball, or use pipenv to setup a virtualenv with all the dependencies installed.



Running example in virtualenv:


If you would like to run the example, then you need to add the root of the source tree into your PYTHONPATH.


pipenv update –dev
pipenv shell


export PYTHONPATH=”$(pwd)”
cd example/
python nubia_example.py


To run the unit tests:


pipenv run nosetests


Disclaimer: Nubia is beta for non-ldshell use-cases. Some of the design decisions might sound odd but they fit the ldshell usecase perfectly. We are continuously making changes to make it more consistent and generic outside of the ldshell use-case. Until a fully stable release is published, use it on your own risk.


Download NUBIA



ads space
ADS SPACE

0 comments:

Post a Comment

Categories

Article How-to All Posts WordPress Android Web design Blogger Plugins CSS Google JQuery Plugins Programming Reviews Web Hosting Blogger Blogging Blogging Tips Tricks Web Development Facebook Git Internet Make Money Online Social Plugins Tips Tips and Tricks Tools Tutorials Windows WordPress Plugins Blogging Tips and Tricks Freebies GSM Google Analytics HTML How To's JavaScript Plugin Development S.E.O SEO SMS SmartPhone Social Media Tips amp; Tricks Top-Most Updates Webmaster Tools Whatsapp Applications Apps Blogger Basics Documentary Downloads Entertainment Gadgets Games Gmail Google AdSense Guest Post IPhone Make Money Blogging SVN Security Softwares Web Hosting Tips and Tricks Wordpress Tips Wordpress Tips and Tricks hostgator iOS Advertising Networks Advertising Technology Affiliates Antivirus Audience amp; Traffic Biography Blog post Blog post Blogger Blogger Errors Blogger Tips Blogger Tools Blogger Widget Blogosphere Bogger Widgets CSS selectors CSS symbols CSS3 Computer amp; Internet Content Writing Coupon Codes Data amp; Analytics Deleted blog Design DoubleClick for Publishers Email and newsletter marketting Email marketing Excel Tips Excel Tips and Tricks Facebook Tricks Feed Feedburner Feedburner subscribers Font Fun GitHub Giveaways Gmail primary inbox Gmail tabs Google sign-in Guides HTML amp; CSS HTML5 Infographics Inspirational Instagram Internet Marketing Internet Tips amp; Tricks Job Listings Knowledge Life Hacks Lists Make-Money Monetization amp; Conversion Monetize Navigation Online Marketing Other PHP Tutorials Passport Publishing amp; Content Quotes RSS Sidebar Smartphones Social Networking Status Tech Tech Blog Technology Telegram Themes UI / UX User Psychology amp; Research VB.Net Web Tools Web browser Widget Windows Tips Windows-10 ad viewability admin notice blogging tools bluehost cherry-pick clone cors custom scrollbar customizer dismissible notices duplicate post feed title git branch git clone gpg gpg2 hybridauth iPad icon font notice responsive wordpress theme same origin policy scrollbar signed git commit smartsvn theme customizer vcs wordpress theme wordpress themes

Blog Archive