Add output of get_usage() to get_info_dict()

Aperta
#2,992 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

Nessuno ha ancora preso questa issue.

  • #3180 di @AmoghDeshmukh — chiusa senza merge
  • #3276 di @Hassad674 — chiusa senza merge
  • #3809 di @mikemikimike — chiusa senza merge
  • #3816 di @sahabajalam — chiusa senza merge
  • #3864 di @pollychen-lab — chiusa senza merge

Valutazione

Difficoltà
3/5
Tempo stimato
1-2 giorni
Idoneità per principianti
55/100
Tipo di issue
Funzionalità
Chiarezza
Abbastanza chiara
Stato di attività
Ferma
Stack tecnologico
python
Ambito
cli

Direzione di ricerca

Inizia tracciando get_info_dict() e get_usage() nelle API command e group di Click, quindi esamina la struttura info-dict restituita e la issue correlata #2762. Il lavoro è completato quando il dizionario include l'output di usage per commands e commands annidati senza richiedere il workaround documentato.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

parsing

Context

I am generating some of my user-facing documentation using get_info_dict(), and was looking for a way to automate the usage as well without having to hardcode it in the docstrings.

Potential solution

Using the calls of get_info_dict() to add a usage key with the value being the output of get_usage().

Other relevant issues: #2762

Workaround

For now I'm using get_info_dict(), then looping through the context to get groups and commands, and using get_usage() on each, then adding it to that dictionary. The code looks something like this (with the for loop matching the structure of my CLI):

    info = ctx.to_info_dict()
    for cmd_n1 in ctx.command.list_commands(ctx):
        cmd2 = ctx.command.get_command(ctx, cmd_n1)
        sub_ctx = ctx._make_sub_context(cmd2)
        usage = cmd2.get_usage(sub_ctx).replace("Usage: ", "")
        info["command"]["commands"][cmd_n1]["usage"] = usage
        if isinstance(cmd2, click.Group):
            # Groups
            for cmd_n2 in cmd2.list_commands(ctx):
                cmd3 = cmd2.get_command(ctx, cmd_n2)
                sub_ctx3 = sub_ctx._make_sub_context(cmd3)
                usage = cmd3.get_usage(sub_ctx3).replace("Usage: ", "")
                info["command"]["commands"][cmd_n1]["commands"][cmd_n2]["usage"] = usage

Lingua principale
Python
Stelle
17.8k
Fork
3.3k
Merge medio
3g 3h
PR unite (30g)
13

Preparare l'ambiente

Apri in Codespaces

Avvia il container di sviluppo del progetto nel browser, con il tuo account GitHub.

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di pallets/click

Tutte le issue di pallets/click

Issue simili

Altre issue su Python

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.