Skip to content

Commit 425c483

Browse files
authored
Update cli.py
Implementation a feature such that users can choose a file from inside the current directory based on a displayed index instead of a filename, collision of filenames with indices handled with the help of a special character
1 parent b01a198 commit 425c483

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

caltechdata_api/cli.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -360,6 +360,7 @@ def upload_supporting_file(record_id=None):
360360
filepaths = []
361361
file_link = ""
362362
file_links = []
363+
idx = 0
363364
while True:
364365
choice = get_user_input(
365366
"Do you want to upload or link data files? (upload/link/n): "
@@ -402,10 +403,10 @@ def upload_supporting_file(record_id=None):
402403
files = [
403404
f for f in os.listdir() if not f.endswith(".json") and os.path.isfile(f)
404405
]
405-
print("\n".join(files))
406+
print((""+ str(++idx) + "/ \n").join(files))
406407
while True:
407408
filename = get_user_input(
408-
"Enter the filename to upload as a supporting file (or '*' to get all files currently in the directory, otherwise 'n' to finish): "
409+
"Enter the filename to upload as a supporting file (or '*' to get all files currently in the directory, or the index number of the file as displayed followed by a /, otherwise 'n' to finish): "
409410
)
410411
if filename == "*":
411412
for files_name in files:
@@ -414,6 +415,11 @@ def upload_supporting_file(record_id=None):
414415
print("All files added successfully")
415416
elif filename == "n":
416417
break
418+
elif filename[len(filename)-1] == '/':
419+
files_name = files[int(filename[0])-1]
420+
filepath = os.path.abspath(files_name)
421+
filepaths.append(filepath)
422+
print("File added successfully")
417423
elif filename in files:
418424
file_size = os.path.getsize(filename)
419425
if file_size > 1024 * 1024 * 1024:

0 commit comments

Comments
 (0)