from django.core.management.base import BaseCommand
from huts.utils import export

class Command(BaseCommand):
    args = ''
    help = 'Dumps the huts, agencies, and regions in the json api format.'

    def handle(self, *args, **options):
        print(export.db_as_json().encode('utf-8'))

from optparse import make_option

from django.core.management.base import BaseCommand
from huts.utils import export


class Command(BaseCommand):
    option_list = BaseCommand.option_list + (
        make_option(
            '--file',
            help='Write to file instead of stdout'
        ),
    )
    help = 'Dumps the huts, agencies, and regions in the json api format.'

    def handle(self, *args, **options):
        out = options['file'] or self.stdout
        out.write(export.db_as_json().encode('utf-8'))

Update command to take file argument
Update command to take file argument

+ from optparse import make_option
+ 
  from django.core.management.base import BaseCommand
  from huts.utils import export
  
+ 
  class Command(BaseCommand):
-     args = ''
+     option_list = BaseCommand.option_list + (
+         make_option(
+             '--file',
+             help='Write to file instead of stdout'
+         ),
+     )
      help = 'Dumps the huts, agencies, and regions in the json api format.'
  
      def handle(self, *args, **options):
+         out = options['file'] or self.stdout
-         print(export.db_as_json().encode('utf-8'))
+         out.write(export.db_as_json().encode('utf-8'))
  
Update command to take file argument
## Code Before:
from django.core.management.base import BaseCommand
from huts.utils import export

class Command(BaseCommand):
    args = ''
    help = 'Dumps the huts, agencies, and regions in the json api format.'

    def handle(self, *args, **options):
        print(export.db_as_json().encode('utf-8'))

## Instruction:
Update command to take file argument
## Code After:
from optparse import make_option

from django.core.management.base import BaseCommand
from huts.utils import export


class Command(BaseCommand):
    option_list = BaseCommand.option_list + (
        make_option(
            '--file',
            help='Write to file instead of stdout'
        ),
    )
    help = 'Dumps the huts, agencies, and regions in the json api format.'

    def handle(self, *args, **options):
        out = options['file'] or self.stdout
        out.write(export.db_as_json().encode('utf-8'))
