Remove inactive code for use_optionlist_for_option_list.
[docutils.git] / docs / api / cmdline-tool.txt
blob200113f997b265910014f3e3d25e73371a3f3efa
1 ===============================================
2  Inside A Docutils Command-Line Front-End Tool
3 ===============================================
5 :Author: David Goodger
6 :Contact: goodger@python.org
7 :Date: $Date$
8 :Revision: $Revision$
9 :Copyright: This document has been placed in the public domain.
11 `The Docutils Publisher`_ class was set up to make building
12 command-line tools easy.  All that's required is to choose components
13 and supply settings for variations.  Let's take a look at a typical
14 command-line front-end tool, ``tools/rst2html.py``, from top to
15 bottom.
17 On Unixish systems, it's best to make the file executable (``chmod +x
18 file``), and supply an interpreter on the first line, the "shebang" or
19 "hash-bang" line::
21     #!/usr/bin/env python
23 Windows systems can be set up to associate the Python interpreter with
24 the ``.py`` extension.
26 Next are some comments providing metadata::
28     # $Id$
29     # Author: David Goodger <goodger@python.org>
30     # Copyright: This module has been placed in the public domain.
32 The module docstring describes the purpose of the tool::
34     """
35     A minimal front end to the Docutils Publisher, producing HTML.
36     """
38 This next block attempts to invoke locale support for
39 internationalization services, specifically text encoding.  It's not
40 supported on all platforms though, so it's forgiving::
42     try:
43         import locale
44         locale.setlocale(locale.LC_ALL, '')
45     except:
46         pass
48 The real work will be done by the code that's imported here::
50     from docutils.core import publish_cmdline, default_description
52 We construct a description of the tool, for command-line help::
54     description = ('Generates (X)HTML documents from standalone '
55                    'reStructuredText sources.  ' + default_description)
57 Now we call the Publisher convenience function, which takes over.
58 Most of it's defaults are used ("standalone" Reader,
59 "reStructuredText" Parser, etc.).  The HTML Writer is chosen by name,
60 and a description for command-line help is passed in::
62     publish_cmdline(writer_name='html', description=description)
64 That's it!  `The Docutils Publisher`_ takes care of the rest.
66 .. _The Docutils Publisher: ./publisher.html