跳转到主要内容

将任何CLI工具包装成类似于Python的语法

项目描述

通用Python CLI包装器

将任何CLI工具包装成类似于Python的语法。

快速开始

from pycliwrapper import CliWrapper
apt_cache = CliWrapper("apt-cache", parser=lambda stdout: stdout.splitlines())

# Equivalent to run: "apt-cache search bash" and parsing
# the output as a list
res = ~apt_cache.search.bash
print(res)

将输出解析为JSON

# Build a wrapper on top of main command
tw = CliWrapper("tw -o json", parser=json.loads)

# Build the command that you want to execute
# using Python syntax. A dot means a subcommand and
# flags are pass as normal python variables.
print("PIPELINES")
cmd = tw.pipelines.list(filter="hello")

# You can see the actual command that will be run
# >> tw -o json pipelines list --filter="hello"
print(f"Executing: {cmd}")

# Execute it using the ~ operator and automatically
# parse the output with the given parser
print(~cmd)

# Build and execute the command in one line
# >> tw -o json compute-envs list
print(~tw.compute_envs.list)

# Mixing positional and flag arguments
# >> tw -o json launch nf-core-nanoseq --workspace="community/showcase"
print(~tw.launch("nf-core-nanoseq", workspace="community/showcase"))

# More complex example
# >> tw -o json runs view -i 2gHGbjH9fRDuaW task -t=1 --execution-time
print(~tw.runs.view(i="2gHGbjH9fRDuaW").task(t=1, execution_time=True))

非标准CLI支持

# Build a wrapper on top of main command
nextflow = CliWrapper("nextflow")

# Hello world
# >> nextflow run "nextflow-io/hello"
print(~nextflow.run("nextflow-io/hello"))

# Mixing Nextflow options and pipeline options
# >> nextflow run "nf-core/rnaseq" -profile "docker,test" -r "3.10.1" --outdir="./results"
# TIP: the _ at the beginning means that you want to use a "-" instead of a "--" even if the key has more than one character
# TIP: the _ at the end means that you want to use a " " instead of a "=" even if the key has more than one character
print(~nextflow.run("nf-core/rnaseq", _profile_="docker,test", _r_="3.10.1", outdir="./results"))

项目详情


下载文件

下载适用于您平台的文件。如果您不确定要选择哪个,请了解更多关于安装包的信息。

源分发

pycliwrapper-1.1.tar.gz (2.8 kB 查看哈希值)

由以下赞助

AWS AWS 云计算和安全赞助商 Datadog Datadog 监控 Fastly Fastly CDN Google Google 下载分析 Microsoft Microsoft PSF 赞助商 Pingdom Pingdom 监控 Sentry Sentry 错误记录 StatusPage StatusPage 状态页面