diff options
author | Todd Leonhardt <todd.leonhardt@gmail.com> | 2019-11-02 15:37:44 -0400 |
---|---|---|
committer | Todd Leonhardt <todd.leonhardt@gmail.com> | 2019-11-02 15:37:44 -0400 |
commit | 12ade7ba7b3adde4c225b965cd4a558574c6c304 (patch) | |
tree | d92c70454f890d19d0eef5d053274c633475715e /docs/features/initialization.rst | |
parent | a18eef6f6aa89280b5f9b92d4e681f22a438ff8b (diff) | |
download | cmd2-git-12ade7ba7b3adde4c225b965cd4a558574c6c304.tar.gz |
Added documentation for empty sections of the Sphinx docs
Diffstat (limited to 'docs/features/initialization.rst')
-rw-r--r-- | docs/features/initialization.rst | 52 |
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() |