diff --git a/commands.py b/commands.py index 3ea29fe..5ff5a4c 100644 --- a/commands.py +++ b/commands.py @@ -296,7 +296,7 @@ def _get_branch_status(path: str) -> str: branch_color = Commands._get_branch_color(branch_path[0]) branch = f'{branch_color}{icon}{RESET}{utils.GLYPHS["space"]}{branch_path[0]}{RESET}/{BOLD}{("/".join(branch_path[1:]))}' else: - branch = f'{TEXT["cyan"]}{utils.GLYPHS["branch"]}{RESET}{utils.GLYPHS["space"]}{branch_stdout}' + branch = f'{CYAN}{utils.GLYPHS["branch"]}{RESET}{utils.GLYPHS["space"]}{branch_stdout}' return branch @staticmethod diff --git a/main.py b/main.py index f4c9801..feaa80f 100755 --- a/main.py +++ b/main.py @@ -1,5 +1,4 @@ #!/usr/bin/env python3 -import sys import utils import settings diff --git a/mud.py b/mud.py index e7cd4f2..57fd252 100644 --- a/mud.py +++ b/mud.py @@ -89,23 +89,23 @@ def run(self) -> None: return # Prints version elif sys.argv[1] in COMMANDS['version']: - utils.print_version() - return - elif sys.argv[1] in COMMANDS['configure']: - self.configure() + utils.version() return + # Checks for available updates elif sys.argv[1] in COMMANDS['update']: utils.check_updates(True) return - + # Runs configuration wizard + elif sys.argv[1] in COMMANDS['configure']: + utils.configure() + return current_directory = os.getcwd() self.config = config.Config() - if len(sys.argv) > 1 and sys.argv[1] in [cmd for group in COMMANDS.values() for cmd in group]: - args = self.parser.parse_args() - if args.command in COMMANDS['init']: - self.init(args) - return + # Discovers repositories in current directory + if sys.argv[1] in COMMANDS['init']: + self.init(self.parser.parse_args()) + return self.config.find() self._filter_repos() @@ -158,10 +158,13 @@ def run(self) -> None: else: self.cmd_runner.run_ordered(self.repos.keys(), sys.argv) + def init(self, args) -> None: self.config.data = {} index = 0 directories = [d for d in os.listdir('.') if os.path.isdir(d) and os.path.isdir(os.path.join(d, '.git'))] + print(directories) + print(os.getcwd()) for directory in directories: if directory in self.config.paths(): continue @@ -174,17 +177,6 @@ def init(self, args) -> None: return self.config.save(utils.CONFIG_FILE_NAME) - def configure(self): - utils.settings.config['mud']['run_async'] = str(utils.ask('Do you want to run commands simultaneously for multiple repositories?')) - utils.settings.config['mud']['run_table'] = str(utils.ask('Do you want to see command execution progress in table view? This will limit output content.')) - utils.settings.config['mud']['auto_fetch'] = str(utils.ask(f'Do you want to automatically run {BOLD}\'git fetch\'{RESET} whenever you run commands such as {BOLD}\'mud info\'{RESET}?')) - utils.settings.config['mud']['ask_updates'] = str(utils.ask(f'Do you want to get information about latest updates?')) - utils.settings.config['mud']['nerd_fonts'] = str(utils.ask(f'Do you want to use {BOLD}nerd-fonts{RESET}?')) - utils.settings.config['mud']['simplify_branches'] = str(utils.ask(f'Do you want to simplify branches? (ex. {BOLD}feature/name{RESET} -> {BOLD}f/name{RESET}')) - utils.settings.save() - print('Your settings are updated!') - pass - def add(self, args) -> None: self.config.add_label(args.path, args.label) self.config.save(utils.CONFIG_FILE_NAME) diff --git a/utils.py b/utils.py index 3e3aa6b..5dcf82d 100644 --- a/utils.py +++ b/utils.py @@ -1,6 +1,6 @@ +import sys import random import subprocess -import sys from settings import * from styles import * @@ -66,12 +66,28 @@ def set_up(): sys.exit() +def version() -> None: + os.chdir(os.path.dirname(os.path.abspath(__file__))) + hash = subprocess.check_output(['git', 'rev-parse', '--short', 'HEAD'], text=True).splitlines()[0] + m = random.choice(TEXT[3:]) + u = random.choice(TEXT[3:]) + d = random.choice(TEXT[3:]) + t = random.choice(TEXT[3:]) + v = random.choice(TEXT[3:]) + print(fr''' +{m} __ __{u} __ __{d} _____ +{m}/\ '-./ \{u}/\ \/\ \{d}/\ __-. {BOLD}{t}Multi-directory runner{RESET} [{v}{hash}{RESET}] +{m}\ \ \-./\ \{u} \ \_\ \{d} \ \/\ \ {RESET}Jasur Sadikov +{m} \ \_\ \ \_\{u} \_____\{d} \____- {RESET}https://github.com/jasursadikov/mud +{m} \/_/ \/_/{u}\/_____/{d}\/____/ {RESET}Type 'mud --help' for help +''') + + def check_updates(explicit: bool = False) -> bool: - target_directory = os.curdir + target_directory = os.getcwd() os.chdir(os.path.dirname(os.path.abspath(__file__))) subprocess.run(['git', 'fetch'], check=True) - result = subprocess.run(['git', 'status', '-uno'], capture_output=True, text=True) if 'Your branch is behind' in result.stdout: @@ -106,6 +122,18 @@ def check_updates(explicit: bool = False) -> bool: return False +def configure(): + settings.config['mud']['run_async'] = str(ask('Do you want to run commands simultaneously for multiple repositories?')) + settings.config['mud']['run_table'] = str(ask('Do you want to see command execution progress in table view? This will limit output content.')) + settings.config['mud']['auto_fetch'] = str(ask(f'Do you want to automatically run {BOLD}\'git fetch\'{RESET} whenever you run commands such as {BOLD}\'mud info\'{RESET}?')) + settings.config['mud']['ask_updates'] = str(ask(f'Do you want to get information about latest updates?')) + settings.config['mud']['nerd_fonts'] = str(ask(f'Do you want to use {BOLD}nerd-fonts{RESET}?')) + settings.config['mud']['simplify_branches'] = str(ask(f'Do you want to simplify branches? (ex. {BOLD}feature/name{RESET} -> {BOLD}f/name{RESET}')) + settings.save() + print('Your settings are updated!') + pass + + def ask(text: str) -> bool: print(f"{text} [Y/n] ", end='', flush=True) if sys.platform.startswith('win'): @@ -127,21 +155,4 @@ def ask(text: str) -> bool: def print_error(text: str, code: int = 255) -> None: print(f'{RED}Error:{RESET} {text}') - sys.exit(code) - - -def print_version() -> None: - os.chdir(os.path.dirname(os.path.abspath(__file__))) - hash = subprocess.check_output(['git', 'rev-parse', '--short', 'HEAD'], text=True).splitlines()[0] - m = random.choice(TEXT[3:]) - u = random.choice(TEXT[3:]) - d = random.choice(TEXT[3:]) - t = random.choice(TEXT[3:]) - v = random.choice(TEXT[3:]) - print(fr''' -{m} __ __{u} __ __{d} _____ -{m}/\ '-./ \{u}/\ \/\ \{d}/\ __-. {BOLD}{t}Multi-directory runner{RESET} [{v}{hash}{RESET}] -{m}\ \ \-./\ \{u} \ \_\ \{d} \ \/\ \ {RESET}Jasur Sadikov -{m} \ \_\ \ \_\{u} \_____\{d} \____- {RESET}https://github.com/jasursadikov/mud -{m} \/_/ \/_/{u}\/_____/{d}\/____/ {RESET}Type 'mud --help' for help -''') + sys.exit(code) \ No newline at end of file