Commands
Commands in Masonite are generally designed to make your development life easier. Commands can range from creating controllers and models to installing packages and publishing assets.
Masonite uses the cleo package for it's command features.
Commands for Masonite can be seen by running:
1
$ python craft
Copied!
This will show a list of commands already available for Masonite.
Every command has a "help" screen which describes the command's available arguments and options. In order to view the help prefix the name of the command with help. For example, to see help of serve command you can run:
1
$ python craft help serve
Copied!

Creating Commands

Commands can be created a simple basic command class and inheriting cleo's Command class:
1
from cleo import Command
2
3
class KeyCommand(Command):
4
"""
5
Description of Command
6
7
command:signature
8
{--f|--flag : A flag you can use for the command}
9
{--o|--option=default: An option for the command}
10
"""
11
12
def handle(self):
13
pass
Copied!
Once created you can register the command to Masonite's Service Container so it will show up in show up when you run python craft

Registering Commands

To register command you will need to register them against Masonite's Service Container. You can do so in a service provider
1
from some.place.YourCommand import YourCommand
2
3
class AuthenticationProvider(Provider):
4
def __init__(self, application):
5
self.application = application
6
7
def register(self):
8
self.application.make('commands').add(YourCommnand())
Copied!
When you run python craft you will now see the command you added.
Last modified 1mo ago
Export as PDF
Copy link