bit3 / faker-cli
此包已被废弃且不再维护。未建议替代包。
Faker PHP 库的命令行命令。
1.4
2016-06-11 08:30 UTC
Requires
- php: >=5.4
- fzaninotto/faker: ~1.0
- symfony/console: ~2.3
This package is not auto-updated.
Last update: 2022-02-01 12:35:36 UTC
README
Faker 是一个 PHP 库,可为您生成假数据。这是一个用于以静态方式轻松生成假数据的命令行工具。
用法
作为 Phar(推荐)
您可以在 发布页面 上找到最新的 Phar。
$ wget https://github.com/bit3/faker-cli/releases/download/1.4/faker.phar $ ./faker.phar
作为 Composer 安装
$ composer create-project bit3/faker-cli
$ cd faker-cli
$ ./bin/faker.php
参数和参数
$ ./bin/faker.php
--locale (-l) # The locale to used. (default: "en_US")
--seed (-s) # The generators seed.
--pattern (-p) # The printf pattern. (default: "%s")
--delimiter (-d) # The delimiter is used by the csv and printf format.
--enclosure (-e) # The enclosure is used by the csv and printf format.
--escape (-E) # The escape character is used by the printf format. (default: "\\")
--format (-f) # The output format (json, xml, csv, php, printf, vprintf) (default: "printf")
--count (-c) # The count of generated data. (default: 1)
<type> # The data type to generate (e.g. "randomDigit", "words", "name", "city")
<args1>..<argsN> # Arguments for the type, e.g. "words 5" will generate 5 words.
单个值生成器示例
$ ./bin/faker.php word
culpa
consequatur
quisquam
recusandae
asperiores
accusamus
nihil
repellat
vero
omnis
多个值生成器示例
$ ./bin/faker.php --count 5 words 2
culpa,consequatur
quisquam,recusandae
asperiores,accusamus
nihil,repellat
vero,omnis
输出格式
您可以通过定义 --format
选项来使用不同的输出格式。默认格式是 JSON。
JSON 输出
$ ./bin/faker.php word
[
"culpa",
"consequatur",
"quisquam",
"recusandae",
"asperiores",
"accusamus",
"nihil",
"repellat",
"vero",
"omnis"
]
$ ./bin/faker.php --count 5 words 2
[
[
"culpa",
"consequatur"
],
[
"quisquam",
"recusandae"
],
[
"asperiores",
"accusamus"
],
[
"nihil",
"repellat"
],
[
"vero",
"omnis"
]
]
XML 输出
$ ./bin/faker.php --format xml word
<?xml version="1.0"?>
<array>
<item>culpa</item>
<item>consequatur</item>
<item>quisquam</item>
<item>recusandae</item>
<item>asperiores</item>
<item>accusamus</item>
<item>nihil</item>
<item>repellat</item>
<item>vero</item>
<item>omnis</item>
</array>
CSV 输出
$ ./bin/faker.php --format csv word
culpa
consequatur
quisquam
recusandae
asperiores
accusamus
nihil
repellat
vero
omnis
PHP 输出
$ ./bin/faker.php --format php word
array (
0 => 'culpa',
1 => 'consequatur',
2 => 'quisquam',
3 => 'recusandae',
4 => 'asperiores',
5 => 'accusamus',
6 => 'nihil',
7 => 'repellat',
8 => 'vero',
9 => 'omnis',
)
printf 和 vprintf 输出
printf 和 vprintf 输出基本相同。但是 printf
为单个值生成器类型设计,例如 safeEmail
,而 vprintf
为多个值生成器类型设计,例如 words 5
。
$ ./bin/faker.php --format printf \
--pattern "INSERT INTO emails (uuid, email) VALUES (UUID(), %s);" \
--enclosure "'" \
safeEmail
INSERT INTO emails (uuid, email) VALUES (UUID(), 'dbednar@example.com');
INSERT INTO emails (uuid, email) VALUES (UUID(), 'xhettinger@example.net');
INSERT INTO emails (uuid, email) VALUES (UUID(), 'gerald62@example.org');
INSERT INTO emails (uuid, email) VALUES (UUID(), 'miles91@example.com');
INSERT INTO emails (uuid, email) VALUES (UUID(), 'to\'conner@example.com');
INSERT INTO emails (uuid, email) VALUES (UUID(), 'bridgette.runolfsdottir@example.com');
INSERT INTO emails (uuid, email) VALUES (UUID(), 'fgoldner@example.org');
INSERT INTO emails (uuid, email) VALUES (UUID(), 'grimes.leo@example.org');
INSERT INTO emails (uuid, email) VALUES (UUID(), 'lilian.reynolds@example.net');
INSERT INTO emails (uuid, email) VALUES (UUID(), 'ratke.darlene@example.net');
./bin/faker.php --format vprintf \
--pattern "INSERT INTO keywords (uuid, keyword1, keyword2, keyword3) VALUES (UUID(), %s, %s, %s);" \
--enclosure "'" \
words 3
INSERT INTO keywords (uuid, keyword1, keyword2, keyword3) VALUES (UUID(), 'est', 'illo', 'consequuntur');
INSERT INTO keywords (uuid, keyword1, keyword2, keyword3) VALUES (UUID(), 'dolorem', 'temporibus', 'commodi');
INSERT INTO keywords (uuid, keyword1, keyword2, keyword3) VALUES (UUID(), 'sint', 'reiciendis', 'sint');
INSERT INTO keywords (uuid, keyword1, keyword2, keyword3) VALUES (UUID(), 'sunt', 'eum', 'id');
INSERT INTO keywords (uuid, keyword1, keyword2, keyword3) VALUES (UUID(), 'tempora', 'rerum', 'occaecati');
INSERT INTO keywords (uuid, keyword1, keyword2, keyword3) VALUES (UUID(), 'corrupti', 'impedit', 'doloribus');
INSERT INTO keywords (uuid, keyword1, keyword2, keyword3) VALUES (UUID(), 'amet', 'consectetur', 'repudiandae');
INSERT INTO keywords (uuid, keyword1, keyword2, keyword3) VALUES (UUID(), 'est', 'id', 'amet');
INSERT INTO keywords (uuid, keyword1, keyword2, keyword3) VALUES (UUID(), 'odio', 'facere', 'nesciunt');
INSERT INTO keywords (uuid, keyword1, keyword2, keyword3) VALUES (UUID(), 'voluptas', 'quia', 'rerum');
您也可以使用多值生成器类型与 printf
一起使用,它们将由默认的 --delimiter
字符(逗号)连接。
$ ./bin/faker.php --format printf \
--pattern "INSERT INTO words (uuid, words) VALUES (UUID(), %s);" \
--delimiter ' / ' \
--enclosure "'" \
words 10
INSERT INTO words (uuid, words) VALUES (UUID(), 'est / illo / consequuntur / dolorem / temporibus / commodi / sint / reiciendis / sint / sunt');
INSERT INTO words (uuid, words) VALUES (UUID(), 'eum / id / tempora / rerum / occaecati / corrupti / impedit / doloribus / amet / consectetur');
INSERT INTO words (uuid, words) VALUES (UUID(), 'repudiandae / est / id / amet / odio / facere / nesciunt / voluptas / quia / rerum');
INSERT INTO words (uuid, words) VALUES (UUID(), 'ad / sed / esse / sed / exercitationem / sed / et / rem / esse / excepturi');
INSERT INTO words (uuid, words) VALUES (UUID(), 'animi / minus / qui / perferendis / quo / repudiandae / aliquam / dolorem / voluptas / fugiat');
INSERT INTO words (uuid, words) VALUES (UUID(), 'at / odit / dolorem / a / aperiam / dignissimos / ipsa / sunt / consequatur / alias');
INSERT INTO words (uuid, words) VALUES (UUID(), 'accusantium / voluptatum / autem / nobis / cumque / neque / modi / iure / voluptatem / error');
INSERT INTO words (uuid, words) VALUES (UUID(), 'molestiae / consequatur / alias / eligendi / corrupti / illum / commodi / molestiae / aut / repellat');
INSERT INTO words (uuid, words) VALUES (UUID(), 'id / quisquam / et / sit / consequuntur / aut / et / ullam / asperiores / molestiae');
INSERT INTO words (uuid, words) VALUES (UUID(), 'cupiditate / culpa / voluptatem / et / mollitia / dolor / sit / nisi / praesentium / qui');
建议使用 --enclosure
选项。每个 --enclosure
字符的出现都将用默认的 \\
(转义字符)转义。
构建您自己的 Phar
安装并运行 php-box
$ curl -LSs https://box-project.github.io/box2/installer.php | php
$ ./box.phar build
许可协议
Faker 命令行工具在 MIT 许可下发布。有关详细信息,请参阅捆绑的 LICENSE 文件。