Skip to content

Commit

Permalink
merge command line branch
Browse files Browse the repository at this point in the history
  • Loading branch information
joke2k committed Mar 30, 2014
2 parents f80e589 + fdacd92 commit 3efa194
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 5 deletions.
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ build
docs/_build
eggs
parts
bin
var
sdist
develop-eggs
Expand Down
9 changes: 9 additions & 0 deletions bin/faker
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#!/usr/bin/env python

import sys

from faker.__main__ import command


if __name__ == '__main__':
command(*sys.argv[1:])
27 changes: 26 additions & 1 deletion faker/__main__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
from __future__ import unicode_literals
from __future__ import print_function

from faker import Faker, Factory, documentor, AVAILABLE_LOCALES, DEFAULT_LOCALE

import os
import sys

if sys.version < '3':
Expand Down Expand Up @@ -40,7 +44,6 @@ def print_provider(doc, provider, formatters, excludes=None):


def main(provider_or_field=None, *args):
from faker import Faker, Factory, documentor, DEFAULT_LOCALE, AVAILABLE_LOCALES
fake = Faker(locale=DEFAULT_LOCALE)

from faker.providers import BaseProvider
Expand Down Expand Up @@ -82,6 +85,28 @@ def main(provider_or_field=None, *args):
print_provider(d, p, fs)


def command(*args):
try:
f = args[0]
except IndexError:
f = '--help'

if f in ["--help", "-h"]:
main()
sys.exit()

locale = os.environ['LANG'].split('.')[0]

if locale not in AVAILABLE_LOCALES:
locale = DEFAULT_LOCALE
fake = Faker(locale=locale)

try:
print(fake.format(f, *args[1:]))
except AttributeError:
print('No faker found for "{0}"'.format(f))


if __name__ == "__main__":
if sys.stdout.encoding is None:
print("please set python env PYTHONIOENCODING=UTF-8, example: "
Expand Down
6 changes: 3 additions & 3 deletions faker/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,9 @@ def test_documentor(self):
main('faker.providers.it_IT.person')
self.assertRaises(AttributeError, self.generator.get_formatter, 'barFormatter')

def test_build_docs(self):
from faker.build_docs import write_docs
write_docs()
def test_command(self):
from faker.__main__ import command
command('address')


if __name__ == '__main__':
Expand Down
1 change: 1 addition & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
version=version,
description="Faker is a Python package that generates fake data for you.",
long_description=README + '\n\n' + NEWS,
scripts=['bin/faker'],
classifiers=[
# Get strings from http://pypi.python.org/pypi?%3Aaction=list_classifiers
'Development Status :: 3 - Alpha',
Expand Down

0 comments on commit 3efa194

Please sign in to comment.