summaryrefslogtreecommitdiff
path: root/docs
diff options
context:
space:
mode:
authorFederico Ceratto <federico.ceratto@gmail.com>2017-01-06 12:23:48 +0000
committerGitHub <noreply@github.com>2017-01-06 12:23:48 +0000
commit46d1028a330ffe4d344b99739d1d4b607654ade5 (patch)
treea9d266360cc23d383335c69195a2b65cc8cba77f /docs
parentef074cc2ffb64b2c5281757820f6904bd368d51e (diff)
parent01a8ab20a7ce3544da7c3e69dfc5d4cb0ad257ae (diff)
downloadcmd2-git-46d1028a330ffe4d344b99739d1d4b607654ade5.tar.gz
Merge pull request #29 from tleonhardt/master
Refactored to create a unified Python 2/3 codebase based on six which doesn't require 2to3
Diffstat (limited to 'docs')
-rw-r--r--docs/conf.py75
-rw-r--r--docs/freefeatures.rst72
-rw-r--r--docs/index.rst17
-rw-r--r--docs/pycon2010/fileutil.py12
-rw-r--r--docs/pycon2010/graph.py41
-rw-r--r--docs/pycon2010/pirate.py5
-rw-r--r--docs/pycon2010/pirate2.py6
-rw-r--r--docs/pycon2010/pirate3.py12
-rw-r--r--docs/pycon2010/pirate4.py18
-rw-r--r--docs/pycon2010/pirate5.py19
-rw-r--r--docs/pycon2010/pirate6.py20
-rw-r--r--docs/pycon2010/pirate7.py22
-rw-r--r--docs/pycon2010/pirate8.py25
-rw-r--r--docs/pycon2010/pycon2010.rst64
-rw-r--r--docs/pycon2010/schematic.py32
-rw-r--r--docs/unfreefeatures.rst42
16 files changed, 232 insertions, 250 deletions
diff --git a/docs/conf.py b/docs/conf.py
index ee6b5e6a..32d9243c 100644
--- a/docs/conf.py
+++ b/docs/conf.py
@@ -11,12 +11,12 @@
# All configuration values have a default; values that are commented out
# serve to show the default.
-import sys, os
+# import sys, os
# If extensions (or modules to document with autodoc) are in another directory,
# add these directories to sys.path here. If the directory is relative to the
# documentation root, use os.path.abspath to make it absolute, like shown here.
-#sys.path.append(os.path.abspath('.'))
+# sys.path.append(os.path.abspath('.'))
# -- General configuration -----------------------------------------------------
@@ -31,7 +31,7 @@ templates_path = ['_templates']
source_suffix = '.rst'
# The encoding of source files.
-#source_encoding = 'utf-8'
+# source_encoding = 'utf-8'
# The master toctree document.
master_doc = 'index'
@@ -51,40 +51,40 @@ release = '0.6.9a'
# The language for content autogenerated by Sphinx. Refer to documentation
# for a list of supported languages.
-#language = None
+# language = None
# There are two options for replacing |today|: either, you set today to some
# non-false value, then it is used:
-#today = ''
+# today = ''
# Else, today_fmt is used as the format for a strftime call.
-#today_fmt = '%B %d, %Y'
+# today_fmt = '%B %d, %Y'
# List of documents that shouldn't be included in the build.
-#unused_docs = []
+# unused_docs = []
# List of directories, relative to source directory, that shouldn't be searched
# for source files.
exclude_trees = ['_build']
# The reST default role (used for this markup: `text`) to use for all documents.
-#default_role = None
+# default_role = None
# If true, '()' will be appended to :func: etc. cross-reference text.
-#add_function_parentheses = True
+# add_function_parentheses = True
# If true, the current module name will be prepended to all description
# unit titles (such as .. function::).
-#add_module_names = True
+# add_module_names = True
# If true, sectionauthor and moduleauthor directives will be shown in the
# output. They are ignored by default.
-#show_authors = False
+# show_authors = False
# The name of the Pygments (syntax highlighting) style to use.
pygments_style = 'sphinx'
# A list of ignored prefixes for module index sorting.
-#modindex_common_prefix = []
+# modindex_common_prefix = []
# -- Options for HTML output ---------------------------------------------------
@@ -96,26 +96,26 @@ html_theme = 'default'
# Theme options are theme-specific and customize the look and feel of a theme
# further. For a list of options available for each theme, see the
# documentation.
-#html_theme_options = {}
+# html_theme_options = {}
# Add any paths that contain custom themes here, relative to this directory.
-#html_theme_path = []
+# html_theme_path = []
# The name for this set of Sphinx documents. If None, it defaults to
# "<project> v<release> documentation".
-#html_title = None
+# html_title = None
# A shorter title for the navigation bar. Default is the same as html_title.
-#html_short_title = None
+# html_short_title = None
# The name of an image file (relative to this directory) to place at the top
# of the sidebar.
-#html_logo = None
+# html_logo = None
# The name of an image file (within the static path) to use as favicon of the
# docs. This file should be a Windows icon file (.ico) being 16x16 or 32x32
# pixels large.
-#html_favicon = None
+# html_favicon = None
# Add any paths that contain custom static files (such as style sheets) here,
# relative to this directory. They are copied after the builtin static files,
@@ -124,74 +124,73 @@ html_static_path = ['_static']
# If not '', a 'Last updated on:' timestamp is inserted at every page bottom,
# using the given strftime format.
-#html_last_updated_fmt = '%b %d, %Y'
+# html_last_updated_fmt = '%b %d, %Y'
# If true, SmartyPants will be used to convert quotes and dashes to
# typographically correct entities.
-#html_use_smartypants = True
+# html_use_smartypants = True
# Custom sidebar templates, maps document names to template names.
-#html_sidebars = {}
+# html_sidebars = {}
# Additional templates that should be rendered to pages, maps page names to
# template names.
-#html_additional_pages = {}
+# html_additional_pages = {}
# If false, no module index is generated.
-#html_use_modindex = True
+# html_use_modindex = True
# If false, no index is generated.
-#html_use_index = True
+# html_use_index = True
# If true, the index is split into individual pages for each letter.
-#html_split_index = False
+# html_split_index = False
# If true, links to the reST sources are added to the pages.
-#html_show_sourcelink = True
+# html_show_sourcelink = True
# If true, an OpenSearch description file will be output, and all pages will
# contain a <link> tag referring to it. The value of this option must be the
# base URL from which the finished HTML is served.
-#html_use_opensearch = ''
+# html_use_opensearch = ''
# If nonempty, this is the file name suffix for HTML files (e.g. ".xhtml").
-#html_file_suffix = ''
+# html_file_suffix = ''
# Output file base name for HTML help builder.
htmlhelp_basename = 'cmd2doc'
-
# -- Options for LaTeX output --------------------------------------------------
# The paper size ('letter' or 'a4').
-#latex_paper_size = 'letter'
+# latex_paper_size = 'letter'
# The font size ('10pt', '11pt' or '12pt').
-#latex_font_size = '10pt'
+# latex_font_size = '10pt'
# Grouping the document tree into LaTeX files. List of tuples
# (source start file, target name, title, author, documentclass [howto/manual]).
latex_documents = [
- ('index', 'cmd2.tex', u'cmd2 Documentation',
- u'Catherine Devlin', 'manual'),
+ ('index', 'cmd2.tex', u'cmd2 Documentation',
+ u'Catherine Devlin', 'manual'),
]
# The name of an image file (relative to this directory) to place at the top of
# the title page.
-#latex_logo = None
+# latex_logo = None
# For "manual" documents, if this is true, then toplevel headings are parts,
# not chapters.
-#latex_use_parts = False
+# latex_use_parts = False
# Additional stuff for the LaTeX preamble.
-#latex_preamble = ''
+# latex_preamble = ''
# Documents to append as an appendix to all manuals.
-#latex_appendices = []
+# latex_appendices = []
# If false, no module index is generated.
-#latex_use_modindex = True
+# latex_use_modindex = True
# Example configuration for intersphinx: refer to the Python standard library.
diff --git a/docs/freefeatures.rst b/docs/freefeatures.rst
index 87952611..43b39b29 100644
--- a/docs/freefeatures.rst
+++ b/docs/freefeatures.rst
@@ -51,8 +51,8 @@ Commands at invocation
You can send commands to your app as you invoke it by
including them as extra arguments to the program.
-``cmd2`` interprets each argument as a separate
-command, so you should enclose each command in
+``cmd2`` interprets each argument as a separate
+command, so you should enclose each command in
quotation marks if it is more than a one-word command.
::
@@ -60,9 +60,9 @@ quotation marks if it is more than a one-word command.
cat@eee:~/proj/cmd2/example$ python example.py "say hello" "say Gracie" quit
hello
Gracie
- cat@eee:~/proj/cmd2/example$
+ cat@eee:~/proj/cmd2/example$
+
-
Output redirection
==================
@@ -75,7 +75,7 @@ As in a Unix shell, output of a command can be redirected:
ending with a bare ``>``, as in ``mycommand args >``.. Redirecting
to paste buffer requires software to be installed on the operating
system, pywin32_ on Windows or xclip_ on \*nix.
-
+
If your application depends on mathematical syntax, ``>`` may be a bad
choice for redirecting output - it will prevent you from using the
greater-than sign in your actual user commands. You can override your
@@ -83,7 +83,7 @@ app's value of ``self.redirector`` to use a different string for output redirect
class MyApp(cmd2.Cmd):
redirector = '->'
-
+
::
(Cmd) say line1 -> out.txt
@@ -94,7 +94,7 @@ app's value of ``self.redirector`` to use a different string for output redirect
.. _pywin32: http://sourceforge.net/projects/pywin32/
.. _xclip: http://www.cyberciti.biz/faq/xclip-linux-insert-files-command-output-intoclipboard/
-
+
Python
======
@@ -109,34 +109,34 @@ See see :ref:`parameters`)
::
- (Cmd) py print("-".join("spelling"))
- s-p-e-l-l-i-n-g
- (Cmd) py
- Python 2.6.4 (r264:75706, Dec 7 2009, 18:45:15)
- [GCC 4.4.1] on linux2
- Type "help", "copyright", "credits" or "license" for more information.
- (CmdLineApp)
-
- py <command>: Executes a Python command.
- py: Enters interactive Python mode.
- End with `Ctrl-D` (Unix) / `Ctrl-Z` (Windows), `quit()`, 'exit()`.
- Non-python commands can be issued with `cmd("your command")`.
-
- >>> import os
- >>> os.uname()
- ('Linux', 'eee', '2.6.31-19-generic', '#56-Ubuntu SMP Thu Jan 28 01:26:53 UTC 2010', 'i686')
- >>> cmd("say --piglatin {os}".format(os=os.uname()[0]))
- inuxLay
- >>> self.prompt
- '(Cmd) '
- >>> self.prompt = 'Python was here > '
- >>> quit()
- Python was here >
+ (Cmd) py print("-".join("spelling"))
+ s-p-e-l-l-i-n-g
+ (Cmd) py
+ Python 2.6.4 (r264:75706, Dec 7 2009, 18:45:15)
+ [GCC 4.4.1] on linux2
+ Type "help", "copyright", "credits" or "license" for more information.
+ (CmdLineApp)
+
+ py <command>: Executes a Python command.
+ py: Enters interactive Python mode.
+ End with `Ctrl-D` (Unix) / `Ctrl-Z` (Windows), `quit()`, 'exit()`.
+ Non-python commands can be issued with `cmd("your command")`.
+
+ >>> import os
+ >>> os.uname()
+ ('Linux', 'eee', '2.6.31-19-generic', '#56-Ubuntu SMP Thu Jan 28 01:26:53 UTC 2010', 'i686')
+ >>> cmd("say --piglatin {os}".format(os=os.uname()[0]))
+ inuxLay
+ >>> self.prompt
+ '(Cmd) '
+ >>> self.prompt = 'Python was here > '
+ >>> quit()
+ Python was here >
Searchable command history
==========================
-All cmd_-based applications have access to previous commands with
+All cmd_-based applications have access to previous commands with
the up- and down- cursor keys.
All cmd_-based applications on systems with the ``readline`` module
@@ -155,7 +155,7 @@ also provide `bash-like history list editing`_.
Quitting the application
========================
-``cmd2`` pre-defines a ``quit`` command for you (with
+``cmd2`` pre-defines a ``quit`` command for you (with
synonyms ``exit`` and simply ``q``).
It's trivial, but it's one less thing for you to remember.
@@ -164,14 +164,14 @@ Abbreviated commands
====================
``cmd2`` apps will accept shortened command names
-so long as there is no ambiguity. Thus, if
+so long as there is no ambiguity. Thus, if
``do_divide`` is defined, then ``divid``, ``div``,
or even ``d`` will suffice, so long as there are
no other commands defined beginning with *divid*,
*div*, or *d*.
This behavior can be turned off with ``app.abbrev`` (see :ref:`parameters`)
-
+
Misc. pre-defined commands
==========================
@@ -196,12 +196,12 @@ a ``cmd2``-based app is copied from the screen and pasted into a text
file, ``transcript.txt``, then a transcript test can be run against it::
python app.py --test transcript.txt
-
+
Any non-whitespace deviations between the output prescribed in ``transcript.txt`` and
the actual output from a fresh run of the application will be reported
as a unit test failure. (Whitespace is ignored during the comparison.)
-Regular expressions can be embedded in the transcript inside paired ``/``
+Regular expressions can be embedded in the transcript inside paired ``/``
slashes. These regular expressions should not include any whitespace
expressions.
diff --git a/docs/index.rst b/docs/index.rst
index 40fb8c81..f98ebb4a 100644
--- a/docs/index.rst
+++ b/docs/index.rst
@@ -20,11 +20,11 @@ The basic use of ``cmd2`` is identical to that of cmd_.
1. Create a subclass of ``cmd2.Cmd``. Define attributes and
``do_*`` methods to control its behavior. Throughout this documentation,
we will assume that you are naming your subclass ``App``::
-
+
from cmd2 import Cmd
class App(Cmd):
# customized attributes and methods here
-
+
2. Instantiate ``App`` and start the command loop::
app = App()
@@ -36,21 +36,20 @@ Resources
* cmd_
* `project bug tracker`_
* `cmd2 project page`_
-* `PyCon 2010 presentation <http://us.pycon.org/2010/conference/talks/#proposal_link_153>`_,
+* `PyCon 2010 presentation <https://github.com/python-cmd2/cmd2/blob/master/docs/pycon2010/pycon2010.rst>`_,
*Easy Command-Line Applications with cmd and cmd2*:
- :doc:`slides <pycon2010/pycon2010>`,
- `video <http://python.mirocommunity.com/video/1533/easy-command-line-applications>`_
-
+ :doc:`slides <pycon2010/pycon2010>`,
+ `video <http://pyvideo.org/pycon-us-2010/pycon-2010--easy-command-line-applications-with-c.html>`_
These docs will refer to ``App`` as your ``cmd2.Cmd``
subclass, and ``app`` as an instance of ``App``. Of
course, in your program, you may name them whatever
you want.
-
+
Contents:
.. toctree::
:maxdepth: 2
-
+
overview
example
freefeatures
@@ -61,7 +60,7 @@ Contents:
Compatibility
=============
-Tested and working with Python 2.5, 2.6, 2.7, 3.1; Jython 2.5
+Tested and working with Python 2.7, 3.5, 3.6
Indices and tables
==================
diff --git a/docs/pycon2010/fileutil.py b/docs/pycon2010/fileutil.py
deleted file mode 100644
index 5e754b5a..00000000
--- a/docs/pycon2010/fileutil.py
+++ /dev/null
@@ -1,12 +0,0 @@
-import glob
-import os.path
-
-for fullfilename in glob.glob('/home/cat/proj/cmd2/*.py'):
- (dirpath, fname) = os.path.split(fullfilename)
- stats = os.stat(fullfilename)
- binds['path'] = dirpath
- binds['name'] = fname
- binds['bytes'] = stats.st_size
- cmd("""INSERT INTO cat.files (path, name, bytes)
- VALUES (%(path)s, %(name)s, %(bytes)s)""")
-quit()
diff --git a/docs/pycon2010/graph.py b/docs/pycon2010/graph.py
deleted file mode 100644
index 96ffde72..00000000
--- a/docs/pycon2010/graph.py
+++ /dev/null
@@ -1,41 +0,0 @@
-from turtle import *
-pu()
-goto(-400,-400)
-
-def label(txt):
- write(txt, font=('Arial', 20, 'italic'))
-hideturtle()
-width(6)
-
-def line(len, _label):
- start = pos()
- pd()
- forward(len)
- pu()
- forward(30)
- pd()
- label(_label)
- pu()
- goto(start)
-
-def tech(x, y, _label):
- pu()
- goto(x, y)
- pd()
- write(_label, font=('Arial', 40, 'bold'))
- pu()
-
-line(600, "Easy to write")
-left(90)
-line(600, "Easy to use")
-
-tech(-360, 160, 'GUI')
-tech(-390, 100, 'AJAX')
-tech(-300, -10, 'webapp')
-tech(190, -380, 'CLU')
-tech(60, -320, 'TUI')
-tech(100, -210, 'cmd')
-tech(80, -80, 'cmd2')
-
-while True:
- pass \ No newline at end of file
diff --git a/docs/pycon2010/pirate.py b/docs/pycon2010/pirate.py
index 98db50ea..bd8b5170 100644
--- a/docs/pycon2010/pirate.py
+++ b/docs/pycon2010/pirate.py
@@ -1,7 +1,10 @@
+# coding=utf-8
from cmd import Cmd
+
class Pirate(Cmd):
pass
+
pirate = Pirate()
-pirate.cmdloop() \ No newline at end of file
+pirate.cmdloop()
diff --git a/docs/pycon2010/pirate2.py b/docs/pycon2010/pirate2.py
index e2c49609..343f94ff 100644
--- a/docs/pycon2010/pirate2.py
+++ b/docs/pycon2010/pirate2.py
@@ -1,18 +1,24 @@
+# coding=utf-8
from cmd import Cmd
+
+
# using ``do_`` methods
class Pirate(Cmd):
gold = 3
+
def do_loot(self, arg):
'Seize booty from a passing ship.'
self.gold += 1
print('Now we gots {0} doubloons'
.format(self.gold))
+
def do_drink(self, arg):
'Drown your sorrrows in rrrum.'
self.gold -= 1
print('Now we gots {0} doubloons'
.format(self.gold))
+
pirate = Pirate()
pirate.cmdloop()
diff --git a/docs/pycon2010/pirate3.py b/docs/pycon2010/pirate3.py
index 7977a8dc..ecc70f3f 100644
--- a/docs/pycon2010/pirate3.py
+++ b/docs/pycon2010/pirate3.py
@@ -1,21 +1,29 @@
+# coding=utf-8
from cmd import Cmd
+
+
# using hook
class Pirate(Cmd):
gold = 3
+
def do_loot(self, arg):
'Seize booty from a passing ship.'
self.gold += 1
+
def do_drink(self, arg):
- 'Drown your sorrrows in rrrum.'
+ 'Drown your sorrrows in rrrum.'
self.gold -= 1
+
def precmd(self, line):
self.initial_gold = self.gold
return line
- def postcmd(self, stop, line):
+
+ def postcmd(self, stop, line):
if self.gold != self.initial_gold:
print('Now we gots {0} doubloons'
.format(self.gold))
+
pirate = Pirate()
pirate.cmdloop()
diff --git a/docs/pycon2010/pirate4.py b/docs/pycon2010/pirate4.py
index 5de9c212..a4e4816d 100644
--- a/docs/pycon2010/pirate4.py
+++ b/docs/pycon2010/pirate4.py
@@ -1,27 +1,35 @@
+# coding=utf-8
from cmd import Cmd
+
+
# using arguments
class Pirate(Cmd):
gold = 3
+
def do_loot(self, arg):
'Seize booty from a passing ship.'
self.gold += 1
+
def do_drink(self, arg):
'''Drown your sorrrows in rrrum.
-
- drink [n] - drink [n] barrel[s] o' rum.'''
+
+ drink [n] - drink [n] barrel[s] o' rum.'''
try:
self.gold -= int(arg)
except:
if arg:
print('''What's "{0}"? I'll take rrrum.'''.format(arg))
- self.gold -= 1
+ self.gold -= 1
+
def precmd(self, line):
self.initial_gold = self.gold
return line
- def postcmd(self, stop, line):
+
+ def postcmd(self, stop, line):
if self.gold != self.initial_gold:
print('Now we gots {0} doubloons'.format(self.gold))
+
pirate = Pirate()
-pirate.cmdloop() \ No newline at end of file
+pirate.cmdloop()
diff --git a/docs/pycon2010/pirate5.py b/docs/pycon2010/pirate5.py
index 7add4635..2167c7f4 100644
--- a/docs/pycon2010/pirate5.py
+++ b/docs/pycon2010/pirate5.py
@@ -1,25 +1,32 @@
+# coding=utf-8
from cmd import Cmd
+
+
# quitting
class Pirate(Cmd):
gold = 3
+
def do_loot(self, arg):
'Seize booty from a passing ship.'
self.gold += 1
+
def do_drink(self, arg):
'''Drown your sorrrows in rrrum.
-
- drink [n] - drink [n] barrel[s] o' rum.'''
+
+ drink [n] - drink [n] barrel[s] o' rum.'''
try:
self.gold -= int(arg)
except:
if arg:
print('''What's "{0}"? I'll take rrrum.'''.format(arg))
- self.gold -= 1
+ self.gold -= 1
+
def precmd(self, line):
self.initial_gold = self.gold
return line
- def postcmd(self, stop, line):
+
+ def postcmd(self, stop, line):
if self.gold != self.initial_gold:
print('Now we gots {0} doubloons'
.format(self.gold))
@@ -27,9 +34,11 @@ class Pirate(Cmd):
print("Off to debtorrr's prison.")
stop = True
return stop
+
def do_quit(self, arg):
print("Quiterrr!")
- return True
+ return True
+
pirate = Pirate()
pirate.cmdloop()
diff --git a/docs/pycon2010/pirate6.py b/docs/pycon2010/pirate6.py
index 4a03fed4..a90c2b52 100644
--- a/docs/pycon2010/pirate6.py
+++ b/docs/pycon2010/pirate6.py
@@ -1,29 +1,37 @@
+# coding=utf-8
from cmd2 import Cmd
+
+
# prompts and defaults
class Pirate(Cmd):
gold = 3
prompt = 'arrr> '
+
def default(self, line):
print('What mean ye by "{0}"?'
.format(line))
+
def do_loot(self, arg):
'Seize booty from a passing ship.'
self.gold += 1
+
def do_drink(self, arg):
'''Drown your sorrrows in rrrum.
-
- drink [n] - drink [n] barrel[s] o' rum.'''
+
+ drink [n] - drink [n] barrel[s] o' rum.'''
try:
self.gold -= int(arg)
except:
if arg:
print('''What's "{0}"? I'll take rrrum.'''.format(arg))
- self.gold -= 1
+ self.gold -= 1
+
def precmd(self, line):
self.initial_gold = self.gold
return line
- def postcmd(self, stop, line):
+
+ def postcmd(self, stop, line):
if self.gold != self.initial_gold:
print('Now we gots {0} doubloons'
.format(self.gold))
@@ -31,9 +39,11 @@ class Pirate(Cmd):
print("Off to debtorrr's prison.")
stop = True
return stop
+
def do_quit(self, arg):
print("Quiterrr!")
- return True
+ return True
+
pirate = Pirate()
pirate.cmdloop()
diff --git a/docs/pycon2010/pirate7.py b/docs/pycon2010/pirate7.py
index 25ff5822..a333070c 100644
--- a/docs/pycon2010/pirate7.py
+++ b/docs/pycon2010/pirate7.py
@@ -1,28 +1,36 @@
+# coding=utf-8
from cmd2 import Cmd
+
+
# prompts and defaults
class Pirate(Cmd):
gold = 3
prompt = 'arrr> '
+
def default(self, line):
print('What mean ye by "{0}"?'.format(line))
+
def do_loot(self, arg):
'Seize booty from a passing ship.'
self.gold += 1
+
def do_drink(self, arg):
'''Drown your sorrrows in rrrum.
-
- drink [n] - drink [n] barrel[s] o' rum.'''
+
+ drink [n] - drink [n] barrel[s] o' rum.'''
try:
self.gold -= int(arg)
except:
if arg:
print('''What's "{0}"? I'll take rrrum.'''.format(arg))
- self.gold -= 1
+ self.gold -= 1
+
def precmd(self, line):
self.initial_gold = self.gold
return line
- def postcmd(self, stop, line):
+
+ def postcmd(self, stop, line):
if self.gold != self.initial_gold:
print('Now we gots {0} doubloons'
.format(self.gold))
@@ -30,17 +38,21 @@ class Pirate(Cmd):
print("Off to debtorrr's prison.")
stop = True
return stop
+
def do_quit(self, arg):
print("Quiterrr!")
- return True
+ return True
+
default_to_shell = True
multilineCommands = ['sing']
terminators = Cmd.terminators + ['...']
songcolor = 'blue'
settable = Cmd.settable + 'songcolor Color to ``sing`` in (red/blue/green/cyan/magenta, bold, underline)'
Cmd.shortcuts.update({'~': 'sing'})
+
def do_sing(self, arg):
print(self.colorize(arg, self.songcolor))
+
pirate = Pirate()
pirate.cmdloop()
diff --git a/docs/pycon2010/pirate8.py b/docs/pycon2010/pirate8.py
index 3e80b241..55d6df5c 100644
--- a/docs/pycon2010/pirate8.py
+++ b/docs/pycon2010/pirate8.py
@@ -1,28 +1,36 @@
+# coding=utf-8
from cmd2 import Cmd, options, make_option
+
+
# prompts and defaults
class Pirate(Cmd):
gold = 3
prompt = 'arrr> '
+
def default(self, line):
print('What mean ye by "{0}"?'.format(line))
+
def do_loot(self, arg):
'Seize booty from a passing ship.'
self.gold += 1
+
def do_drink(self, arg):
'''Drown your sorrrows in rrrum.
-
- drink [n] - drink [n] barrel[s] o' rum.'''
+
+ drink [n] - drink [n] barrel[s] o' rum.'''
try:
self.gold -= int(arg)
except:
if arg:
print('''What's "{0}"? I'll take rrrum.'''.format(arg))
- self.gold -= 1
+ self.gold -= 1
+
def precmd(self, line):
self.initial_gold = self.gold
return line
- def postcmd(self, stop, line):
+
+ def postcmd(self, stop, line):
if self.gold != self.initial_gold:
print('Now we gots {0} doubloons'
.format(self.gold))
@@ -30,21 +38,25 @@ class Pirate(Cmd):
print("Off to debtorrr's prison.")
stop = True
return stop
+
def do_quit(self, arg):
print("Quiterrr!")
- return True
+ return True
+
default_to_shell = True
multilineCommands = ['sing']
terminators = Cmd.terminators + ['...']
songcolor = 'blue'
settable = Cmd.settable + 'songcolor Color to ``sing`` in (red/blue/green/cyan/magenta, bold, underline)'
Cmd.shortcuts.update({'~': 'sing'})
+
def do_sing(self, arg):
print(self.colorize(arg, self.songcolor))
+
@options([make_option('--ho', type='int', default=2,
help="How often to chant 'ho'"),
make_option('-c', '--commas',
- action="store_true",
+ action="store_true",
help="Intersperse commas")])
def do_yo(self, arg, opts):
chant = ['yo'] + ['ho'] * opts.ho
@@ -53,5 +65,6 @@ class Pirate(Cmd):
print('{0} and a bottle of {1}'
.format(chant, arg))
+
pirate = Pirate()
pirate.cmdloop()
diff --git a/docs/pycon2010/pycon2010.rst b/docs/pycon2010/pycon2010.rst
index 0b3b7a46..6c3af676 100644
--- a/docs/pycon2010/pycon2010.rst
+++ b/docs/pycon2010/pycon2010.rst
@@ -11,7 +11,7 @@ Web 2.0
.. image:: web-2-0-logos.gif
:height: 350px
-
+
But first...
============
@@ -20,10 +20,10 @@ But first...
.. image:: akkad.png
:height: 250px
-
+
Sargon the Great
Founder of Akkadian Empire
-
+
.. twenty-third century BC
In between
@@ -31,16 +31,16 @@ In between
.. image:: apple.jpg
:height: 250px
-
+
Command-Line Interface
- Unlike the Akkadian Empire,
+ Unlike the Akkadian Empire,
the CLI will never die.
Defining CLI
============
Also known as
-
+
- "Line-oriented command interpreter"
- "Command-line interface"
- "Shell"
@@ -85,24 +85,24 @@ Examples
.. image:: urwid.png
:height: 250px
-
+
Decide your priorities
======================
.. image:: strategy.png
:height: 350px
-
+
A ``cmd`` app: pirate.py
========================
::
from cmd import Cmd
-
+
class Pirate(Cmd):
pass
-
+
pirate = Pirate()
pirate.cmdloop()
@@ -114,9 +114,9 @@ Fundamental prrrinciple
=======================
.. class:: huge
-
- ``(Cmd) foo a b c``
-
+
+ ``(Cmd) foo a b c``
+
becomes
``self.do_foo('a b c')``
@@ -139,7 +139,7 @@ Fundamental prrrinciple
print('Now we gots {0} doubloons'
.format(self.gold))
-.. do_methods; more help
+.. do_methods; more help
Hooks
=====
@@ -163,16 +163,16 @@ Hooks: pirate3.py
'Seize booty from a passing ship.'
self.gold += 1
def do_drink(self, arg):
- 'Drown your sorrrows in rrrum.'
+ 'Drown your sorrrows in rrrum.'
self.gold -= 1
def precmd(self, line):
self.initial_gold = self.gold
return line
- def postcmd(self, stop, line):
+ def postcmd(self, stop, line):
if self.gold != self.initial_gold:
print('Now we gots {0} doubloons'
.format(self.gold))
-
+
Arguments: pirate4.py
=====================
@@ -180,22 +180,22 @@ Arguments: pirate4.py
def do_drink(self, arg):
'''Drown your sorrrows in rrrum.
-
- drink [n] - drink [n] barrel[s] o' rum.'''
+
+ drink [n] - drink [n] barrel[s] o' rum.'''
try:
self.gold -= int(arg)
except:
if arg:
print('''What's "{0}"? I'll take rrrum.'''
.format(arg))
- self.gold -= 1
-
+ self.gold -= 1
+
quitting: pirate5.py
====================
::
- def postcmd(self, stop, line):
+ def postcmd(self, stop, line):
if self.gold != self.initial_gold:
print('Now we gots {0} doubloons'
.format(self.gold))
@@ -205,7 +205,7 @@ quitting: pirate5.py
return stop
def do_quit(self, arg):
print("Quiterrr!")
- return True
+ return True
prompts, defaults: pirate6.py
=============================
@@ -227,7 +227,7 @@ Other CLI packages
* CMdO
* pycopia
* cmdlin
- * cmd2
+ * cmd2
Demo
====
@@ -258,7 +258,7 @@ Script files
Commands at invocation
-Output redirection
+Output redirection
Python
@@ -273,9 +273,9 @@ But wait, there's more
* Timing
* Echo
* Debug
-
+
Minor changes: pirate7.py
-=========================
+=========================
::
@@ -287,18 +287,18 @@ Minor changes: pirate7.py
Cmd.shortcuts.update({'~': 'sing'})
def do_sing(self, arg):
print(self.colorize(arg, self.songcolor))
-
+
Now how much would you pay?
===========================
options / flags
-Quiet (suppress feedback)
+Quiet (suppress feedback)
BASH-style ``select``
Parsing: terminators, suffixes
-
+
Options: pirate8.py
===================
@@ -307,13 +307,13 @@ Options: pirate8.py
@options([make_option('--ho', type='int', default=2,
help="How often to chant 'ho'"),
make_option('-c', '--commas',
- action="store_true",
+ action="store_true",
help="Intersperse commas")])
def do_yo(self, arg, opts):
chant = ['yo'] + ['ho'] * opts.ho
separator = ', ' if opts.commas else ' '
chant = separator.join(chant)
- print('{0} and a bottle of {1}'
+ print('{0} and a bottle of {1}'
.format(chant, arg))
Serious example: sqlpython
diff --git a/docs/pycon2010/schematic.py b/docs/pycon2010/schematic.py
deleted file mode 100644
index 80774859..00000000
--- a/docs/pycon2010/schematic.py
+++ /dev/null
@@ -1,32 +0,0 @@
-from turtle import *
-hideturtle()
-width(6)
-pensize = 10
-pu()
-goto(0,-400)
-
-def rectangle(x, y, _label):
- pu()
- seth(0)
- backward(x / 2)
- fontsize = 40
- pd()
- for i in range(2):
- forward(x)
- left(90)
- forward(y)
- left(90)
- pu()
- forward(x / 2)
- left(90)
- forward(y / 2 - fontsize)
- pd()
- write(_label, align='center', font=('Arial', fontsize, 'bold'))
-
-rectangle(800, 80, 'cmd')
-pu()
-forward(80)
-rectangle(200, 400, 'cmd2')
-
-while True:
- pass
diff --git a/docs/unfreefeatures.rst b/docs/unfreefeatures.rst
index 1cd0081c..c9149409 100644
--- a/docs/unfreefeatures.rst
+++ b/docs/unfreefeatures.rst
@@ -6,13 +6,13 @@ Multiline commands
==================
Command input may span multiple lines for the
-commands whose names are listed in the
+commands whose names are listed in the
parameter ``app.multilineCommands``. These
commands will be executed only
after the user has entered a *terminator*.
By default, the command terminators is
``;``; replacing or appending to the list
-``app.terminators`` allows different
+``app.terminators`` allows different
terminators. A blank line
is *always* considered a command terminator
(cannot be overridden).
@@ -21,17 +21,17 @@ Parsed statements
=================
``cmd2`` passes ``arg`` to a ``do_`` method (or
-``default`) as a ParsedString, a subclass of
+``default`) as a ParsedString, a subclass of
string that includes an attribute ``parsed``.
``parsed`` is a ``pyparsing.ParseResults``
-object produced by applying a pyparsing_
+object produced by applying a pyparsing_
grammar applied to ``arg``. It may include:
command
Name of the command called
raw
- Full input exactly as typed.
+ Full input exactly as typed.
terminator
Character used to end a multiline command
@@ -68,9 +68,9 @@ process are painfully complex and should not be
considered stable; future ``cmd2`` releases may
change it somewhat (hopefully reducing complexity).
-(Getting ``arg`` as a ``ParsedString`` is
+(Getting ``arg`` as a ``ParsedString`` is
technically "free", in that it requires no application
-changes from the cmd_ standard, but there will
+changes from the cmd_ standard, but there will
be no result unless you change your application
to *use* ``arg.parsed``.)
@@ -83,7 +83,7 @@ to *use* ``arg.parsed``.)
Environment parameters
======================
-Your application can define user-settable parameters
+Your application can define user-settable parameters
which your code can reference. Create them as class attributes
with their default values, and add them (with optional
documentation) to ``settable``.
@@ -111,7 +111,7 @@ documentation) to ``settable``.
(Cmd) set --long
degrees_c: 22 # temperature in Celsius
- sunny: False #
+ sunny: False #
(Cmd) sunbathe
Too dim.
(Cmd) set sunny yes
@@ -135,7 +135,7 @@ a ``do_`` methods accept Unix-style *flags*. It uses optparse_
to parse the flags, and they work the same way as for
that module.
-Flags are defined with the ``options`` decorator,
+Flags are defined with the ``options`` decorator,
which is passed a list of optparse_-style options,
each created with ``make_option``. The method
should accept a second argument, ``opts``, in
@@ -180,19 +180,19 @@ the option's online help.
arg_desc='(from city) (to city)')
def do_travel(self, arg, opts=None):
'Gets you from (from city) to (to city).'
-
+
::
(Cmd) help travel
Gets you from (from city) to (to city).
Usage: travel [options] (from-city) (to-city)
-
+
Options:
-h, --help show this help message and exit
-t, --train by train
-
-.. _optparse:
+
+.. _optparse:
.. _outputters:
@@ -200,17 +200,17 @@ poutput, pfeedback, perror
==========================
Standard ``cmd`` applications produce their output with ``self.stdout.write('output')`` (or with ``print``,
-but ``print`` decreases output flexibility). ``cmd2`` applications can use
+but ``print`` decreases output flexibility). ``cmd2`` applications can use
``self.poutput('output')``, ``self.pfeedback('message')``, and ``self.perror('errmsg')``
instead. These methods have these advantages:
- More concise
- ``.pfeedback()`` destination is controlled by :ref:`quiet` parameter.
-
+
color
=====
-Text output can be colored by wrapping it in the ``colorize`` method.
+Text output can be colored by wrapping it in the ``colorize`` method.
.. automethod:: cmd2.Cmd.colorize
@@ -221,7 +221,7 @@ quiet
Controls whether ``self.pfeedback('message')`` output is suppressed;
useful for non-essential feedback that the user may not always want
-to read. ``quiet`` is only relevant if
+to read. ``quiet`` is only relevant if
``app.pfeedback`` is sometimes used.
``select``
@@ -234,13 +234,13 @@ Presents numbered options to user, as bash ``select``.
.. automethod:: cmd2.Cmd.select
::
-
+
def do_eat(self, arg):
sauce = self.select('sweet salty', 'Sauce? ')
result = '{food} with {sauce} sauce, yum!'
result = result.format(food=arg, sauce=sauce)
self.stdout.write(result + '\n')
-
+
::
(Cmd) eat wheaties
@@ -248,4 +248,4 @@ Presents numbered options to user, as bash ``select``.
2. salty
Sauce? 2
wheaties with salty sauce, yum!
- \ No newline at end of file
+