Repository: ErykMroczek/mofmt (language: python)

Issue:
Add --version argument
Currently there is no quick way to get the current version of mofmt on the command line. 

With `mofmt --version`, mofmt tries to format a file named `--version`.


Discussion / hints:

Fix patch:
diff --git a/mofmt/__init__.py b/mofmt/__init__.py
index e69de29..e19434e 100644
--- a/mofmt/__init__.py
+++ b/mofmt/__init__.py
@@ -0,0 +1,1 @@
+__version__ = "0.3.3"
diff --git a/mofmt/mofmt.py b/mofmt/mofmt.py
index 351416f..50f65e7 100644
--- a/mofmt/mofmt.py
+++ b/mofmt/mofmt.py
@@ -2,19 +2,35 @@
 from itertools import chain
 from pathlib import Path
 
+from mofmt import __version__
 from mofmt.io import get_files_from_dir, read_file, write_file
 from mofmt.parsing import parse_source
 from mofmt.printing import Printer
 
+HELP_MSG = """
+mofmt: Modelica code formatter
+
+Usage: mofmt SRC ...
+
+Options:
+-h, --help: display this message and exit
+-v, --version: display a version number and exit
+"""
+
 
 def main() -> None:
+    if len(sys.argv) < 2:
+        raise SystemExit(HELP_MSG)
+    else:
+        if sys.argv[1] in ("-h", "--help"):
+            raise SystemExit(HELP_MSG)
+        elif sys.argv[1] in ("-v", "--version"):
+            raise SystemExit(f"mofmt, {__version__}")
     format_files(sys.argv)
 
 
 def format_files(args: list[str]) -> None:
     """Format files specified in argument list"""
-    if len(args) < 2:
-        raise SystemExit("mofmt takes at least one argument (file/directory path)")
     paths = [Path(arg) for arg in args[1:]]
     modelica_files = list(
         chain.from_iterable(


Test patch:
diff --git a/tests/functional/test_mofmt.py b/tests/functional/test_mofmt.py
index 04a0329..663640b 100644
--- a/tests/functional/test_mofmt.py
+++ b/tests/functional/test_mofmt.py
@@ -95,12 +95,6 @@ def test_recursive_directories(tmp_path):
 
 def test_errors(tmp_path):
     """Check error handling"""
-    # Check argument parsing
-    with pytest.raises(SystemExit):
-        format_files(["mofmt"])
-    # Check nonexistent files handling
-    with pytest.raises(FileNotFoundError):
-        format_files(["mofmt", "not_exists"])
     # Check file extension reckognition
     p = Path(tmp_path, "file.txt")
     p.write_text(INPUT_CODE, "utf-8")