Skip to content

Commit f4607ba

Browse files
feat: 命令可以通过添加 --yes 参数忽略(直接确认)操作中的所有提示
Merge pull request #26 from DuckDuckStudio/develop-1.8
2 parents d90fd4b + 060b28e commit f4607ba

File tree

7 files changed

+58
-50
lines changed

7 files changed

+58
-50
lines changed

.github/workflows/build-release.yml

+4-4
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,10 @@ jobs:
3939

4040
- name: 压缩发行版
4141
run: |
42-
7z a .\version\Release\zh-CN\GitHub-Labels-Manager-v1.7.zip .\version\Code\zh-CN
43-
7z a .\version\Release\en-US\GitHub-Labels-Manager-v1.7-EN.zip .\version\Code\en-US
44-
7z a .\version\Release\zh-CN\GitHub-Labels-Manager-v1.7.7z .\version\Code\zh-CN
45-
7z a .\version\Release\en-US\GitHub-Labels-Manager-v1.7-EN.7z .\version\Code\en-US
42+
7z a .\version\Release\zh-CN\GitHub-Labels-Manager-v1.8.zip .\version\Code\zh-CN
43+
7z a .\version\Release\en-US\GitHub-Labels-Manager-v1.8-EN.zip .\version\Code\en-US
44+
7z a .\version\Release\zh-CN\GitHub-Labels-Manager-v1.8.7z .\version\Code\zh-CN
45+
7z a .\version\Release\en-US\GitHub-Labels-Manager-v1.8-EN.7z .\version\Code\en-US
4646
4747
- name: 打包发行版
4848
run: |

other-languages/en_US/config.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
{
2-
"version": "1.7"
2+
"version": "1.8"
33
}

other-languages/en_US/glm.py

+23-19
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
init(autoreset=True)
1212

13-
version = "1.7"
13+
version = "1.8"
1414
script_path = os.path.dirname(os.path.abspath(sys.argv[0]))
1515
config_path = os.path.join(script_path, "config.json")
1616

@@ -29,13 +29,14 @@ def read_token():
2929
print(f"{Fore.RED}{Fore.RESET} Error reading Token:\n{Fore.RED}{e}{Fore.RESET}")
3030
return "error"
3131

32-
def set_token(token):
32+
def set_token(token, yes=False):
3333
# 凭据 github-access-token.glm
3434
# == 移除 ==
3535
if token == "remove":
36-
print(f"{Fore.YELLOW}{Fore.RESET} Are you sure you want to remove the set Token?")
3736
try:
38-
input(f"Press {Fore.BLUE}Enter{Fore.RESET} to confirm, press {Fore.BLUE}Ctrl + C{Fore.RESET} to cancel...")
37+
if not yes:
38+
print(f"{Fore.YELLOW}{Fore.RESET} Are you sure you want to remove the set Token?")
39+
input(f"Press {Fore.BLUE}Enter{Fore.RESET} to confirm, press {Fore.BLUE}Ctrl + C{Fore.RESET} to cancel...")
3940
keyring.delete_password("github-access-token.glm", "github-access-token")
4041
print(f"{Fore.GREEN}{Fore.RESET} The Token was successfully removed.")
4142
return "successful"
@@ -48,7 +49,7 @@ def set_token(token):
4849

4950
# == 添加 ==
5051
# --- Token 检查 ---
51-
if not token.startswith('ghp_'):
52+
if not token.startswith('ghp_') and not yes:
5253
print(f"{Fore.YELLOW}{Fore.RESET} Please check whether the Token is correct.")
5354
try:
5455
input(f"Press {Fore.BLUE}Enter{Fore.RESET} to confirm, press {Fore.BLUE}Ctrl + C{Fore.RESET} to cancel...")
@@ -95,35 +96,38 @@ def formatting_url(url):
9596
print(f"{Fore.RED}{Fore.RESET} The repo link is {Fore.YELLOW}invalid{Fore.RESET}, please make sure your repo link is correct.\n{Fore.BLUE}[!]{Fore.RESET} The repo link should like the following:\n{Fore.GREEN}Correct:{Fore.RESET} https://github.com/example/example-repo/\n{Fore.RED}Error:{Fore.RESET} https://github.com/example/example-repo/labels/")
9697
return "url error"
9798

98-
def get_labels(url, save):
99+
def get_labels(url, save, yes=False):
99100
# 本函数有以下行为
100101
# 正常操作保存标签,并返回successful,错误时输出错误原因并返回具体错误信息
101102
# 可能返回如下错误
102103
# cancel 操作取消 | get error 获取时出错
103104

105+
# v1.8
106+
# 在调用时如果传入 yes=True则直接确认所有提示
107+
104108
# 获取标签
105109

106110
if save:
107111
output = save
108112
else:
113+
# 无论是否 --yes 都要选择
109114
print("Please select a save location:", end=" ")
110-
111115
output = filedialog.asksaveasfilename(filetypes=[
112116
("Label data json file", "*.json")
113117
])
114118

115119
if not output:
116120
print(f"{Fore.RED}{Fore.RESET} No save location is selected.")
117-
return "cancel"# 返回取消状态
121+
return "cancel" # 返回取消状态
118122

119123
if not output.endswith(".json"):
120124
output += ".json"
121125

122-
if os.path.exists(output):
126+
if os.path.exists(output) and not yes:
123127
print(f"{Fore.YELLOW}{Fore.RESET} The save location is occupied! Whether to overwrite it? [Y/N]")
124128
if input(f"{Fore.BLUE}?{Fore.RESET} [Y] Confirm [N] Cancel: ").lower() not in ["是", "覆盖", "overwrite", "y", "yes"]:
125129
print(f"{Fore.BLUE}[!]{Fore.RESET} Cancelled operation.")
126-
return "cancel"# 返回取消状态
130+
return "cancel" # 返回取消状态
127131

128132
print(f"\r{Fore.GREEN}{Fore.RESET} The save location has been selected: {Fore.BLUE}{output}{Fore.RESET}")
129133
# ------------
@@ -268,11 +272,11 @@ def set_labels(url, token, json_file=None):
268272

269273
# ---------------------------------------------------------------------------
270274

271-
def copy_labels(source_url, set_url, token, json_file=os.path.join(script_path, "labels-temp.json"), save=False):
275+
def copy_labels(source_url, set_url, token, json_file, save=False, yes=False):
272276
# 调用get与set函数复制仓库标签
273277
# 传入先所有者,再仓库名
274278
# 先源仓库,再目标仓库,token,json_file,save
275-
if get_labels(source_url, json_file) == "successful":
279+
if get_labels(source_url, json_file, yes) == "successful":
276280
if set_labels(set_url, token, json_file) == "successful":
277281
if not save:
278282
try:
@@ -293,6 +297,7 @@ def main():
293297
parser_get = subparsers.add_parser('get', help='Get labels')
294298
parser_get.add_argument('repo_url', type=str, help='GitHub repo URL')
295299
parser_get.add_argument('--save', type=str, help='Location where the label information is saved')
300+
parser_get.add_argument('--yes', help='Ignore (confirm directly) all prompts in the operation', action='store_true')
296301

297302
# 命令:set
298303
parser_set = subparsers.add_parser('set', help='Set labels')
@@ -307,13 +312,15 @@ def main():
307312
parser_copy.add_argument('--token', type=str, help='GitHub Token')
308313
parser_copy.add_argument('--json', type=str, help='Location of the Label data json file (default: labels-temp.json in the glm directory)')
309314
parser_copy.add_argument('--save', help='Reserve the Label data json file', action='store_true')
315+
parser_copy.add_argument('--yes', help='Ignore (confirm directly) all prompts in the operation', action='store_true')
310316

311317
# 命令:config
312318
parser_config = subparsers.add_parser('config', help='Modify the configuration of the program')
313319
parser_config.add_argument('--token', type=str, help='Set GitHub Token')
314320
parser_config.add_argument('--edit', help='Open configuration file', action='store_true')
315321
parser_config.add_argument('--version', help='Displays the version of GitHub Labels Manager (GLM)', action='store_true')
316322
parser_config.add_argument('--show', help='Show current configuration', action='store_true')
323+
parser_config.add_argument('--yes', help='Ignore (confirm directly) all prompts in the operation', action='store_true')
317324

318325
# 命令:clear
319326
parser_clear = subparsers.add_parser('clear', help='Clear labels')
@@ -328,7 +335,7 @@ def main():
328335
running_result = formatting_url(args.repo_url)
329336
if running_result == "url error":
330337
return 1, running_result
331-
running_result = get_labels(running_result, args.save)
338+
running_result = get_labels(running_result, args.save, args.yes)
332339
if running_result in ["cancel", "get error"]:
333340
return 1, running_result
334341
elif args.command == 'set':
@@ -370,12 +377,9 @@ def main():
370377
json_file = args.json
371378
if not json_file.endswith(".json"):
372379
json_file += ".json"
373-
if args.save:
374-
running_result = copy_labels(source_repo, set_repo, token, json_file, True)
375-
else:
376-
running_result = copy_labels(source_repo, set_repo, token, json_file)
380+
running_result = copy_labels(source_repo, set_repo, token, json_file, args.save, args.yes)
377381
else:
378-
running_result = copy_labels(source_repo, set_repo, token)
382+
running_result = copy_labels(source_repo, set_repo, token, os.path.join(script_path, "labels-temp.json"), False, args.yes)
379383
if running_result in ["file error", "function not return successful"]:
380384
return 1, running_result
381385
elif args.command == 'config':
@@ -391,7 +395,7 @@ def main():
391395

392396
print(f"{Fore.GREEN}{Fore.RESET} Current configuration information:\n Account configuration:\n Token: {token}\n Program configuration:\n Version: {Fore.BLUE}GitHub Labels Manager v{version} by 鸭鸭「カモ」{Fore.RESET}\n Installed in: {Fore.BLUE}{script_path}{Fore.RESET}")
393397
elif args.token:
394-
running_result = set_token(args.token)
398+
running_result = set_token(args.token, args.yes)
395399
if running_result == "error":
396400
return 1, running_result
397401
elif args.edit:

pack.iss

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
[Setup]
22
AppName=GitHub 标签管理器
3-
AppVersion=1.7
4-
VersionInfoVersion=1.7
3+
AppVersion=1.8
4+
VersionInfoVersion=1.8
55
AppPublisher=DuckStudio
66
VersionInfoCopyright=Copyright (c) 鸭鸭「カモ」
77
AppPublisherURL=https://duckduckstudio.github.io/yazicbs.github.io/
88
DefaultDirName={autopf}\GitHub_Labels_Manager
99
DefaultGroupName=GitHub 标签管理器
1010
UninstallDisplayIcon={app}\glm.exe
1111
OutputDir=.\version\Release\zh-CN
12-
OutputBaseFilename=GitHub_Labels_Manager_Setup_v1.7
12+
OutputBaseFilename=GitHub_Labels_Manager_Setup_v1.8
1313
SetupIconFile=.\ico.ico
1414
LicenseFile=.\LICENSE
1515
Compression=lzma2

packEN.iss

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
[Setup]
22
AppName=GitHub Labels Manager
3-
AppVersion=1.7
4-
VersionInfoVersion=1.7
3+
AppVersion=1.8
4+
VersionInfoVersion=1.8
55
AppPublisher=DuckStudio
66
VersionInfoCopyright=Copyright (c) 鸭鸭「カモ」
77
AppPublisherURL=https://duckduckstudio.github.io/yazicbs.github.io/
88
DefaultDirName={autopf}\GitHub_Labels_Manager
99
DefaultGroupName=GitHub Labels Manager
1010
UninstallDisplayIcon={app}\glm.exe
1111
OutputDir=.\version\Release\en-US
12-
OutputBaseFilename=GitHub_Labels_Manager_Setup_v1.7-EN
12+
OutputBaseFilename=GitHub_Labels_Manager_Setup_v1.8-EN
1313
SetupIconFile=.\ico.ico
1414
LicenseFile=.\LICENSE
1515
Compression=lzma2

程序脚本/config.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
{
2-
"version": "1.7"
2+
"version": "1.8"
33
}

程序脚本/glm.py

+23-19
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
init(autoreset=True)
1212

13-
version = "1.7"
13+
version = "1.8"
1414
script_path = os.path.dirname(os.path.abspath(sys.argv[0]))
1515
config_path = os.path.join(script_path, "config.json")
1616

