Skip to content

Commit

Permalink
Change cli 'lookup' command to also return matching provider names
Browse files Browse the repository at this point in the history
  • Loading branch information
serpro69 committed Oct 4, 2023
1 parent 1d66b9f commit b90bf81
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 14 deletions.
35 changes: 24 additions & 11 deletions cli-bot/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,21 @@ Quickly find required kotlin-faker functionality from your terminal
<img src=./img/faker-peek.gif width="768" height="606" alt=""/>

## ToC

* [Installation](#installation)
* [Usage](#usage)
* [Available commands](#available-commands)
* [list](#list)
* [lookup](#lookup)
* [Available options](#available-options)
* [--verbose](#verbose-output)
* [--java-syntax](#switch-to-java-syntax)
* [--locale](#using-non-default-locale)
* [--list-locales](#list-available-locales)
* [Available commands](#available-commands)
* [list](#list)
* [lookup](#lookup)
* [Available options](#available-options)
* [--verbose](#verbose-output)
* [--java-syntax](#switch-to-java-syntax)
* [--locale](#using-non-default-locale)
* [--list-locales](#list-available-locales)
* [Thanks](#thanks)

## Installation

The native images are available on [releases](https://github.com/serpro69/kotlin-faker/releases) page.
Download the image to a desired location and make it executable or use below script (Depends on [jq](https://stedolan.github.io/jq/))

Expand All @@ -28,36 +30,47 @@ chmod a+x ~/faker-bot
```

## Usage

Usage details are also available with the `--help` option:
`./faker-bot --help`
`./faker-bot list --help`
`./faker-bot lookup --help`

### Available commands

#### `list`

* `./faker-bot list` - list all providers and their functions
* `./faker-bot list Address Name` - list functions of `Address` and `Name` providers (Case insensitive)

Since version `1.4.0` partial matching is also supported:

* `./faker-bot list addr` - list functions of `Address` provider

#### `lookup`
* `./faker-bot lookup name` - lookup functions by name (Case insensitive partial matching)
#### `lookup`

* `./faker-bot lookup name` - lookup providers and functions by name (Case insensitive partial matching)

### Available options

#### Verbose output

`./faker-bot list --verbose` - prints sample values for each function
`./faker-bot lookup name --verbose` - prints sample values for each function

#### Switch to java syntax

`./faker-bot list --java-syntax` - prints list of all available providers and their functions using java syntax

#### Using non-default locale
`./faker-bot list --verbose --locale de` - combined with `--verbose`, all localized functions will be printed

`./faker-bot list --verbose --locale de` - combined with `--verbose`, all localized functions will be printed
using `de` locale.

#### List available locales

`./faker-bot list --list-locales` - prints all available locales

## Thanks

Inspired by [faker-ruby/faker-bot](https://github.com/faker-ruby/faker-bot)
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,10 @@ object Lookup : Runnable {
val filteredMap = introspector.providerData
.mapValuesTo(mutableMapOf()) { (_, fpPair) ->
val (functions, properties) = fpPair
functions.filter { it.name.lowercase().contains(functionName.lowercase()) } to
functions.filter { it.toString().lowercase().contains(functionName.lowercase()) } to
properties.filter { (sub, funcs) ->
sub.name.lowercase().contains(functionName.lowercase()) ||
funcs.any { f -> f.name.lowercase().contains(functionName.lowercase()) }
sub.toString().lowercase().contains(functionName.lowercase()) ||
funcs.any { f -> f.toString().lowercase().contains(functionName.lowercase()) }
}
}.filterValues { (funcs, subFuncs) ->
funcs.count() > 0 || subFuncs.isNotEmpty()
Expand Down

0 comments on commit b90bf81

Please sign in to comment.