Common arguments and options for GeoJSON processing commands, using Click.
Example
Here’s an example of a command that writes out GeoJSON features as a collection or, optionally, a sequence of individual features. Since most software that reads and writes GeoJSON expects a text containing a single feature collection, that’s the default, and a LF-delimited sequence of texts containing one GeoJSON feature each is a feature that is turned on using the --sequence option. To write sequences of feature texts that conform to the JSON Text Sequences proposed standard (and might contain pretty-printed JSON) with the ASCII Record Separator (0x1e) as a delimiter, use the --rs option
import click
import cligj
import json
@click.command()
@cligj.sequence_opt
@cligj.use_rs_opt
def features(sequence, use_rs):
features = [
{'type': 'Feature', 'id': '1'}, {'type': 'Feature', 'id': '2'}]
if sequence:
for feature in features:
if use_rs:
click.echo(b'\x1e', nl=False)
click.echo(json.dumps(feature))
else:
click.echo(json.dumps(
{'type': 'FeatureCollection', 'features': features}))
On the command line it works like this.
$ features
{'type': 'FeatureCollection', 'features': [{'type': 'Feature', 'id': '1'}, {'type': 'Feature', 'id': '2'}]}
$ features --sequence
{'type': 'Feature', 'id': '1'}
{'type': 'Feature', 'id': '2'}
$ features --sequence --rs
^^{'type': 'Feature', 'id': '1'}
^^{'type': 'Feature', 'id': '2'}
In this example, ^^ represents 0x1e.
Plugins
cligj can also facilitate loading external click-based plugins via setuptools entry points. The cligj.plugins module contains a special group() decorator that behaves exactly like click.group() except that it offers the opportunity load plugins and attach them to the group as it is istantiated.
from pkg_resources import iter_entry_points
import cligj.plugins
import click
@cligj.plugins.group(plugins=iter_entry_points('module.entry_points'))
def cli():
"""A CLI application."""
pass
@cli.command()
@click.argument('arg')
def printer(arg):
"""Print arg."""
click.echo(arg)
@cli.group(plugins=iter_entry_points('other_module.more_plugins'))
def plugins():
"""A sub-group that contains plugins from a different module."""
pass
Metadata
Release files for cligj 0.2.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| cligj-0.2.0.tar.gz | 5.6 kB | Details |
Built distributions (wheels)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| cligj-0.2.0-py3-none-any.whl | Python 3 | none | any | Details |
| cligj-0.2.0-py2-none-any.whl | Python 2 | none | any | Details |
Total release size: 21.1 kB
Release files / cligj-0.2.0.tar.gz
| Download URL | cligj-0.2.0.tar.gz |
|---|---|
| Size | 5.6 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
8037291ed094fa5d9e164b71cd1bc1ffcb3846d326ca95a6699a1b4145237214
|
|
BLAKE2b-256 checksum How to use checksums |
a8725afac40d6898bc61cbd998e36e9ad6b46f327dd8003f828e580be7610a15
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
Release files / cligj-0.2.0-py3-none-any.whl
| Download URL | cligj-0.2.0-py3-none-any.whl |
|---|---|
| Size | 7.8 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
ad8b2e82c9f580b0ffbf0e932ff8a1226645423eefc86d7fb6d6677301f2a051
|
|
BLAKE2b-256 checksum How to use checksums |
ae1b98c8bfb7733cbcde840864f3fd2007849fcdcfb146e98b1b24f5d3e10bff
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
Release files / cligj-0.2.0-py2-none-any.whl
| Download URL | cligj-0.2.0-py2-none-any.whl |
|---|---|
| Size | 7.8 kB |
| Tags | Python 2 |
|
SHA-256 checksum How to use checksums |
0e8f9bef0b4a87649f9f5aa50a575115865183d40438525c3f0864b5db6f0a8f
|
|
BLAKE2b-256 checksum How to use checksums |
40e750ca0b3c0fc7748d3e109be6799bc51134ffe269324779eff96d41a218e9
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |