You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session. You switched accounts on another tab or window. Reload to refresh your session. Dismiss alert
Welcome to the second Click tutorial on how to improve your command-line tools and Python scripts. I’ll show you some more advanced features that help you when things are getting a bit more complex and feature rich in you scripts. You might wonder why I suggest using Click over argparse or optparse. I don’t think they are bad tools, they both have their place and being part of the standard library
はじめに Qiitaのコメントで、紹介してもらったclickを調べてみたら、簡単にサブコマンドを実装できることが分かったので、そのやり方をまとめておく。サブコマンドとは、スクリプトの第一引数が、コマンドになっているような形態のコマンドで、git, svnなどのバージョン管理コマンドや、djangoのプロジェクト管理スクリプトmanage.pyなどにみられる形式だ。 環境構築 clickは、pythonの標準パッケージではないので、pipでインストールする。 import click @click.group(invoke_without_command=True) @click.pass_context def cli(ctx): if ctx.invoked_subcommand is None: print ctx.get_help() else: print('gonna invok
Python のコマンドラインパーサといえば、標準ライブラリに組み込まれている argparse が基本。 蛇足になるけど、バージョン 2.7 以前で使われていた optparse は将来的に廃止予定なので新たに使うことは避けた方が良い。 そして、今回紹介する Python のサードパーティ製コマンドラインパーサ Click は、既存のパッケージと比較すると最小限のコードで美しくコマンドラインインターフェースを実装できるように作られている。 どれくらい楽になるかといえば、もう argparse を使っている場合じゃないな、と思えるレベル。 Welcome to Click — Click Documentation (8.0.x) もくじ もくじ Click をインストールする 基本的な使い方 コマンドを定義する オプションを追加する 引数を追加する サブコマンドを作る オプションについて
リリース、障害情報などのサービスのお知らせ
最新の人気エントリーの配信
処理を実行中です
j次のブックマーク
k前のブックマーク
lあとで読む
eコメント一覧を開く
oページを開く