Repository navigation
Expand file tree
/
Copy pathcli.py
More file actions
84 lines (63 loc) · 2.26 KB
/
Copy pathcli.py
File metadata and controls
84 lines (63 loc) · 2.26 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
import os
from typing import List, Optional
from InquirerPy import inquirer
from InquirerPy.separator import Separator
from InquirerPy.base.control import Choice
from InquirerPy.validator import PathValidator
def get_path(msg: str = "Enter path:") -> str:
"""
Prompt the user to enter a directory path.
Args:
msg (str): The prompt message to display to the user. Defaults to "Enter path:".
Returns:
str: The expanded directory path entered by the user.
"""
input_path = inquirer.filepath(
message=msg,
validate=PathValidator(is_dir=True, message="Input is not a directory"),
only_directories=True,
).execute()
if input_path:
return os.path.expanduser(input_path)
def get_string(msg: str = "Enter string:") -> str:
"""
Prompt the user to enter a string.
Args:
msg (str): The prompt message to display to the user. Defaults to "Enter string:".
Returns:
str: The string entered by the user.
"""
input_string = inquirer.text(
message=msg,
default=""
).execute()
return input_string
def flatten_list(nested_list):
return [item for sublist in nested_list for item in sublist]
def get_selected_resources(resources_list: List[str]) -> Optional[List[str]]:
"""
Prompt the user to select resources from a given list.
Args:
resources_list (List[str]): The list of resources to choose from.
Returns:
Optional[List[str]]: A list of selected resources or None if no selection is made.
"""
choices = inquirer.select(
message="Select resources to move from source to destination project:",
choices=[Choice(value=resources_list, name="Select ALL"), Separator()] + resources_list,
default=None,
multiselect=True,
).execute()
if len(choices) > 0 and isinstance(choices[0], list):
return flatten_list(choices)
else:
return choices
def get_confirm(msg: str = "Confirm?") -> bool:
"""
Prompt the user to confirm an action.
Args:
msg (str): The prompt message to display to the user. Defaults to "Confirm?".
Returns:
bool: True if the user confirms, False otherwise.
"""
return inquirer.confirm(message=msg, default=True).execute()