diff --git a/README.md b/README.md index 3579f1756..5bd2e7d7e 100644 --- a/README.md +++ b/README.md @@ -146,7 +146,7 @@ Install the prebuilt package and run an example: brew install mflowcode/mfc/mfc mkdir -p ~/mfc_quickstart && cd ~/mfc_quickstart cp $(brew --prefix mfc)/examples/1D_sodshocktube/case.py . -mfc run case.py -n 2 +mfc case.py -n 2 ``` Use `-n X` to select the number of MPI processes. For developer commands (`build`, `test`, etc.), clone the repo and use `./mfc.sh`. diff --git a/docs/documentation/getting-started.md b/docs/documentation/getting-started.md index 3494a14b4..b374e7740 100644 --- a/docs/documentation/getting-started.md +++ b/docs/documentation/getting-started.md @@ -23,11 +23,12 @@ Run a quick example: mkdir -p ~/mfc_quickstart && cd ~/mfc_quickstart cp $(brew --prefix mfc)/examples/1D_sodshocktube/case.py . # Use -n X to choose the number of MPI processes -mfc run case.py -n 2 +mfc case.py -n 2 ``` Notes: -- The Homebrew wrapper supports only `mfc run ...`. Developer commands like `build`, `test`, `clean` are available when you clone the repo and use `./mfc.sh`. +- The Homebrew package uses a simplified syntax: just `mfc ` to run cases. +- Developer commands like `build`, `test`, `clean` are available when you clone the repo and use `./mfc.sh`. - The package bundles a Python venv and prebuilt binaries; no additional setup is required. - Examples are installed at `$(brew --prefix mfc)/examples/`. diff --git a/docs/documentation/running.md b/docs/documentation/running.md index 7438fc591..4270f089d 100644 --- a/docs/documentation/running.md +++ b/docs/documentation/running.md @@ -13,11 +13,11 @@ several supercomputer clusters, both interactively and through batch submission. If you installed MFC via Homebrew, run cases with the `mfc` wrapper: ```bash -mfc run -n 2 +mfc -n 2 ``` - Use `-n X` to control the number of MPI processes (ranks). -- Only the `run` command is supported in the Homebrew wrapper. +- The Homebrew package uses a simplified syntax: just `mfc ` to run cases. - To use developer commands (`build`, `test`, `clean`, etc.), clone the repository and use `./mfc.sh`. - The wrapper passes through runtime flags like `-t pre_process simulation`, `-n`, and others; it always runs with preinstalled binaries. - Examples live at `$(brew --prefix mfc)/examples/`. diff --git a/packaging/homebrew/README.md b/packaging/homebrew/README.md index dd99d2be7..cff50ba70 100644 --- a/packaging/homebrew/README.md +++ b/packaging/homebrew/README.md @@ -15,7 +15,7 @@ Run the 1D Sod shock tube example: ```bash mkdir -p ~/mfc_example && cd ~/mfc_example cp $(brew --prefix mfc)/examples/1D_sodshocktube/case.py . -mfc run case.py -n 2 +mfc case.py -n 2 ``` ## What's Included @@ -28,12 +28,12 @@ mfc run case.py -n 2 ## Usage ```bash -mfc run -n +mfc -n ``` Use `-n X` to set the number of MPI processes. -**Note**: The Homebrew wrapper supports only `mfc run`. For developer commands (`build`, `test`, `clean`, etc.), [clone the repository](https://github.com/MFlowCode/MFC) and use `./mfc.sh`. +**Note**: The Homebrew wrapper supports only running cases. For developer commands (`build`, `test`, `clean`, etc.), [clone the repository](https://github.com/MFlowCode/MFC) and use `./mfc.sh`. ## Documentation diff --git a/packaging/homebrew/mfc.rb b/packaging/homebrew/mfc.rb index 61ca6dfb9..6d28f3fc8 100644 --- a/packaging/homebrew/mfc.rb +++ b/packaging/homebrew/mfc.rb @@ -94,20 +94,17 @@ def install fi done - SUBCMD="${ARGS[0]-}" - # Friendly help and guardrails - if [[ ${#ARGS[@]} -eq 0 ]] || [[ "${SUBCMD}" == "--help" ]] || [[ "${SUBCMD}" == "-h" ]]; then + if [[ ${#ARGS[@]} -eq 0 ]] || [[ "${ARGS[0]-}" == "--help" ]] || [[ "${ARGS[0]-}" == "-h" ]]; then cat <<'HHELP' MFC (Homebrew) #{version} Usage: mfc [options] - mfc run [options] Examples: mfc case.py -n 2 - mfc run case.py -n 2 -t pre_process simulation + mfc examples/1D_sodshocktube/case.py -n 2 -t pre_process simulation Notes: - This Homebrew wrapper uses prebuilt binaries and a preinstalled venv. @@ -117,18 +114,48 @@ def install exit 0 fi - # Smart detection: if first arg looks like a case file, auto-prepend "run" - if [[ "${SUBCMD}" =~ .py$ ]] || [[ -f "${SUBCMD}" ]]; then - ARGS=("run" "${ARGS[@]}") - SUBCMD="run" + # Handle --version flag + if [[ "${ARGS[0]-}" == "--version" ]] || [[ "${ARGS[0]-}" == "-v" ]]; then + echo "MFC (Homebrew) #{version}" + exit 0 fi - if [[ "${SUBCMD}" != "run" ]]; then - echo "mfc (Homebrew): only 'run' is supported in the Homebrew package." - echo "Use 'mfc ' or clone the repository for developer commands." + # Find first non-flag argument + first_nonflag="" + for arg in "${ARGS[@]}"; do + if [[ "$arg" != -* ]]; then + first_nonflag="$arg" + break + fi + done + + # Check if no case file provided + if [[ -z "${first_nonflag}" ]]; then + echo "mfc (Homebrew): missing case file." + echo "Usage: mfc [options]" + echo "Example: mfc case.py -n 2" exit 2 fi + # Check if user accidentally used 'mfc run' syntax (even with flags before it) + if [[ "${first_nonflag}" == "run" ]]; then + echo "mfc (Homebrew): The 'run' command is not needed." + echo "Usage: mfc [options]" + echo "Example: mfc case.py -n 2" + exit 2 + fi + + # Require a readable Python file (not a directory) + if [[ ! "${first_nonflag}" =~ .py$ ]] || [[ ! -f "${first_nonflag}" ]]; then + echo "mfc (Homebrew): first argument must be a readable Python case file." + echo "Given: ${first_nonflag}" + echo "Usage: mfc [options]" + exit 2 + fi + + # Always prepend "run" since this wrapper only supports running cases + ARGS=("run" "${ARGS[@]}") + # Create a temporary working directory (Cellar is read-only) TMPDIR="$(mktemp -d)" trap 'rm -rf "${TMPDIR}"' EXIT @@ -226,8 +253,7 @@ def caveats MFC has been installed successfully! To run a case: - mfc - mfc run (explicit form) + mfc [options] Pre-built binaries are also available directly: pre_process, simulation, post_process