簡體   English   中英

鼓掌arg組包含具有不同要求和沖突的參數

[英]Clap arg group containing arguments with different requirements and conflicts

我試圖借助Clap和YAML在Rust中編寫一個CLI。 我的輸入將需要一個參數(文件路徑)和標志-s-r-g 標志-s-r將需要兩個標志-t-m ,但是標志-g-t-m都沖突。 我正在嘗試對其進行配置,以便如果選擇了-t-m將不接受-g ,但是它不允許將-s-r-t-m

如何配置我的YAML文件,以便我可以禁止-gt-gm但允許(並要求)將-t-m-s-r

cli.yml:

name: mfm
version: "0.1.0"
author: Jonathan Marple <elpramnoj@gmail.com>
about: Media file manager written in rust.
args:
    - INPUT:
        help: Sets the input file(s) to use
        required: true
    - scrape:
        short: s
        long: scrape
        help: Scrape information on show/movie
        requires:
            - DB
    - rename:
        short: r
        long: rename
        help: Rename file(s)
        requires:
            - DB
    - generate:
        short: g
        long: generate
        help: Generate folders for file(s)
        conflicts_with:
            - tvdb
            - tmdb
    - tvdb:
        short: t
        long: tvdb
        help: Pull from tvdb
    - tmdb:
        short: m
        long: tmdb
        help: Pull from tmdb
groups:
    - CMD:
        required: true
        args:
            - scrape
            - rename
            - generate
    - DB:
        args:
            - tvdb
            - tmdb

我也嘗試過將DB標記為“ conflicts_with:但是無論如何它的行為都相同。

按照弗朗索瓦的建議,我轉而使用子命令。 我必須兩次寫出-t-m標志以及它們的DB組,一次為每個使用它們的子命令寫一次。 我試圖避免這種情況,以使我的YAML文件保持干凈且重復性較小,但是功能更為重要。

工作的YAML文件:

name: mfm
version: "0.1.0"
author: Jonathan Marple <elpramnoj@gmail.com>
about: Media file manager written in rust.
args:
    - INPUT:
        help: Sets the input file(s) to use
        required: true
        min_values: 1
subcommands:
    - scrape:
        about: Scrape information on show/movie
        args:
            - tvdb:
                short: t
                long: tvdb
                help: Pull from tvdb
            - tmdb:
                short: m
                long: tmdb
                help: Pull from tmdb
        groups:
            - DB:
                required: true
                args:
                    - tvdb
                    - tmdb
    - rename:
        about: Rename file(s)
        args:
            - tvdb:
                short: t
                long: tvdb
                help: Pull from tvdb
            - tmdb:
                short: m
                long: tmdb
                help: Pull from tmdb
        groups:
            - DB:
                required: true
                args:
                    - tvdb
                    - tmdb
    - generate:
        about: Generate folders for file(s)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM