Skip to content

Commit

Permalink
feat: 允许 init 命令带参数
Browse files Browse the repository at this point in the history
  • Loading branch information
NoNormalCreeper committed Dec 2, 2024
1 parent 558c766 commit 4053c01
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 5 deletions.
18 changes: 15 additions & 3 deletions byrdocs/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
command_parser.add_argument("command", nargs='?', help="要执行的命令")
command_parser.add_argument("file", nargs='?', help="要上传的文件路径").completer = argcomplete.completers.FilesCompleter()
command_parser.add_argument("--token", help="指定登录时使用的 token")
command_parser.add_argument("--manually", "-m", action='store_true')

baseURL = "https://byrdocs.org"

Expand Down Expand Up @@ -105,8 +106,8 @@ def upload_progress(chunk, progress_bar: tqdm):
progress_bar.update(chunk)

@interrupt_handler
def _ask_for_init(file_name: str=None) -> str:
ask_for_init(file_name)
def _ask_for_init(file_name: str=None, manually=False) -> str:
ask_for_init(file_name, manually)

@interrupt_handler
def main():
Expand All @@ -129,7 +130,18 @@ def main():
args.command = 'upload'

if args.command == 'init':
_ask_for_init()
if args.file:
if (file_type := get_file_type(args.file)) == "unsupported":
print(error("错误:不支持的文件格式,仅支持上传 PDF 或 ZIP 文件。"))
exit(1)
else:
with open(args.file, "rb") as f:
_ask_for_init(f"{hashlib.md5(f.read()).hexdigest()}.{file_type}")
exit(0)
if args.manually:
_ask_for_init(None, True)
else:
_ask_for_init(None, False)
exit(0)

if args.command == 'validate':
Expand Down
4 changes: 2 additions & 2 deletions byrdocs/yaml_init.py
Original file line number Diff line number Diff line change
Expand Up @@ -203,9 +203,9 @@ def cancel(text="操作已取消。") -> None:
exit(0)


def ask_for_init(file_name: str = None) -> str: # 若需要传入 file_name,需要带上后缀名
def ask_for_init(file_name: str = None, manually: bool = False) -> str: # 若需要传入 file_name,需要带上后缀名
global metadata
if (recent_file_choices_resp := get_recent_file_choices()) is not None:
if not manually and ((recent_file_choices_resp := get_recent_file_choices()) is not None):
recent_file_choices, time_strings = get_recent_file_choices()
if file_name is None:
file_name = inquirer.fuzzy(
Expand Down

0 comments on commit 4053c01

Please sign in to comment.