Skip to content

Commit

Permalink
added model docstring command
Browse files Browse the repository at this point in the history
  • Loading branch information
josephmancuso committed Oct 7, 2018
1 parent 8275601 commit 3ba231f
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 1 deletion.
24 changes: 24 additions & 0 deletions masonite/commands/ModelDocstringCommand.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
""" A ModelDocstringCommand Command """

from cleo import Command

from config.database import DB


class ModelDocstringCommand(Command):
"""
Generate a model docstring based on a table definition
model:docstring
{table : Name of the table to generate the docstring for}
"""

def handle(self):
conn = DB.get_schema_manager().list_table_columns(self.argument('table'))
docstring = '"""Model Definition (generated with love by Masonite) \n\n'
for name, column in conn.items():
length = '({})'.format(column._length) if column._length else ''
docstring += '{}: {}{} default: {}\n'.format(
name, column.get_type(), length, column.get_default())

print(docstring + '"""')
1 change: 1 addition & 0 deletions masonite/commands/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
from .MigrateResetCommand import MigrateResetCommand
from .MigrateRollbackCommand import MigrateRollbackCommand
from .ModelCommand import ModelCommand
from .ModelDocstringCommand import ModelDocstringCommand
from .ProviderCommand import ProviderCommand
from .ServeCommand import ServeCommand
from .ViewCommand import ViewCommand
Expand Down
3 changes: 2 additions & 1 deletion masonite/providers/AppProvider.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
KeyCommand, MakeMigrationCommand,
MigrateCommand, MigrateRefreshCommand,
MigrateResetCommand, MigrateRollbackCommand,
ModelCommand, ProviderCommand, RoutesCommand,
ModelCommand, ModelDocstringCommand, ProviderCommand, RoutesCommand,
SeedCommand, SeedRunCommand, ServeCommand,
TinkerCommand, ViewCommand, ValidatorCommand)

Expand Down Expand Up @@ -49,6 +49,7 @@ def register(self):
self.app.bind('MasoniteMigrateRollbackCommand',
MigrateRollbackCommand())
self.app.bind('MasoniteModelCommand', ModelCommand())
self.app.bind('MasoniteModelDocstringCommand', ModelDocstringCommand())
self.app.bind('MasoniteProviderCommand', ProviderCommand())
self.app.bind('MasoniteViewCommand', ViewCommand())
self.app.bind('MasoniteRoutesCommand', RoutesCommand())
Expand Down

0 comments on commit 3ba231f

Please sign in to comment.