Skip to content

Commit

Permalink
Automatically prepend a program name to args in Gmsh.initialize.
Browse files Browse the repository at this point in the history
  • Loading branch information
fredrikekre committed Sep 29, 2022
1 parent b2ff2e2 commit 8ecf02b
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
14 changes: 13 additions & 1 deletion src/Gmsh.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
7 changes: 6 additions & 1 deletion test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 8ecf02b

Please sign in to comment.