整理composer安装版本的python脚本

脚本实现的功能是去除composer安装命令后的版本号

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
def remove_version_numbers(commands):
"""
Remove version numbers from composer require commands.

Args:
commands (list of str): List of composer require commands.

Returns:
list of str: Commands with version numbers removed.
"""
cleaned_commands = []
for command in commands:
# Split the command by space and remove any part that starts with '^'
parts = [part for part in command.split() if not part.startswith('^')]
cleaned_command = ' '.join(parts)
cleaned_commands.append(cleaned_command)

return cleaned_commands


def main():
print("请输入您的 Composer 命令,每行一个。输入 'END' 来结束输入:")
user_input = []
while True:
line = input()
if line == "END":
break
user_input.append(line)

# 移除版本号
cleaned_commands = remove_version_numbers(user_input)
print("\n处理后的命令:")
for command in cleaned_commands:
print(command)


if __name__ == "__main__":
main()