Skip to main content
Help us improve Python packaging – donate today!

Python Command Line Utility

Project Description

# Taskr

## Installation

via pip:

```
pip install taskr
```



## Usage - Task


### ```@task``` decorator

Setup a task function like (Let's call it as "utils.py")

```
from taskr import task

@task
def run(source, destination, speed=42):
print('Run from {0} to {1} by speed={2}'.format(source, destination, speed))

if __name__ == '__main__':
task.dispatch()
```

Then execute by

```
$ python utils.py run Tokyo Yokohama
```

And you'll get

```
Run from Tokyo to Yokohama by speed=42
```

To get help of utils.py

```
$ python utils.py run -h
usage: utils.py run [-h] [--speed SPEED] source destination

positional arguments:
source
destination

optional arguments:
-h, --help show this help message and exit
--speed SPEED
```


### ```@task.set_name``` decorator

By default, we make the name of the function as its action/task name.
If you want to change the action name, you can use ```@task.set_name``` decorator like this

```
@task
@task.set_name('run_to')
def run(source, destination, speed=42):
print('Run from {0} to {1} by speed={2}'.format(source, destination, speed))
```

And now execute by

```
$ python utils.py run_to Tokyo Yokohama
```


### ```@task.set_argument``` decorator

taskr uses ```argparse``` module of Python to parse argument passed in.
By default, we map positional argument of task function into required positonal argument of argparser and
optional argument of task function into optional argument of argparser.

If you want to change this behavior or add help text, choice limitation, and etc when setup argparse,
you can use ```@task.set_argument``` decorator and pass the same arguments you pass when using argparse.

```
@task
@task.set_argument('source', help='The source where you come from', choice=('Tokyo', 'Osaka'))
@task.set_argument('--speed', '-s', help='The speed you wanna run', type=int, dest='speed')
def run(source, destination, speed=42):
print('Run from {0} to {1} by speed={2}'.format(source, destination, speed))
```

And now you can only run from Tokyo or Osaka but cannot run from Kyoto
Also you must run in an int value speed.

For positional arguments, taskr matches its name and argument of function automatically.
But for optional arguments, you must assign ```dest``` to make taskr understand which argument of function
shoule map to.


### ```@task.pass_argparse_namespace``` decorator

If your task function has set ```pass_argparse_namespace``` by this decorator,
then all the argument of argparse should be decalred explicitly. (i.e. taskr won't discover for you automatically)
Also the argument passed into your task function is only the "Namespace" comes from argparse

For example

```
@task
@task.pass_argparse_namespace
@task.set_argument('start_time')
@task.set_argument('end_time')
def sleep(arguments):
print('Sleep from {0.start_time} to {0.end_time}'.format(arguments))
```


## Usage - console & Color

The ```console``` helps you to print color message on console.

It gives you a str 'Hello World' with loght red color and white background.
Also you can use ```console.info```, ```console.error```, ```console.success```, ```console.highlight```,
and ```console.prompt``` to print messages

To get colored string, use Color.str.

```
Color.str('Hello World', foreground=Color.RED, background=Color.White, light=True)
```

It gives a 'Hello World' string with light red text and white background.

Release history Release notifications

History Node

0.2.45

History Node

0.2.44

History Node

0.2.43

History Node

0.2.42

History Node

0.2.41

History Node

0.2.40

History Node

0.2.39

History Node

0.2.38

History Node

0.2.37

History Node

0.2.36

History Node

0.2.35

History Node

0.2.34

History Node

0.2.33

History Node

0.2.32

History Node

0.2.31

History Node

0.2.30

History Node

0.2.29

History Node

0.2.28

History Node

0.2.27

History Node

0.2.26

History Node

0.2.25

History Node

0.2.24

History Node

0.2.23

History Node

0.2.22.1

History Node

0.2.22

History Node

0.2.21

History Node

0.2.20

History Node

0.2.19

History Node

0.2.18

History Node

0.2.17

History Node

0.2.16

History Node

0.2.15.3

History Node

0.2.15.2

History Node

0.2.15.1

History Node

0.2.15

History Node

0.2.14.1

History Node

0.2.14

History Node

0.2.13

History Node

0.2.12

History Node

0.2.11

History Node

0.2.10

History Node

0.2.9

History Node

0.2.8

History Node

0.2.7

History Node

0.2.6

History Node

0.2.5

History Node

0.2.4

History Node

0.2.3

History Node

0.2.2

History Node

0.2.1

History Node

0.2.0

History Node

0.1.41

History Node

0.1.40

History Node

0.1.39

History Node

0.1.38

History Node

0.1.37

History Node

0.1.36

History Node

0.1.35

History Node

0.1.34

History Node

0.1.33

History Node

0.1.32

History Node

0.1.31

History Node

0.1.30

History Node

0.1.29

History Node

0.1.28

History Node

0.1.27

History Node

0.1.26

History Node

0.1.25

History Node

0.1.24

History Node

0.1.23

History Node

0.1.22

History Node

0.1.21

History Node

0.1.20

History Node

0.1.19

History Node

0.1.18

History Node

0.1.17

History Node

0.1.16

History Node

0.1.15

History Node

0.1.14

This version
History Node

0.1.13

History Node

0.1.12

History Node

0.1.11

History Node

0.1.10

History Node

0.1.9

History Node

0.1.8

History Node

0.1.7

History Node

0.1.6

History Node

0.1.5

History Node

0.1.4

History Node

0.1.3

History Node

0.1.2

History Node

0.1.1

History Node

0.1.0

History Node

0.0.14

History Node

0.0.13

History Node

0.0.12

History Node

0.0.11

History Node

0.0.10

History Node

0.0.9

History Node

0.0.8

History Node

0.0.6

History Node

0.0.5

History Node

0.0.4

History Node

0.0.3

History Node

0.0.2

History Node

0.0.1

Download files

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

Filename, size & hash SHA256 hash help File type Python version Upload date
taskr-0.1.13.tar.gz (7.4 kB) Copy SHA256 hash SHA256 Source None Aug 11, 2014

Supported by

Elastic Elastic Search Pingdom Pingdom Monitoring Google Google BigQuery Sentry Sentry Error logging CloudAMQP CloudAMQP RabbitMQ AWS AWS Cloud computing Fastly Fastly CDN DigiCert DigiCert EV certificate StatusPage StatusPage Status page