@@ -29,13 +29,14 @@ def read_token():
2929
print(f"{Fore.RED}{Fore.RESET} 读取Token时出错:\n{Fore.RED}{e}{Fore.RESET}")
3030
return "error"
3131

32-
def set_token(token):
32+
def set_token(token, yes=False):
3333
# 凭据 github-access-token.glm
3434
# == 移除 ==
3535
if token == "remove":
36-
print(f"{Fore.YELLOW}{Fore.RESET} 确定要移除设置的Token?")
3736
try:
38-
input(f"按{Fore.BLUE}Enter{Fore.RESET}键确认,按{Fore.BLUE}Ctrl + C{Fore.RESET}键取消...")
37+
if not yes:
38+
print(f"{Fore.YELLOW}{Fore.RESET} 确定要移除设置的Token?")
39+
input(f"按{Fore.BLUE}Enter{Fore.RESET}键确认,按{Fore.BLUE}Ctrl + C{Fore.RESET}键取消...")
3940
keyring.delete_password("github-access-token.glm", "github-access-token")
4041
print(f"{Fore.GREEN}{Fore.RESET} 成功移除设置的Token")
4142
return "successful"
@@ -48,7 +49,7 @@ def set_token(token):
4849

4950
# == 添加 ==
5051
# --- Token 检查 ---
51-
if not token.startswith('ghp_'):
52+
if not token.startswith('ghp_') and not yes:
5253
print(f"{Fore.YELLOW}{Fore.RESET} 请确认Token是否正确")
5354
try:
5455
input(f"按{Fore.BLUE}Enter{Fore.RESET}键确认,按{Fore.BLUE}Ctrl + C{Fore.RESET}键取消...")
@@ -95,35 +96,38 @@ def formatting_url(url):
9596
print(f"{Fore.RED}{Fore.RESET} 仓库链接{Fore.YELLOW}无效{Fore.RESET},请确保你的仓库链接正确\n{Fore.BLUE}[!]{Fore.RESET} 建议检查链接是否过度,例如以下情况:\n{Fore.GREEN}正确:{Fore.RESET} https://github.com/example/example-repo/\n{Fore.RED}错误{Fore.RESET} https://github.com/example/example-repo/labels/")
9697
return "url error"
9798

98-
def get_labels(url, save):
99+
def get_labels(url, save, yes=False):
99100
# 本函数有以下行为
100101
# 正常操作保存标签,并返回successful,错误时输出错误原因并返回具体错误信息
101102
# 可能返回如下错误
102103
# cancel 操作取消 | get error 获取时出错
103104

105+
# v1.8
106+
# 在调用时如果传入 yes=True则直接确认所有提示
107+
104108
# 获取标签
105109

106110
if save:
107111
output = save
108112
else:
113+
# 无论是否 --yes 都要选择
109114
print("请选择保存位置:", end=" ")
110-
111115
output = filedialog.asksaveasfilename(filetypes=[
112116
("标签数据json文件", "*.json")
113117
])
114118

115119
if not output:
116120
print(f"{Fore.RED}{Fore.RESET} 未选择保存位置")
117-
return "cancel"# 返回取消状态
121+
return "cancel" # 返回取消状态
118122

119123
if not output.endswith(".json"):
120124
output += ".json"
121125

122-
if os.path.exists(output):
126+
if os.path.exists(output) and not yes:
123127
print(f"{Fore.YELLOW}{Fore.RESET} 保存位置已被占用!是否覆盖 [Y/N]")
124128
if input(f"{Fore.BLUE}?{Fore.RESET} [Y] 覆盖 [N] 取消: ").lower() not in ["是", "覆盖", "y", "yes"]:
125129
print(f"{Fore.BLUE}[!]{Fore.RESET} 已取消操作")
126-
return "cancel"# 返回取消状态
130+
return "cancel" # 返回取消状态
127131

128132
print(f"\r{Fore.GREEN}{Fore.RESET} 已选择保存位置: {Fore.BLUE}{output}{Fore.RESET}")
129133
# ------------
@@ -268,11 +272,11 @@ def set_labels(url, token, json_file=None):
268272

