Skip to main content

ec - the simplest way to create CLI applications

Project description

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

ec - also supports

  • Typed arguments.

  • Sub commands (like git).

  • Custom types.

  • Shell mode (imagine python shell)

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

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

Detailed docs could be found at PyDocs.

For more examples check the github page.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

ec-0.2.0.zip (82.9 kB view hashes)

Uploaded Source

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page