Skip to content

Commit

Permalink
Merge pull request #41 from jiro4989/chore/document
Browse files Browse the repository at this point in the history
📝 Update document
  • Loading branch information
jiro4989 authored Dec 30, 2019
2 parents 8784f86 + 4dda4bc commit e5e083d
Show file tree
Hide file tree
Showing 2 changed files with 110 additions and 5 deletions.
81 changes: 78 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
# faker

Faker is a Nim package that generates fake data for you.
![Build Status](https://github.com/jiro4989/faker/workflows/build/badge.svg)

WIP
faker is a Nim package that generates fake data for you.
faker is heavily inspired by [Python Faker](https://github.com/joke2k/faker).

***WIP***

## Installation

```bash
nimble install https://github.com/jiro4989/faker
nimble install faker
```

## Usage
Expand All @@ -20,22 +23,46 @@ import faker
block:
let fake = newFaker("ja_JP")
echo fake.address()
# -> 茨城県港区東三島31丁目3番16号
echo fake.name()
# -> 若松 香織
block:
# default locale is `LANG` environment variables
let fake = newFaker()
echo fake.address()
# -> 94622 Cesar Camp Apt. 13 South Caitlyn, HI 35128
echo fake.name()
# -> Bruce Wagner DDS
```

### CLI

```bash
$ faker address
大阪府調布市湯宮27丁目24番12号

# Set locale and run
$ LANG=en_US.UTF-8 faker name
Mr. Leonard Johns
```

## Supported locale

I understand only English and Japanese.

| Locale | Description |
| ------ | ----------- |
| en_US | English |
| ja_JP | Japanese |

## Providers

TODO list.

- [ ] base
- [x] faker.provider.address
- [ ] faker.provider.automotive
Expand All @@ -59,3 +86,51 @@ $ faker address
- [ ] faker.provider.python
- [ ] faker.provider.ssn
- [ ] faker.provider.user_agent

## API document

* https://jiro4989.github.io/faker/faker.html

## Development

### Adding new module

You can generate a new module with `nimble genMod` task.
Run below.

```bash
$ nimble genMod new_module
```

Please see other module implements, and edit a generated module.

### Update provider code

You can update `src/faker/provider/*.nim` codes with `nimble genProvs` task.
Run below if you had edited a new module.

```bash
$ nimble genProvs
```

See `src/faker/provider/*.nim`.
A new provider will be generated.

```bash
$ ls -1 src/faker/provider/*.nim
src/faker/provider/address.nim
src/faker/provider/job.nim
src/faker/provider/person.nim
src/faker/provider/phone_number.nim
src/faker/provider/new_module.nim # <--- New provider.
src/faker/provider/util.nim
```

## Pull request

Welcome :heart:

## LICENSE

MIT

34 changes: 32 additions & 2 deletions src/faker/cli/faker.nim
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,35 @@ import os

import ../../faker

const
usage = """faker generates fake data for you.
Usage:
faker <subcommand>
faker -h | --help
Examples:
$ faker address
$ LANG=en_US.UTF-8 faker person
$ LANG=ja_JP.UTF-8 faker person
Avairable subcommand:
address
phone_number, phoneNumber
job
name
Avairable locale:
en_US
ja_JP
Options:
-h, --help Show usage and exit.
"""

proc main(args: seq[string]): int =
if args.len < 1:
stderr.writeLine "Need args"
stderr.writeLine usage
return 1

let subcmd = args[0]
Expand All @@ -14,8 +40,12 @@ proc main(args: seq[string]): int =
of "phoneNumber": echo fake.phoneNumber()
of "phone_number": echo fake.phoneNumber()
of "job": echo fake.job()
of "name": echo fake.name()
of "-h", "--help": echo usage
else:
discard
stderr.writeLine subcmd & " is not supported."
stderr.writeLine "See 'faker -h'."
return 1

when isMainModule:
let args = commandLineParams()
Expand Down

0 comments on commit e5e083d

Please sign in to comment.