From 8ecf02be27c9d4eec38b33afb648b01341f6cb46 Mon Sep 17 00:00:00 2001 From: Fredrik Ekre Date: Thu, 29 Sep 2022 14:42:03 +0200 Subject: [PATCH] Automatically prepend a program name to args in Gmsh.initialize. --- src/Gmsh.jl | 14 +++++++++++++- test/runtests.jl | 7 ++++++- 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/src/Gmsh.jl b/src/Gmsh.jl index b18838f..9691051 100644 --- a/src/Gmsh.jl +++ b/src/Gmsh.jl @@ -14,14 +14,26 @@ already initialized. The argument vector `argv` is passed to `gmsh.initialize`. `argv` can be used to pass command line options to Gmsh, see [Gmsh documentation for more -details](https://gmsh.info/doc/texinfo/gmsh.html#index-Command_002dline-options). +details](https://gmsh.info/doc/texinfo/gmsh.html#index-Command_002dline-options). Note that +this wrapper prepends the program name to `argv` since Gmsh expects that to be the first +entry. If `finalize_atexit` is `true` a Julia exit hook is added, which calls `finalize()`. + +**Example** +```julia +Gmsh.initialize(["-v", "0"]) # initialize with decreased verbosity +``` """ function initialize(argv=String[]; finalize_atexit=true) if Bool(gmsh.isInitialized()) return false end + # Prepend a dummy program name in case argv only contains options + # see https://gitlab.onelab.info/gmsh/gmsh/-/issues/2112 + if length(argv) > 0 && startswith(first(argv), "-") + argv = pushfirst!(copy(argv), "gmsh") + end gmsh.initialize(argv) if finalize_atexit atexit(finalize) diff --git a/test/runtests.jl b/test/runtests.jl index 3ced156..e91368a 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -30,9 +30,14 @@ rm(path, recursive=true) @test Bool(gmsh.isInitialized()) @test length(Base.atexit_hooks) == l Gmsh.finalize() - # argv + # argv with program name @test Gmsh.initialize(["gmsh", "-v", "0"]) @test Bool(gmsh.isInitialized()) @test gmsh.option.getNumber("General.Verbosity") == 0 Gmsh.finalize() + # argv without program name + @test Gmsh.initialize(["-v", "2"]) + @test Bool(gmsh.isInitialized()) + @test gmsh.option.getNumber("General.Verbosity") == 2 + Gmsh.finalize() end