Coder Social home page Coder Social logo

ec's Introduction

The intenetion

ec - intends to reduce the learning curve needed to expose functionality via the command line. With available options like argparse and docopt, it might take several hours to get them right. And there is also the issue of the needed amount of extra coding to setup and process the arguments. See the following example to see how ec solves the issue.

A simple example

from ec.ec import task

@task
def say_hello():
        print 'Hello, world!'

could be accessed from the command line, like:

$ python hello.py say_hello
        Hello, world!

Features

  • Typed arguments.
  • Sub commands (like git).
  • Custom types.
  • Shell mode (like python's interactive mode).
  • Named / Positional arguments.

A more complete example

from: simple.py

from ec.ec import task, arg, group

@task # define a task
@arg(type=int, desc= 'Value for arg1') # add an argument with a type and a description
@arg(type=int)
def task1(arg1, arg2=1):
        print arg1, arg2

@group(desc = 'A group with some tasks') # define a group
class group1:
        @task
        def task1(arg1): # define a task inside the group
                print arg1 + arg1

Execute a task: <dispatch mode>

From the command-line enter

$ python simple.py task1 arg1=1 arg2=2
        1 2

$ python simple.py group1/task1 arg1=1
        2

$ python simple.py group1/task1 1 # positional arguments too are supported
        2

Interactively execute tasks: <shell mode>

From the command-line enter

$ python simple.py # this will enter into ec-shell

>task1
Value for arg1: 1
arg2 (1): 2
1 2

>group1/task1 # execute task1 under group1
arg1: 1
11

>task1 arg1=1 # arguments can be given while calling the task, the missing arguments will be collected from the user
arg2 (1): 2
1 2

>^Z # exit the shell

Utilizing STDIN:

From the command-line enter

$ echo 1 2 | xargs python simple.py task1 # Dispatch a command with args passed through STDIN and converted to args using xargs.
$ echo -e "1\n2" | python simple.py -p task1 # Dispatch a command and with partial args and pass the rest through STDIN.
$ echo task1 1 2 | python simple.py # Feeding the shell with complete commands through stdin.

Detailed docs could be found at PyDocs.

For more examples check the github page.

ec's People

Contributors

viswanathct avatar

Stargazers

Gaurav  avatar praveen kumar a x  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.