main.py
1import sys
2import time
3import utils
4import argparse
5
6
7def get_index_of_config(configs, config_name):
8 for i, config in enumerate(configs):
9 if config == config_name:
10 return i + 1
11 return -1
12
13
14def toInt(input):
15 try:
16 return int(input)
17 except ValueError:
18 return -1
19
20
21def index_to_config_name(configs, index):
22 return configs[index - 1]
23
24
25arg_parser = argparse.ArgumentParser(description="Git Account Manager")
26arg_parser.add_argument(
27 "-c", "--create", help="Create a new configuration", action="store_true"
28)
29arg_parser.add_argument(
30 "-x",
31 "--export",
32 help="Export a configuration or all configurations",
33 action="store_true",
34)
35
36args = arg_parser.parse_args()
37
38
39def main():
40 if args.create:
41 utils.create()
42 sys.exit(0)
43 elif args.export:
44 utils.export()
45 sys.exit(0)
46 else:
47 configs = utils.get_config_names()
48
49 print("Welcome to the Git Account Manager!")
50 print("Available configurations:")
51 for _config in configs:
52 data = utils.get_account_login(
53 index_to_config_name(configs, get_index_of_config(configs, _config))
54 )
55 print(f" - {_config} ({get_index_of_config(configs, _config)}) {data}")
56 print("Please select a configuration to use (by index // Example: 1):")
57
58 config_name_index = input()
59 config_name = index_to_config_name(configs, int(config_name_index))
60
61 if config_name not in configs:
62 print("Invalid configuration name.")
63 sys.exit(1)
64
65 print(f"Using configuration: {config_name}")
66 time.sleep(2)
67
68 utils.load(config_name=config_name)
69
70
71if __name__ == "__main__":
72 main()
73