Commits

Ronny Pfannschmidt  committed 7669e08

add support for running a default command instead of printing the usage if no args are given

  • Participants
  • Parent commits 5de77b3

Comments (0)

Files changed (2)

File flaskext/script.py

         with app.test_request_context():
             command.run(*positional_args, **command_namespace.__dict__)
 
-    def run(self, commands=None):
+    def run(self, commands=None, default_command=None):
         
         """
         Prepares manager to receive command line input. Usually run
         if commands:
             self._commands.update(commands)
         
+        
+
         try:
+            if len(sys.argv) == 1 and default_command is not None:
+                command = default_command
+            else:
+                command = sys.argv[1]
             self.handle(sys.argv[0],
-                        sys.argv[1],
+                        command,
                         sys.argv[2:])
             
             sys.exit(0)
         manager = Manager(lambda: app)
         assert callable(manager.app)
 
+    def test_run_with_default_command(self):
+        manager = Manager(self.app)
+        manager.add_command('simple', SimpleCommand())
+        try:
+            manager.run(default_command='simple')
+        except SystemExit, e:
+            assert e.code==0
+        assert 'OK' in sys.stdout.getvalue()
+