Skip to content

Commit

Permalink
Merge a306f26 into e748d21
Browse files Browse the repository at this point in the history
  • Loading branch information
kazhala committed Dec 7, 2021
2 parents e748d21 + a306f26 commit 9021fd4
Show file tree
Hide file tree
Showing 13 changed files with 1,170 additions and 276 deletions.
10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,16 @@

Notable changes are documented in this file.

## dev

### Fixed

- Fixed InvalidArgument raised for callable default

### Added

- number prompt

## 0.3.0 (12/10/2021)

**New Documentation: [inquirerpy.readthedocs.io](https://inquirerpy.readthedocs.io/en/latest/)**
Expand Down
1 change: 1 addition & 0 deletions InquirerPy/enum.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@
INQUIRERPY_POINTER_SEQUENCE: str = "\u276f"
INQUIRERPY_FILL_CIRCLE_SEQUENCE: str = "\u25c9"
INQUIRERPY_EMPTY_CIRCLE_SEQUENCE: str = "\u25cb"
INQUIRERPY_QMARK_SEQUENCE: str = "\u003f"
1 change: 1 addition & 0 deletions InquirerPy/inquirer.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,6 @@
from InquirerPy.prompts import FuzzyPrompt as fuzzy
from InquirerPy.prompts import InputPrompt as text
from InquirerPy.prompts import ListPrompt as select
from InquirerPy.prompts import NumberPrompt as number
from InquirerPy.prompts import RawlistPrompt as rawlist
from InquirerPy.prompts import SecretPrompt as secret
1 change: 1 addition & 0 deletions InquirerPy/prompts/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,6 @@
from InquirerPy.prompts.fuzzy import FuzzyPrompt
from InquirerPy.prompts.input import InputPrompt
from InquirerPy.prompts.list import ListPrompt
from InquirerPy.prompts.number import NumberPrompt
from InquirerPy.prompts.rawlist import RawlistPrompt
from InquirerPy.prompts.secret import SecretPrompt
488 changes: 488 additions & 0 deletions InquirerPy/prompts/number.py

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions InquirerPy/resolver.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
from InquirerPy.prompts.fuzzy import FuzzyPrompt
from InquirerPy.prompts.input import InputPrompt
from InquirerPy.prompts.list import ListPrompt
from InquirerPy.prompts.number import NumberPrompt
from InquirerPy.prompts.rawlist import RawlistPrompt
from InquirerPy.prompts.secret import SecretPrompt
from InquirerPy.utils import InquirerPyQuestions, InquirerPySessionResult, get_style
Expand All @@ -28,10 +29,9 @@
"rawlist": RawlistPrompt,
"expand": ExpandPrompt,
"fuzzy": FuzzyPrompt,
"number": NumberPrompt,
}

list_prompts = {"list", "checkbox", "rawlist", "expand", "fuzzy"}


def prompt(
questions: InquirerPyQuestions,
Expand Down
151 changes: 0 additions & 151 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,159 +20,8 @@ as well as more customisation options.

<!-- end intro -->

↓↓↓ Simple AWS S3 uploader/downloader prompt.

> Note: [boto3](https://github.com/boto/boto3) package and configured AWS credentials is required for the following example.
![Demo](https://github.com/kazhala/gif/blob/master/InquirerPy-demo.gif)

<!-- start example -->

<details>
<summary>Classic Syntax (PyInquirer)</summary>

```python
import boto3

from InquirerPy import prompt
from InquirerPy.exceptions import InvalidArgument
from InquirerPy.validator import PathValidator

client = boto3.client("s3")


def get_bucket(_):
return [bucket["Name"] for bucket in client.list_buckets()["Buckets"]]


def walk_s3_bucket(result):
response = []
paginator = client.get_paginator("list_objects")
for result in paginator.paginate(Bucket=result["bucket"]):
for file in result["Contents"]:
response.append(file["Key"])
return response


def is_upload(result):
return result[0] == "Upload"


questions = [
{
"message": "Select an S3 action:",
"type": "list",
"choices": ["Upload", "Download"],
},
{
"message": "Enter the filepath to upload:",
"type": "filepath",
"when": is_upload,
"validate": PathValidator(),
"only_files": True,
},
{
"message": "Select a bucket:",
"type": "fuzzy",
"choices": get_bucket,
"name": "bucket",
},
{
"message": "Select files to download:",
"type": "fuzzy",
"when": lambda _: not is_upload(_),
"choices": walk_s3_bucket,
"multiselect": True,
},
{
"message": "Enter destination folder:",
"type": "filepath",
"when": lambda _: not is_upload(_),
"only_directories": True,
"validate": PathValidator(),
},
{"message": "Confirm?", "type": "confirm", "default": False},
]

try:
result = prompt(questions, vi_mode=True)
except InvalidArgument:
print("No available choices")

# Download or Upload the file based on result ...
```

</details>

<details>
<summary>Alternative Syntax</summary>

```python
import os

import boto3

from InquirerPy import inquirer
from InquirerPy.exceptions import InvalidArgument
from InquirerPy.validator import PathValidator

client = boto3.client("s3")
os.environ["INQUIRERPY_VI_MODE"] = "true"


def get_bucket(_):
return [bucket["Name"] for bucket in client.list_buckets()["Buckets"]]


def walk_s3_bucket(bucket):
response = []
paginator = client.get_paginator("list_objects")
for result in paginator.paginate(Bucket=bucket):
for file in result["Contents"]:
response.append(file["Key"])
return response


try:
action = inquirer.select(
message="Select an S3 action:", choices=["Upload", "Download"]
).execute()

if action == "Upload":
file_to_upload = inquirer.filepath(
message="Enter the filepath to upload:",
validate=PathValidator(),
only_files=True,
).execute()
bucket = inquirer.fuzzy(
message="Select a bucket:", choices=get_bucket
).execute()
else:
bucket = inquirer.fuzzy(
message="Select a bucket:", choices=get_bucket
).execute()
file_to_download = inquirer.fuzzy(
message="Select files to download:",
choices=lambda _: walk_s3_bucket(bucket),
multiselect=True,
).execute()
destination = inquirer.filepath(
message="Enter destination folder:",
only_directories=True,
validate=PathValidator(),
).execute()

confirm = inquirer.confirm(message="Confirm?").execute()
except InvalidArgument:
print("No available choices")

# Download or Upload the file based on result ...
```

</details>

<!-- end example -->

## Motivation

[PyInquirer](https://github.com/CITGuru/PyInquirer) is a great Python port of [Inquirer.js](https://github.com/SBoudrias/Inquirer.js/), however, the project is slowly reaching
Expand Down
10 changes: 1 addition & 9 deletions docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,8 @@
:end-before: <!-- end intro -->
```

```{Note}
[boto3](https://github.com/boto/boto3) package and configured AWS credentials is required for the following example.
```

![Demo](https://assets.kazhala.me/InquirerPy/InquirerPy-demo.gif)

```{include} ../README.md
:start-after: <!-- start example -->
:end-before: <!-- end example -->
```

## Install

```{admonition} Requirements
Expand Down Expand Up @@ -153,6 +144,7 @@ python3 examples/classic/rawlist
pages/prompts/input.md
pages/prompts/secret.md
pages/prompts/filepath.md
pages/prompts/number.md
pages/prompts/confirm.md
pages/prompts/list.md
pages/prompts/rawlist.md
Expand Down
Loading

0 comments on commit 9021fd4

Please sign in to comment.