def cmd_delete(args: argparse.Namespace) -> None: stream: AccountsStream = AccountsStream(accounts_json_path) accounts: Accounts = stream.load() name = args.name if not accounts.exist(name): logger.error("Not found that name account.") raise CommandFailedError() accounts.delete(name) stream.save(accounts) logger.info("Deleted successfully")
def cmd_add(args: argparse.Namespace) -> None: stream: AccountsStream = AccountsStream(accounts_json_path) accounts: Accounts = stream.load() name: str = input("git user.name: ") if accounts.exist(name): logger.error("This name is already used") raise CommandFailedError() email: str = input("git user.email: ") account: Account = Account(name, email) accounts.add(account) stream.save(accounts) logger.info("Saved successfully")
def cmd_set(args: argparse.Namespace) -> None: accounts_stream: AccountsStream = AccountsStream(accounts_json_path) accounts: Accounts = accounts_stream.load() name: str = args.name if not accounts.exist(name): logger.error("Not found that name account.") raise CommandFailedError() account: Account = accounts.find_account(name) git_stream: GitConfigStream = GitConfigStream() git_stream.set("user.name", account.name) git_stream.set("user.email", account.email) logger.info("Set successfully")
def cmd_list(args: argparse.Namespace) -> None: stream: AccountsStream = AccountsStream(accounts_json_path) accounts: Accounts = stream.load() if len(accounts) == 0: logger.info("Haven't added accounts yet. try \"gac add\"") raise CommandFailedError() longest_name_length = 0 for account in accounts: longest_name_length = max(longest_name_length, len(account.name)) longest_name_length += 0 logger.info("NAME" + " " * (longest_name_length - 4) + " | EMAIL") logger.info("-" * (longest_name_length + 8)) for account in accounts: logger.info(account.name + " " * (longest_name_length - len(account.name)) + " | " + account.email)
def cmd_current(args: argparse.Namespace) -> None: config_stream: GitConfigStream = GitConfigStream() name: str = config_stream.get("user.name") email: str = config_stream.get("user.email") logger.info("user.name: {}".format(name)) logger.info("user.email: {}".format(email))