将任何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的哈希值
算法 | 哈希摘要 | |
---|---|---|
SHA256 | 5e34252a9a4a45b8ed5ba333e1dbbc70f059e65e327a4039293286dd8dcffa59 |
|
MD5 | 680b5a2eabe4a3ebb3f04f2430e59774 |
|
BLAKE2b-256 | 6b2110f70910a61c92d343866637402dab75d4d9def785c28a76bbe108295f63 |