Add output of get_usage() to get_info_dict()

オープン
#2,992 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

メンテナーはふだん 1 日以内に返信

まだ誰も着手していません。

  • #3180 @AmoghDeshmukh による — マージされずにクローズ
  • #3276 @Hassad674 による — マージされずにクローズ
  • #3809 @mikemikimike による — マージされずにクローズ
  • #3816 @sahabajalam による — マージされずにクローズ
  • #3864 @pollychen-lab による — マージされずにクローズ

評価

難易度
3/5
見積もり時間
1〜2日
初心者へのやさしさ
55/100
issue の種類
機能追加
明瞭さ
おおむね明確
活発さ
停滞
技術スタック
python
領域
cli

調査の方向性

まず Click の command API と group API における get_info_dict() と get_usage() を追跡し、次に返される info-dict 構造と関連する issue #2762 を調査します。辞書に commands とネストされた commands の usage 出力が含まれ、文書化された workaround を必要としなければ完了です。

索引モデルが issue の本文から書いたものです。

説明

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

主要言語
Python
スター
17.8k
フォーク
3.3k
平均マージ
3日 3時間
マージ済み PR(30日)
13

環境構築

Codespaces で開く

このプロジェクトの開発コンテナを、あなたの GitHub アカウントでブラウザ上に起動します。

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

pallets/click のほかの issue

pallets/click の issue をすべて見る

似ている issue

Python の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。