Skip to main content

Click utility functions

Project description

===========
Click Click
===========

.. image:: https://travis-ci.org/zalando/python-clickclick.svg?branch=master
:target: https://travis-ci.org/zalando/python-clickclick
:alt: Travis CI build status

.. image:: https://coveralls.io/repos/zalando/python-clickclick/badge.svg
:target: https://coveralls.io/r/zalando/python-clickclick

.. image:: https://img.shields.io/pypi/dw/clickclick.svg
:target: https://pypi-hypernode.com/pypi/clickclick/
:alt: PyPI Downloads

.. image:: https://img.shields.io/pypi/v/clickclick.svg
:target: https://pypi-hypernode.com/pypi/clickclick/
:alt: Latest PyPI version

.. image:: https://img.shields.io/pypi/l/clickclick.svg
:target: https://pypi-hypernode.com/pypi/clickclick/
:alt: License

Utility functions (Python 3 only) for the wonderful `Click library`_.
Click is a Python package for creating beautiful command line interfaces in a composable way with as little code as necessary.


Usage
=====

.. code-block:: python

from clickclick import Action, OutputFormat

with Action('Performing remote call..') as act:
do_something()
act.progress()
do_something_else()

output_format = 'json' # default: "text"
with OutputFormat(output_format):
print_table(['col1', 'col2'], rows)


.. _Click library: http://click.pocoo.org/

Working Example
---------------

See this `example script`_ and the `shell script`_.

.. _example script: example.py

.. literalinclude:: example.py
:language: python3
:linenos:


.. _shell script: example.sh

.. literalinclude:: example.sh
:language: bash
:linenos:

::

$ ./example.py
Usage: example.py [OPTIONS] COMMAND [ARGS]...

Options:
-V, --version Print the current version number and exit.
-h, --help Show this message and exit.

Commands:
list Example for Listings
localtime Print the localtime
output Example for all possible Echo Formats You see...
work-in-progress Work untile working is done
work_done Work done in ?? %

::

$ ./example.py l
Usage: example.py [OPTIONS] COMMAND [ARGS]...

Error: Too many matches: list, localtime

::

$ ./example.py lo
Localtime: 2015-08-27 15:47:46.688547

::

$ ./example.py li
Identifier|Name |Status |Creation Date|Description |Without Title
0 Column #0 ERROR -4228033s ago this is a verrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrr.. column without title
1 Column #1 FINE -4228033s ago this is a verrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrr.. column without title
2 Column #2 WARNING -4228033s ago this is a verrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrr.. column without title

::

$ ./example.py li -o tsv
id name state creation_time desc without_title
0 Column #0 ERROR -4228033s ago this is a verrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrry long description column without title
1 Column #1 FINE -4228033s ago this is a verrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrry long description column without title
2 Column #2 WARNING -4228033s ago this is a verrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrry long description column without title

::

$ ./example.py li -o json
[{"creation_time": 1444911300, "desc": "this is a verrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrry long description", "id": 0, "name": "Column #0", "state": "ERROR", "without_title": "column without title"}, {"creation_time": 1444911300, "desc": "this is a verrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrry long description", "id": 1, "name": "Column #1", "state": "FINE", "without_title": "column without title"}, {"creation_time": 1444911300, "desc": "this is a verrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrry long description", "id": 2, "name": "Column #2", "state": "WARNING", "without_title": "column without title"}]

::

$ ./example.py li -o yaml
creation_time: 1444911300
desc: this is a verrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrry long description
id: 0
name: 'Column #0'
state: ERROR
without_title: column without title
---
creation_time: 1444911300
desc: this is a verrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrry long description
id: 1
name: 'Column #1'
state: FINE
without_title: column without title
---
creation_time: 1444911300
desc: this is a verrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrry long description
id: 2
name: 'Column #2'
state: WARNING
without_title: column without title


::

$ ./example.py work-
do anything.. OK
create an excption.. EXCEPTION OCCURRED: No active exception to reraise
Start with working.. . . . . OK
Calc 1 + 1.. 2
Oh, I make an error.. work not complete done
Oh, I make a warning.. work is complicated
Start an exception.. EXCEPTION OCCURRED: name 'function_not_found' is not defined
Make a final error.. this is the end..

::

$ ./example.py work_ 15.4
Please select the state of your work
1) Done
2) In Progress
3) unknown
4) lost
Please select (1-4) [4]: 2
Your work is 15.4% In Progress

::

$ ./example.py work_ 15.4
Please select the state of your work
1) Done
2) In Progress
3) unknown
4) lost
Please select (1-4) [4]: 3
Your work is 15.4% unknown

::

$ ./example.py work_ 15.4
Please select the state of your work
1) Done
2) In Progress
3) unknown
4) lost
Please select (1-4) [4]:
Your work is 15.4% lost

::

$ ./example.py output
This is a ok: OK
This is a ok with message:all is fine
This is a warning: please check this
Start with working.. . . . . OK
Id|Name
1 Test #1
2 Test #2
Only FYI
This is a error: this is wrong, please fix
This is a fatal error: this is a fuckup

::

$ ./example.py output -o tsv
id name
1 Test #1
2 Test #2

::

$ ./example.py output -o json
[{"id": 1, "name": "Test #1"}, {"id": 2, "name": "Test #2"}]

::

$ ./example.py output -o yaml
id: 1
name: 'Test #1'
---
id: 2
name: 'Test #2'


License
=======

Copyright (c) 2015 Zalando SE

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

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

clickclick-1.2.tar.gz (8.3 kB view details)

Uploaded Source

Built Distribution

clickclick-1.2-py3-none-any.whl (9.8 kB view details)

Uploaded Python 3

File details

Details for the file clickclick-1.2.tar.gz.

File metadata

  • Download URL: clickclick-1.2.tar.gz
  • Upload date:
  • Size: 8.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for clickclick-1.2.tar.gz
Algorithm Hash digest
SHA256 3d436615e3cbc55d04b02f368a76cd3729c523e96e3353455d2bbfc95d5d703d
MD5 ae7bc7a84da16a5b5a8c82e023e4d705
BLAKE2b-256 eeb6ad6a25ab897a17809e5c6b9cc45f6e19b162645129c02a4e15b4d32fb874

See more details on using hashes here.

File details

Details for the file clickclick-1.2-py3-none-any.whl.

File metadata

File hashes

Hashes for clickclick-1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 ba9368ebf40f7a39e51bda0edc676056d86f7721af90cbd2035a82b6c00b8726
MD5 4427d2d4dbb76dd6adc9f38dbe79bc25
BLAKE2b-256 b3faa06ef8534d1e47a5a16f9b122f88c12d7b5f68e2164c460c0bcf44b1277b

See more details on using hashes here.

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