Anonymous avatar Anonymous committed f57349e

doc changes

Comments (0)

Files changed (1)

     manager = Manager(app)
     
     @manager.command
-    def hello(app):
+    def hello():
         print "hello"
 
     if __name__ == "__main__":
     class Hello(Command):
         "prints hello world"
 
-        def run(self, app):
+        def run(self):
             print "hello world"
 
 Now the command needs to be added to our ``Manager`` instance, like the one created above::
 
     manager.run({'hello' : Hello()})
 
-The ``Command`` class must define a ``run`` method. The first argument to your ``run`` , other than ``self``, 
-is always ``app``: this is the Flask application instance that is passed directly to the ``Manager``; if you 
-pass an app factory, the ``Manager`` will call this and pass the result to your ``Command``. Additional arguments
+The ``Command`` class must define a ``run`` method. The positional and optional arguments
 depend on the command-line arguments you pass to the ``Command`` (see below).
 
 To get a list of available commands and their descriptions, just run with no command::
 the ``@command`` decorator, which belongs to the ``Manager`` instance:: 
 
     @manager.command
-    def hello(app):
+    def hello():
         "Just say hello"
         print "hello"
 
 
 The ``@option`` decorator is explained in more detail below.
 
-Note that with ``@command`` and ``@option`` decorators, the function must take the Flask application instance as the first
-argument, just as with ``Command.run``.
 
 Adding arguments to commands
 ----------------------------
             Option('--name', '-n', dest='name'),
         )
 
-        def run(self, app, name):
+        def run(self, name):
             print "hello %s" % name
 
 Positional and optional arguments are stored as ``Option`` instances - see the :ref:`api` below for details.
                 Option('-n', '--name', dest='name', default=self.default_name),
             ]
 
-        def run(self, app, name):
+        def run(self, name):
             print "hello",  name
 
 If you are using the ``@command`` decorator, it's much easier - the options are extracted automatically from your function arguments. This is an example of a positional argument::
 
     @manager.command
-    def hello(app, name):
+    def hello(name):
         print "hello", name
 
 You then invoke this on the command line like so::
 Or you can do optional arguments::
 
     @manager.command
-    def hello(app, name="Fred")
+    def hello(name="Fred")
         print hello, name
 
 These can be called like so::
 There are a couple of important points to note here.
 
 The short-form **-n** is formed from the first letter of the argument, so "name" > "-n". Therefore it's a good idea that your
-optional argument variable names begin with different letters (The first argument, "app", is ignored, 
-so don't worry about "a" being taken).
+optional argument variable names begin with different letters.
 
 The second issue is that the **-h** switch always runs the help text for that command, so avoid arguments starting with the letter "h".
 
 Note also that if your optional argument is a boolean, for example::
 
     @manage.command
-    def verify(app, verified=False):
+    def verify(verified=False):
         """
         Checks if verified
         """
 The ``@command`` decorator is fine for simple operations, but often you need the flexibility. For more sophisticated options it's better to use the ``@option`` decorator::
 
     @manager.option('-n', '--name', dest='name', default='joe')
-    def hello(app, name):
+    def hello(name):
         print "hello", name
 
 You can add as many options as you want::
 
     @manager.option('-n', '--name', dest='name', default='joe')
     @manager.option('-u', '--url', dest='url', default=None)
-    def hello(app, name, url):
+    def hello(name, url):
         if url is None:
             print "hello", name
         else:
 Suppose you have this command::
     
     @manager.command
-    def hello(app, name):
+    def hello(name):
         uppercase = app.config.get('USE_UPPERCASE', False)
         if uppercase:
             name = name.upper()
     manager = Manager(app)
         
     @manager.command
-    def dropdb(app):
+    def dropdb():
         if prompt_bool(
             "Are you sure you want to lose all your data"):
             db.drop_all()
 
 Needless to say the development server is not intended for production use.
 
-The ``Shell`` command starts a Python shell. You can pass in a ``make_context`` argument, which must be a ``callable`` returning a ``dict``. As with commands, it always takes the ``app`` as the first argument. By default, this is just a dict returning the ``app`` instance::
+The ``Shell`` command starts a Python shell. You can pass in a ``make_context`` argument, which must be a ``callable`` returning a ``dict``. By default, this is just a dict returning the your Flask application instance::
+
+    from flask import app
 
     from flaskext.script import Shell, Manager
     
     from myapp import models
     from myapp.models import db
 
-    def _make_context(app):
-        return dict(app=app, db=db, models=models)
+    def _make_context():
+        return dict(app=app, app, db=db, models=models)
 
     manager = Manager(create_app)
     manager.add_command("shell", Shell(make_context=_make_context))
 
     shell = Shell(use_ipython=False)
 
-There is also a ``@shell`` decorator which you can use with a context function::
+There is also a ``shell`` decorator which you can use with a context function::
 
-    @shell
-    def make_shell_context(app):
+    @manager.shell
+    def make_shell_context():
         return dict(app=app, db=db, models=models)
 
 This enables a **shell** command with the defaults enabled::
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.