Skip to content

Commit

Permalink
Merge pull request #210 from akhildevelops/master
Browse files Browse the repository at this point in the history
Publish CLI in a release through Actions, fix lint errors, add few more fake generators to CLI
  • Loading branch information
cksac authored Dec 24, 2024
2 parents 1fd56e0 + 8ef939a commit 8c92743
Show file tree
Hide file tree
Showing 9 changed files with 206 additions and 317 deletions.
26 changes: 26 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
name: Release

on:
push:
tags:
- "v*.*.*"

jobs:
build_and_release:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions-rs/cargo@v1
with:
command: build
args: --release --bin fake --features cli
# TODO: Support generating for multiple targets.
# https://stackoverflow.com/questions/73498168/github-actions-merge-artifacts-after-matrix-steps
- name: Archive Binary
run: |
tar cvzf fake-${{ github.ref_name }}-linux-x86_64.tar.gz README.md -C target/release fake
- name: Release
uses: softprops/action-gh-release@v2
with:
files: |
fake-${{ github.ref_name }}-linux-x86_64.tar.gz
15 changes: 1 addition & 14 deletions .github/workflows/rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -62,18 +62,5 @@ jobs:
with:
command: clippy
args: --workspace --tests --examples -- -D warnings
cli:
name: Fake-CLI
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions-rs/cargo@v1
with:
command: build
args: --release --bin fake --features cli
- name: Upload Bin Artifact
uses: actions/upload-artifact@v4
with:
name: fake
path: target/release/fake


168 changes: 154 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,22 @@
[![Docs Status](https://docs.rs/fake/badge.svg)](https://docs.rs/fake)
[![Latest Version](https://img.shields.io/crates/v/fake.svg)](https://crates.io/crates/fake)

A Rust library and command line tool for generating fake data.
A Rust library and command line tool for generating fake data in different languages. Currently supports:

| Language | Code |
|-----------------------|-------|
| English | en |
| French | fr_fR |
| Arabic | ar_sA |
| Traditional Chinese | zh_tw |
| Simplified Chinese | zh_cn |
| Japanese | ja_jp |
| Portugese (Brazilian) | pt_br |


## Installation

Default:
### Library:

```toml
[dependencies]
Expand Down Expand Up @@ -38,6 +49,114 @@ Available library features:
- `always-true-rng`: expose AlwaysTrueRng
- `maybe-non-empty-collections`: allow to use AlwaysTrueRng to generate non-empty collections

### CLI:
`cargo install --features=cli --git https://github.com/cksac/fake-rs.git`

Access cli using `fake` command. Below are the currently available fake generators.

```shell
❯ fake
An easy to use library and command line for generating fake data like name, number, address, lorem, dates, etc.

Usage: fake [OPTIONS] [COMMAND]

Commands:
CityPrefix
CitySuffix
CityName
CountryName
CountryCode
StreetSuffix
StreetName
TimeZone
StateName
StateAbbr
SecondaryAddressType
SecondaryAddress
ZipCode
PostCode
BuildingNumber
Latitude
Longitude
Geohash
Isbn
Isbn10
Isbn13
CreditCardNumber
CompanySuffix
CompanyName
Buzzword
BuzzwordMiddle
BuzzwordTail
CatchPhrase
BsVerb
BsAdj
BsNoun
Bs
Profession
Industry
FreeEmailProvider
DomainSuffix
FreeEmail
SafeEmail
Username
Password
IPv4
IPv6
IP
MACAddress
UserAgent
Seniority
Field
Position
Word
Words
Sentence
Sentences
Paragraph
Paragraphs
FirstName
LastName
Title
Suffix
Name
NameWithTitle
PhoneNumber
CellNumber
FilePath
FileName
FileExtension
DirPath
MimeType
Semver
SemverStable
SemverUnstable
CurrencyCode
CurrencyName
CurrencySymbol
Bic
Isin
HexColor
RgbColor
RgbaColor
HslColor
HslaColor
Color
Time
Date
DateTime
RfcStatusCode
ValidStatusCode
help Print this message or the help of the given subcommand(s)

Options:
-r, --repeat <repeat> [default: 1]
-l, --locale <locale> [default: EN]
-h, --help Print help
-V, --version Print version

```

## Usage

### In rust code
Expand Down Expand Up @@ -109,21 +228,42 @@ fn main() {
```

## Command line
```shell
Usage: cli [OPTIONS] [COMMAND]

Commands:
Name
FirstName
CityPrefix
Password
help
Generate random name (defaults to EN locale)
```shell
❯ ./fake Name
Generating 1 fakes for EN locale
Theresa Walker
```
Generate 5 chinese random names by mentioning locale to zh_cn
```shell
❯ ./fake -r5 -lzh_cn Name
Generating 5 fakes for ZH_CN locale
何丹华
尹雅瑾
于金福
郭雨珍
龙菲霞
```
Generate 5 random passwords with minimum 10 characters
```shell
❯ ./fake -r5 Password --min 10
Generating 5 fakes for EN locale
Q6eeXHfC3uzSRqtZwB
6fDHAOh3I7Ah77duLL
R8ygoTLmd4i1z1Z
5Uxj3RdEK5O4Af3ow
2XWsGT0lUaDnMZTb7
```
Arguments can be sent to fake generators like password that accept different ranges
```shell
❯ ./fake Password --help
Usage: fake Password [OPTIONS]

Options:
-r, --repeat <repeat> [default: 1]
-l, --locale <locale> [default: EN]
-h, --help Print help
-V, --version Print version
--max <max> [default: 20]
--min <min> [default: 10]
-h, --help Print help
```

# Fakers with locale
Expand Down
4 changes: 2 additions & 2 deletions fake/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "fake"
version = "3.0.1"
version = "3.1.0"
authors = ["cksac <[email protected]>"]
description = "An easy to use library and command line for generating fake data like name, number, address, lorem, dates, etc."
keywords = ["faker", "data", "generator", "random"]
Expand Down Expand Up @@ -61,7 +61,7 @@ bigdecimal = ["bigdecimal-rs", "rust_decimal"]
geo = ["geo-types", "num-traits"]
http = ["dep:http", "url-escape"]
bson_oid = ["bson"]
cli = ["dep:clap"]
cli = ["dep:clap","random_color","chrono","http"]

[[example]]
name = "basic"
Expand Down
Loading

0 comments on commit 8c92743

Please sign in to comment.