269273
# ---------------------------------------------------------------------------
270274

271-
def copy_labels(source_url, set_url, token, json_file=os.path.join(script_path, "labels-temp.json"), save=False):
275+
def copy_labels(source_url, set_url, token, json_file, save=False, yes=False):
272276
# 调用get与set函数复制仓库标签
273277
# 传入先所有者,再仓库名
274278
# 先源仓库,再目标仓库,token,json_file,save
275-
if get_labels(source_url, json_file) == "successful":
279+
if get_labels(source_url, json_file, yes) == "successful":
276280
if set_labels(set_url, token, json_file) == "successful":
277281
if not save:
278282
try:
@@ -293,6 +297,7 @@ def main():
293297
parser_get = subparsers.add_parser('get', help='获取标签')
294298
parser_get.add_argument('repo_url', type=str, help='GitHub仓库URL')
295299
parser_get.add_argument('--save', type=str, help='标签信息保存的位置')
300+
parser_get.add_argument('--yes', help='忽略(直接确认)操作中的所有提示', action='store_true')
296301

297302
# 命令:set
298303
parser_set = subparsers.add_parser('set', help='设置标签')
@@ -307,13 +312,15 @@ def main():
307312
parser_copy.add_argument('--token', type=str, help='GitHub访问令牌')
308313
parser_copy.add_argument('--json', type=str, help='标签数据文件的存放位置(默认为glm所在目录下的labels-temp.json)')
309314
parser_copy.add_argument('--save', help='保留获取到的标签数据文件', action='store_true')
315+
parser_copy.add_argument('--yes', help='忽略(直接确认)操作中的所有提示', action='store_true')
310316

311317
# 命令:config
312318
parser_config = subparsers.add_parser('config', help='修改配置')
313319
parser_config.add_argument('--token', type=str, help='设置GitHub访问令牌')
314320
parser_config.add_argument('--edit', help='打开配置文件', action='store_true')
315321
parser_config.add_argument('--version', help='显示GLM版本', action='store_true')
316322
parser_config.add_argument('--show', help='显示当前配置', action='store_true')
323+
parser_config.add_argument('--yes', help='忽略(直接确认)操作中的所有提示', action='store_true')
317324

318325
# 命令:clear
319326
parser_clear = subparsers.add_parser('clear', help='清空标签')
@@ -328,7 +335,7 @@ def main():
328335
running_result = formatting_url(args.repo_url)
329336
if running_result == "url error":
330337
return 1, running_result
331-
running_result = get_labels(running_result, args.save)
338+
running_result = get_labels(running_result, args.save, args.yes)
332339
if running_result in ["cancel", "get error"]:
333340
return 1, running_result
334341
elif args.command == 'set':
@@ -370,12 +377,9 @@ def main():
370377
json_file = args.json
371378
if not json_file.endswith(".json"):
372379
json_file += ".json"
373-
if args.save:
374-
running_result = copy_labels(source_repo, set_repo, token, json_file, True)
375-
else:
376-
running_result = copy_labels(source_repo, set_repo, token, json_file)
380+
running_result = copy_labels(source_repo, set_repo, token, json_file, args.save, args.yes)
377381
else:
378-
running_result = copy_labels(source_repo, set_repo, token)
382+
running_result = copy_labels(source_repo, set_repo, token, os.path.join(script_path, "labels-temp.json"), False, args.yes)
379383
if running_result in ["file error", "function not return successful"]:
380384
return 1, running_result
381385
elif args.command == 'config':
@@ -391,7 +395,7 @@ def main():
391395

392396
print(f"{Fore.GREEN}{Fore.RESET} 当前配置信息如下:\n 账户设置:\n Token: {token}\n 程序设置:\n 版本: {Fore.BLUE}GitHub Labels Manager v{version} by 鸭鸭「カモ」{Fore.RESET}\n 安装在: {Fore.BLUE}{script_path}{Fore.RESET}")
393397
elif args.token:
394-
running_result = set_token(args.token)
398+
running_result = set_token(args.token, args.yes)
395399
if running_result == "error":
396400
return 1, running_result
397401
elif args.edit:

0 commit comments

Comments
 (0)