Giter Site home page Giter Site logo

mnikley / speed-cli Goto Github PK

View Code? Open in Web Editor NEW
0.0 1.0 0.0 19 KB

Create colored, descriptive CLIs for your scriptcollections without hussle!

License: MIT License

Python 100.00%
cli command-line-interface package-manager script-management scripts-collection

speed-cli's Introduction

PyPI PyPI - Python Version logo

Simplify script and package management by quickly creating a CLI that automatically parses arguments and returns of your functions. Get an instant understanding of your collection without diving into extensive documentation. Customize descriptions and add informative text, making script interaction easy without remembering all the details.

speed_cli_showcase

Install

pip install speed-cli

Basic Usage

from speed_cli import CLI
from your_package import test_func, test_func_two, test_func_three

CLI(menu=[
    test_func, 
    test_func_two, 
    test_func_three
])

and that's it! With an example your_package.py file looking like this:

def test_func():
    print("K")

def test_func_two(number):
    print(f"Doing some calculations with: {number}!")

def test_func_three(my_num: int = 5, my_str: str = 'fredl') -> str:
    return f"{my_num**2} {my_str}"

this would give you an interactive prompt like this:

cli_green

.. of course, you can always modify your CLI and make it more fancy and descriptive! Lets say i want to give the second function some more description, and add custom fields:

    from speed_cli import CLI, Color, MenuEntry

    red = Color('red')
    CLI(color="blue",
        menu=[
            test_func,
            MenuEntry(func=test_func_two,
                      title="My second test function",
                      description="This function is used to do this and that!",
                      warning=f"Be aware to pass the argument {red.colorize('number')} !!"
                      ),
            test_func_three
        ])

would give you:

cli_blue

.. you can also add default arguments for your functions:

def test_func(some_str=None, some_int=None):
    print(f"K {some_str} {some_int}")

CLI(menu=[
    MenuEntry(func=test_func, args=["fredi", 10])
])

.. the Color class also allows you to simply use colored texts in your prints:

from speed_cli import Color

c = Color()
print(f"I like {c.colorize('colors')} to {c.colorize('emphasize', color='green', bold=True)} on the "
      f"{c.colorize('important', color='black', background='bg_cyan')} stuff!")

gives you:

color

TODO:

  • currently only accepts strings as arguments, conversions have to be done in underlying function; convert based on types if given

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.