From 6d1ec6360cd5a7c2b5ad4a6089a1fe98c585036d Mon Sep 17 00:00:00 2001 From: Jason Gerard DeRose Date: Fri, 14 Nov 2008 12:43:10 -0700 Subject: Tutorial: small improvements to section on using output_for_cli() --- ipalib/__init__.py | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) (limited to 'ipalib/__init__.py') diff --git a/ipalib/__init__.py b/ipalib/__init__.py index 356482dcc..52ae6b530 100644 --- a/ipalib/__init__.py +++ b/ipalib/__init__.py @@ -528,9 +528,9 @@ To learn more about JSON (Java Script Object Notation), see: http://www.json.org/ ------------------------------------------ -How your command should output to the CLI ------------------------------------------ +--------------------------------------- +How your command should print to stdout +--------------------------------------- As noted above, your command should not print anything while in its ``execute()`` method. So how does your command format its output when @@ -571,7 +571,6 @@ signature: For example, say we setup a command like this: ->>> from ipalib import cli >>> class show_items(Command): ... takes_options = [Param('reverse', type=Bool(), default=False)] ... @@ -596,9 +595,15 @@ For example, say we setup a command like this: >>> api.env.in_server = True # We want to execute, not forward. >>> api.register(show_items) >>> api.finalize() + +Normally `cli.CLI.load_plugins()` will register the `cli.textui` plugin, but for +the sake of our example, we'll just create an instance here: + +>>> from ipalib import cli >>> textui = cli.textui() # We'll pass this to output_for_cli() -Calling it through the ``ipa`` script would basically do the following: +For what we are concerned with in this example, calling your command through +the ``ipa`` script basically will do the following: >>> options = dict(reverse=False) >>> result = api.Command.show_items(**options) -- cgit