Skip to content

Commit

Permalink
Add the skeleton of the ScaffoldCommand.
Browse files Browse the repository at this point in the history
  • Loading branch information
mblayman committed Mar 5, 2016
1 parent 4fefbf4 commit 7ae5ca8
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 17 deletions.
2 changes: 2 additions & 0 deletions handroll/commands/builtins.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
# Copyright (c) 2016, Matt Layman

from handroll.commands.build import BuildCommand
from handroll.commands.scaffold import ScaffoldCommand
from handroll.commands.watch import WatchCommand

COMMANDS = [
BuildCommand(),
WatchCommand(),
ScaffoldCommand(),
]
26 changes: 26 additions & 0 deletions handroll/commands/scaffold.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# Copyright (c) 2016, Matt Layman

from handroll.commands.base import Command
from handroll.i18n import _


class ScaffoldCommand(Command):

name = 'scaffold'
description = _(
'Make a new handroll site from a scaffold '
'or list the available scaffolds')
help = _('make a new handroll site')

def register(self, subparsers):
parser = super(ScaffoldCommand, self).register(subparsers)
parser.add_argument(
'site', nargs='?', help=_('the path to your website'))

def run(self, args):
# TODO: list the scaffolds
# TODO: remove LIST_SCAFFOLDS constant
# TODO: Make `make` simpler by putting switching logic in command.
pass
# scaffolder.make(args.scaffold, args.site)
# finish()
14 changes: 1 addition & 13 deletions handroll/entry.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,10 @@
import os
import sys

from handroll import logger, scaffolder
from handroll import logger
from handroll.commands.builtins import COMMANDS
# from handroll.commands.base import finish, prepare_director
from handroll.exceptions import AbortError
from handroll.i18n import _
# from handroll.site import Site


def main(argv=sys.argv):
Expand All @@ -25,11 +23,6 @@ def main(argv=sys.argv):

try:
args.func(args)
# FIXME: There's not really a graceful way to break this and let the
# old method continue to work.
# if args.scaffold:
# scaffolder.make(args.scaffold, args.site)
# finish()
except AbortError as abort:
logger.error(str(abort))
sys.exit(_('Incomplete.'))
Expand All @@ -55,11 +48,6 @@ def build_parser():
"""Build the parser that will have all available commands and options."""
description = _('A website generator for software artisans')
parser = argparse.ArgumentParser(description=description)
parser.add_argument(
'-s', '--scaffold', action='store',
nargs='?', const=scaffolder.LIST_SCAFFOLDS, metavar='scaffold',
help=_('make a new handroll site from a scaffold '
'or list the available scaffolds'))
parser.add_argument(
'-v', '--verbose', action='store_true', help=_('use verbose messages'))
parser.add_argument(
Expand Down
13 changes: 13 additions & 0 deletions handroll/tests/test_commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

from handroll.commands import Command
from handroll.commands.build import BuildCommand
from handroll.commands.scaffold import ScaffoldCommand
from handroll.commands.watch import WatchCommand
from handroll.tests import TestCase

Expand Down Expand Up @@ -94,3 +95,15 @@ def test_complete_watch(self, serve):
command = WatchCommand()
command.run(args)
self.assertTrue(serve.called)


class TestScaffoldCommand(TestCase):

def test_register_site(self):
parser = mock.Mock()
subparsers = mock.Mock()
subparsers.add_parser.return_value = parser
command = ScaffoldCommand()
command.register(subparsers)
site_call = (('site',), {'nargs': '?', 'help': mock.ANY})
self.assertIn(site_call, parser.add_argument.call_args_list)
10 changes: 6 additions & 4 deletions handroll/tests/test_entry.py
Original file line number Diff line number Diff line change
Expand Up @@ -169,8 +169,9 @@ def test_development_server_served(self, serve):

self.assertTrue(serve.called)

@mock.patch('handroll.entry.scaffolder')
def test_makes_from_scaffolder(self, mock_scaffolder):
# @mock.patch('handroll.entry.scaffolder')
# def test_makes_from_scaffolder(self, mock_scaffolder):
def test_makes_from_scaffolder(self):
# FIXME: I promise I'm coming right back to this.
return
self.arguments.extend(['-s', 'default', 'site'])
Expand All @@ -179,5 +180,6 @@ def test_makes_from_scaffolder(self, mock_scaffolder):
entry.main(self.arguments)
self.fail()
except SystemExit:
mock_scaffolder.make.assert_called_once_with(
'default', 'site')
pass
# mock_scaffolder.make.assert_called_once_with(
# 'default', 'site')

0 comments on commit 7ae5ca8

Please sign in to comment.