Skip to content

Commit

Permalink
Refactor/structure changes (#2)
Browse files Browse the repository at this point in the history
* refactor: move and structure command

* test: validate boolean cases

* test: validate boolean cases

* chore: disabled declarion map

* chore: improve empty cases with required or not required

* test: added cases for url, email, number

* test: list validations

* refactor: move public methods to up

* docs: fix doc example

* feat: manage interactive from direct mode

* feat: manage direct mode and errors

* feat: fix spaces and data for interactive command happy path

* feat: manage cases for not required values

* fix: option select improvement

* docs: update example
  • Loading branch information
jairoFernandez authored Jul 20, 2024
1 parent 564dc35 commit 8cba4d5
Show file tree
Hide file tree
Showing 19 changed files with 978 additions and 568 deletions.
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@

A library to help create CLIs with support for command parameters and interactive prompts.

## Quick start

```bash
npx @ideascol/cli-maker
```

## Installation

To install the library, use npm:
Expand Down
17 changes: 12 additions & 5 deletions examples/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,29 @@

In root folder

```bash {"id":"01J3499W21SGS26C9PNTYM8DF6"}
```bash
npm link
```

In examples folder

```bash {"id":"01J3499W22N4TVDTYDJ9WFKNMP"}
```bash
npm link @ideascol/cli-maker
```

In examples folder

```bash {"id":"01J3499W22N4TVDTYDJBM80WF5"}
npm run example
```bash
npm start --
```

```bash
node index.js email --url=https://demo.com --is_ok=false --age=22 --metadata=tag3 --tags=[23] --email=jair@ooo.co
node index.js all-params \
--fruta_favorita=manzana \
--url=https://demo.com \
--is_ok=false \
--email=jair@ooo.co \
--age=22 \
--metadata=tag2 \
--tags='[23, "casa"]'
```
25 changes: 16 additions & 9 deletions examples/index.js
Original file line number Diff line number Diff line change
@@ -1,35 +1,41 @@
const { CLI, ParamType } = require('@ideascol/cli-maker');

const cli = new CLI("mycli", "A simple CLI", {
askForMissingParam: true,
interactive: true,
version: '1.0.0',
showAlwaysParams: true,
});

let commandEmail = {
name: 'email',
description: 'Get the email of the user',
name: 'all-params',
description: 'Show all params',
params: [
{
name: 'favorite_fruit',
description: 'select your favorite fruit',
required: true,
type: ParamType.List,
options: ['manzana', 'pera', 'uva']
},
{
name: 'url',
description: 'The URL of the user to get the email',
description: 'The URL of your website',
type: ParamType.Url,
required: true
},
{
name: "is_ok",
description: "Is the user ok?",
description: "Is the user ok? (true or false)",
type: ParamType.Boolean,
},
{
name: 'email',
description: 'The name of the user to get the email',
description: 'The email',
type: ParamType.Email,
required: true
},
{
name: 'age',
description: 'The age of the user to get the email',
description: 'The age of the user',
type: ParamType.Number,
},
{
Expand All @@ -40,8 +46,9 @@ let commandEmail = {
},
{
name: 'tags',
description: '(e.g., ["tag1", "tag2"] or {"key1": "value1", "key2": "value2"})',
description: '(["tag1", "tag2"] or {"key1": "value1", "key2": "value2"})',
type: ParamType.Custom,
required: false,
}
],
action: (args) => {
Expand Down
4 changes: 2 additions & 2 deletions examples/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
"description": "An example of how to use the cli-maker library",
"main": "index.js",
"scripts": {
"example": "node index.js"
"start": "node index.js"
},
"dependencies": {
"@ideascol/cli-maker": "*"
}
}
}
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"scripts": {
"build": "tsc",
"build:test": "tsc -p tsconfig.test.json",
"test": "npm run build:test && node dist/tests/index.test.js",
"test": "npm run build:test && for file in dist/tests/*.test.js; do node \"$file\"; done",
"prepublishOnly": "npm run build",
"example": "tsc && tsc examples/example1.ts --outDir dist/examples && node dist/examples/example1.js"
},
Expand All @@ -27,4 +27,4 @@
"@types/node": "^20.14.11",
"typescript": "^5.5.3"
}
}
}
Loading

0 comments on commit 8cba4d5

Please sign in to comment.