From a2f41b220a03b7cc86fe856d01585015920130d8 Mon Sep 17 00:00:00 2001 From: Mateusz Masiarz Date: Thu, 25 Jul 2024 22:54:46 +0200 Subject: [PATCH] Aliases for commands (#245) * Short names for commands * Update readme with information about aliases --- README.md | 9 +++++++++ setup.cfg | 1 + src/sinol_make/__init__.py | 5 +++++ src/sinol_make/commands/doc/__init__.py | 3 +++ src/sinol_make/commands/export/__init__.py | 3 +++ src/sinol_make/commands/gen/__init__.py | 3 +++ src/sinol_make/commands/inwer/__init__.py | 3 +++ src/sinol_make/commands/run/__init__.py | 2 ++ src/sinol_make/commands/verify/__init__.py | 3 +++ src/sinol_make/interfaces/BaseCommand.py | 7 +++++++ 10 files changed, 39 insertions(+) diff --git a/README.md b/README.md index 4f47d199..47e98b1a 100644 --- a/README.md +++ b/README.md @@ -94,6 +94,15 @@ You can also run multiple commands at once, for example: sinol-make gen prog/abcingen2.cpp inwer --cpus 4 run --tests abc1*.in doc export --no-statement ``` +There are also available short aliases for the commands: +- `sinol-make r` for `sinol-make run` +- `sinol-make g` for `sinol-make gen` +- `sinol-make i` for `sinol-make inwer` +- `sinol-make e` for `sinol-make export` +- `sinol-make d` for `sinol-make doc` +- `sinol-make v` for `sinol-make verify` +- `sm` for `sinol-make` + ### Reporting bugs and contributing code - Want to report a bug or request a feature? [Open an issue](https://github.com/sio2project/sinol-make/issues). diff --git a/setup.cfg b/setup.cfg index 542bc314..85505e9f 100644 --- a/setup.cfg +++ b/setup.cfg @@ -44,6 +44,7 @@ tests = [options.entry_points] console_scripts = sinol-make = sinol_make:main + sm = sinol_make:main [tool:pytest] testpaths = diff --git a/src/sinol_make/__init__.py b/src/sinol_make/__init__.py index 5196abf8..250751f8 100644 --- a/src/sinol_make/__init__.py +++ b/src/sinol_make/__init__.py @@ -53,11 +53,16 @@ def main_exn(): curr_args = [] commands = util.get_commands() commands_dict = {command.get_name(): command for command in commands} + commands_short_dict = {command.get_short_name(): command for command in commands if command.get_short_name()} for arg in sys.argv[1:]: if arg in commands_dict.keys() and not (len(curr_args) > 0 and curr_args[0] == 'init'): if curr_args: arguments.append(curr_args) curr_args = [arg] + elif arg in commands_short_dict.keys() and not (len(curr_args) > 0 and curr_args[0] == 'init'): + if curr_args: + arguments.append(curr_args) + curr_args = [commands_short_dict[arg].get_name()] else: curr_args.append(arg) if curr_args: diff --git a/src/sinol_make/commands/doc/__init__.py b/src/sinol_make/commands/doc/__init__.py index ace6f803..0ec5d5b7 100644 --- a/src/sinol_make/commands/doc/__init__.py +++ b/src/sinol_make/commands/doc/__init__.py @@ -17,6 +17,9 @@ class Command(BaseCommand): def get_name(self): return "doc" + def get_short_name(self): + return "d" + def compile_file_latex_div(self, file_path): print(f'Compiling {os.path.basename(file_path)} (latex to dvi)...') os.chdir(os.path.dirname(file_path)) diff --git a/src/sinol_make/commands/export/__init__.py b/src/sinol_make/commands/export/__init__.py index 358a3aff..ac91a74d 100644 --- a/src/sinol_make/commands/export/__init__.py +++ b/src/sinol_make/commands/export/__init__.py @@ -23,6 +23,9 @@ class Command(BaseCommand): def get_name(self): return "export" + def get_short_name(self): + return "e" + def configure_subparser(self, subparser: argparse.ArgumentParser): parser = subparser.add_parser( self.get_name(), diff --git a/src/sinol_make/commands/gen/__init__.py b/src/sinol_make/commands/gen/__init__.py index 18719100..8f7d33ca 100644 --- a/src/sinol_make/commands/gen/__init__.py +++ b/src/sinol_make/commands/gen/__init__.py @@ -15,6 +15,9 @@ class Command(BaseCommand): def get_name(self): return "gen" + def get_short_name(self): + return "g" + def configure_subparser(self, subparser): parser = subparser.add_parser( self.get_name(), diff --git a/src/sinol_make/commands/inwer/__init__.py b/src/sinol_make/commands/inwer/__init__.py index e0885900..17204166 100644 --- a/src/sinol_make/commands/inwer/__init__.py +++ b/src/sinol_make/commands/inwer/__init__.py @@ -23,6 +23,9 @@ class Command(BaseCommand): def get_name(self): return "inwer" + def get_short_name(self): + return "i" + def configure_subparser(self, subparser: argparse.ArgumentParser): parser = subparser.add_parser( self.get_name(), diff --git a/src/sinol_make/commands/run/__init__.py b/src/sinol_make/commands/run/__init__.py index 18aad615..23463c0b 100644 --- a/src/sinol_make/commands/run/__init__.py +++ b/src/sinol_make/commands/run/__init__.py @@ -272,6 +272,8 @@ class Command(BaseCommand): def get_name(self): return 'run' + def get_short_name(self): + return 'r' def configure_subparser(self, subparser): parser = subparser.add_parser( diff --git a/src/sinol_make/commands/verify/__init__.py b/src/sinol_make/commands/verify/__init__.py index 978432a9..0c425a5c 100644 --- a/src/sinol_make/commands/verify/__init__.py +++ b/src/sinol_make/commands/verify/__init__.py @@ -21,6 +21,9 @@ class Command(BaseCommand): def get_name(self): return "verify" + def get_short_name(self): + return "v" + def configure_subparser(self, subparser): parser = subparser.add_parser( self.get_name(), diff --git a/src/sinol_make/interfaces/BaseCommand.py b/src/sinol_make/interfaces/BaseCommand.py index 30c76f9a..256d8131 100644 --- a/src/sinol_make/interfaces/BaseCommand.py +++ b/src/sinol_make/interfaces/BaseCommand.py @@ -11,6 +11,13 @@ def get_name(self): pass + def get_short_name(self): + """ + Get short name of command + """ + return None + + def configure_subparser(self, subparser): """ Configure subparser for command