Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #478 from shmpwk/warn-parse-args
Add warning for argparse.l when not calling :parse-args
- Loading branch information
Showing
5 changed files
with
146 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
\section{その他の機能} | ||
|
||
\subsection{Argument Parser} | ||
|
||
\begin{refdesc} | ||
|
||
\classdesc{argument-parser}{propertied-object}{flaglst docstring parsed-p}{ | ||
コマンドライン引数のパーサを定義する。} | ||
|
||
\methoddesc{:init}{\&key prog description epilog (add-help t)}{ | ||
プログラム名,自動生成されるヘルプテキストの前後に表示するテキストから, | ||
オブジェクトを生成する。} | ||
|
||
\methoddesc{:add-argument}{flags \&key (action :store) const default choices check read required help dest}{ | ||
コマンドライン引数を定義する。 | ||
|
||
{\tt flag} は {\tt "--foo"} や {\tt "-b"} の引数オプションを定義する。 | ||
引数は{\tt '("--bar" "-b")}等のリストで与えることも可能である。 | ||
|
||
{\tt action} はプログラムに引数が渡されたときの挙動を指定する。 | ||
現在サポートされている{\tt action} は {\tt :store}, {\tt :store-true}, | ||
{\tt :store-false}, {\tt :store-const}, {\tt :append}, そしてカスタム関数である。 | ||
{\tt help} はヘルプドキュメントを指定する。 | ||
ほとんどのパラメータはhttps://docs.python.org/3/library/argparse.htmlに習って設計されている。} | ||
|
||
\methoddesc{:parse-args}{}{ | ||
{\tt lisp::*eustop-argument*} を用いてコマンドライン引数をパースする。 | ||
このメソッドは{\tt argument-parser} インスタンスに引数オプション名メ | ||
ソッドを与える前に呼ばなければならない。} | ||
|
||
{\tt argument-parser}のサンプルプログラムを以下に示す。 | ||
|
||
\begin{verbatim} | ||
(require :argparse "argparse.l") | ||
(defvar argparse (instance argparse:argument-parser :init | ||
:description "Program Description (optional)")) | ||
(send argparse :add-argument "--foo" :default 10 :read t | ||
:help "the foo description") | ||
(send argparse :add-argument '("--bar" "-b") :action :store-true | ||
:help "the bar description") | ||
(send argparse :parse-args) | ||
(format t "foo: ~A~%" (send argparse :foo)) | ||
(format t "bar: ~A~%" (send argparse :bar)) | ||
(exit) | ||
\end{verbatim} | ||
|
||
このサンプルプログラムを実行したときの出力は以下のようになる。 | ||
|
||
\begin{verbatim} | ||
$ eus argparse-example.l | ||
foo: 10 | ||
bar: t | ||
$ eus argparse-example.l --foo=100 --bar | ||
foo: 100 | ||
bar: t | ||
$ eus argparse-example.l -h | ||
usage: [-h] [--foo=FOO] [-b] | ||
Program Description (optional) | ||
optional arguments: | ||
-h, --help show this help message and exit | ||
--foo=FOO the foo description (default: 10) | ||
-b, --bar the bar description | ||
\end{verbatim} | ||
|
||
\end{refdesc} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
\section{Miscellaneous} | ||
|
||
\subsection{Argument Parser} | ||
|
||
\begin{refdesc} | ||
|
||
\classdesc{argument-parser}{propertied-object}{flaglst docstring parsed-p}{ | ||
command line argument parser.} | ||
|
||
\methoddesc{:init}{\&key prog description epilog (add-help t)}{ | ||
instantiates argument-parser class object from the name of the program, | ||
description text to display before the argument help and text to | ||
display after them as an epilog.} | ||
|
||
\methoddesc{:add-argument}{flags \&key (action :store) const default choices check read required help dest}{ | ||
defines the command-line argument to be parsed. | ||
|
||
{\tt flag} specify the options strings such as {\tt "--foo"} or {\tt | ||
"-b"}. It also takes list values i.e. {\tt '("--bar" "-b")}. | ||
|
||
{\tt action} defines the behavior when this argument is passed to the | ||
program. Current supported actions are {\tt :store}, {\tt :store-true}, | ||
{\tt :store-false}, {\tt :store-const}, {\tt :append}, and custom functions. | ||
{\tt help} defines the help document text. | ||
Most of the arguments are designed according to https://docs.python.org/3/library/argparse.html.} | ||
|
||
\methoddesc{:parse-args}{}{ | ||
parses command line argument from {\tt lisp::*eustop-argument*}. This | ||
method must be called before sending an argument name method to {\tt | ||
argument-parser} instance.} | ||
|
||
The following shows an example of {\tt argument-parser}. | ||
|
||
\begin{verbatim} | ||
(require :argparse "argparse.l") | ||
(defvar argparse (instance argparse:argument-parser :init | ||
:description "Program Description (optional)")) | ||
(send argparse :add-argument "--foo" :default 10 :read t | ||
:help "the foo description") | ||
(send argparse :add-argument '("--bar" "-b") :action :store-true | ||
:help "the bar description") | ||
(send argparse :parse-args) | ||
(format t "foo: ~A~%" (send argparse :foo)) | ||
(format t "bar: ~A~%" (send argparse :bar)) | ||
(exit) | ||
\end{verbatim} | ||
|
||
The following is an output of the example program above. | ||
|
||
\begin{verbatim} | ||
$ eus argparse-example.l | ||
foo: 10 | ||
bar: t | ||
$ eus argparse-example.l --foo=100 --bar | ||
foo: 100 | ||
bar: t | ||
$ eus argparse-example.l -h | ||
usage: [-h] [--foo=FOO] [-b] | ||
Program Description (optional) | ||
optional arguments: | ||
-h, --help show this help message and exit | ||
--foo=FOO the foo description (default: 10) | ||
-b, --bar the bar description | ||
\end{verbatim} | ||
|
||
\end{refdesc} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
c9b15e5
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for contributing EusLisp documentation
Please check latest documents before merging
PDF version of English manual: manual.pdf
PDF version of Japanese jmanual: jmanual.pdf
HTML version of English manual: manual.html
HTML version of Japanese manual: jmanual.html
Sphinx (ReST) version of English manual: manual.rst