summaryrefslogtreecommitdiff
path: root/docs/features/initialization.rst
diff options
context:
space:
mode:
authorTodd Leonhardt <todd.leonhardt@gmail.com>2019-11-08 19:17:53 -0500
committerGitHub <noreply@github.com>2019-11-08 19:17:53 -0500
commitd5916797620225391379ea40ae466bd7f496ff52 (patch)
tree6452dc4a3f1f45e31cfae16c8acccf3dd7746f14 /docs/features/initialization.rst
parenta18eef6f6aa89280b5f9b92d4e681f22a438ff8b (diff)
parent36796c2c6be67085f3d9000086de7052f08f433c (diff)
downloadcmd2-git-d5916797620225391379ea40ae466bd7f496ff52.tar.gz
Merge pull request #799 from python-cmd2/doc_updates
Doc updates
Diffstat (limited to 'docs/features/initialization.rst')
-rw-r--r--docs/features/initialization.rst52
1 files changed, 50 insertions, 2 deletions
diff --git a/docs/features/initialization.rst b/docs/features/initialization.rst
index f167a55a..936208f1 100644
--- a/docs/features/initialization.rst
+++ b/docs/features/initialization.rst
@@ -1,5 +1,53 @@
Initialization
==============
-Show how to properly initialize a ``cmd2`` app, showing parameters, sequencing,
-etc.
+Here is a basic example ``cmd2`` application which demonstrates many
+capabilities which you may wish to utilize while initializing the app::
+
+ #!/usr/bin/env python3
+ # coding=utf-8
+ """A simple example cmd2 appliction demonstrating the following:
+ 1) Colorizing/stylizing output
+ 2) Using multiline commands
+ 3) Persistent history
+ 4) How to run an initialization script at startup
+ 5) How to group and categorize commands when displaying them in help
+ 6) Opting-in to using the ipy command to run an IPython shell
+ 7) Allowing access to your application in py and ipy
+ 8) Displaying an intro banner upon starting your application
+ 9) Using a custom prompt
+ """
+ import cmd2
+ from cmd2 import style
+
+
+ class BasicApp(cmd2.Cmd):
+ CUSTOM_CATEGORY = 'My Custom Commands'
+
+ def __init__(self):
+ super().__init__(multiline_commands=['echo'], persistent_history_file='cmd2_history.dat',
+ startup_script='scripts/startup.txt', use_ipython=True)
+
+ self.intro = style('Welcome to cmd2!', fg='red', bg='white', bold=True)
+ self.prompt = 'myapp> '
+
+ # Allow access to your application in py and ipy via self
+ self.locals_in_py = True
+
+ # Set the default category name
+ self.default_category = 'cmd2 Built-in Commands'
+
+ @cmd2.with_category(CUSTOM_CATEGORY)
+ def do_intro(self, _):
+ """Display the intro banner"""
+ self.poutput(self.intro)
+
+ @cmd2.with_category(CUSTOM_CATEGORY)
+ def do_echo(self, arg):
+ """Example of a multiline command"""
+ self.poutput(arg)
+
+
+ if __name__ == '__main__':
+ app = BasicApp()
+ app.cmdloop()