Masonite Documentation
v1.4
v1.4
  • Introduction
  • Prologue
    • Introduction and Installaton
    • Contributing Guide
    • How To Contribute
    • Release Cycle
  • What's New
    • Masonite 1.3
    • Masonite 1.4
  • Upgrade Guide
    • Masonite 1.3 to 1.4
  • The Basics
    • Routing
    • Controllers
    • Views
    • Requests
    • The Craft Command
    • Static Files
    • Helper Functions
  • The Craft Command
    • Introduction
    • Creating Commands
    • Authentication System
  • Architectural Concepts
    • Request Lifecycle
    • Service Providers
    • Service Container
  • Advanced
    • Middleware
    • Creating Commands
    • Creating Packages
    • Publishing Packages
    • Validation
    • Extending Classes
    • Creating a Mail Driver
  • Useful Features
    • Template Caching
    • Mail
    • Uploading
    • View Composers and Sharing
    • Caching
    • Broadcasting
    • Queues and Jobs
    • Compiling Assets
  • Security
    • Authentication
    • Encryption
    • CSRF Protection
  • Orator ORM
    • Basic Usage
    • Query Builder
    • ORM
    • Pagination
    • Schema Builder
    • Database Migrations
    • Collections
  • Managers and Drivers
    • About Managers
    • About Drivers
    • Contracts
  • Official Packages
    • Masonite AuthHub
    • Masonite Clerk
    • Masonite Triggers
Powered by GitBook
On this page
  • Creating Commands
  • Introduction
  • Getting Started
  • Adding Our Command To Craft
Edit on Git
Export as PDF
  1. The Craft Command

Creating Commands

Creating Commands

Introduction

It's extremely simple to add commands to Masonite via the craft command tool and Service Providers. If you have been using Masonite for any amount of time you will learn that commands are a huge part of developing web applications with Masonite. We have made it extremely easy to create these commands and add them to craft to build really fast personal commands that you might use often.

Getting Started

You can create commands by using craft itself:

$ craft command HelloWorldCommand

This will create a app/commands/HelloWorldCommand.py file with boiler plate code that looks like this:

""" A HelloWorldCommand Command """
from cleo import Command


class HelloWorldCommand(Command):
    """
    Description of command

    command:name
        {argument : description}
    """

    def handle(self):
        pass

Let's create a simple hello world application which prints "hello world" to the console. Inside the handle method we can simply put:

...

def handle(self):
    print('Hello World')

That's it! Now we just have to add it to our craft command.

Adding Our Command To Craft

PreviousIntroductionNextAuthentication System

Last updated 7 years ago