Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Integrate with Cmd objects #29

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions src/Glob.jl
Original file line number Diff line number Diff line change
Expand Up @@ -291,6 +291,26 @@ end
macro glob_str(pattern) GlobMatch(pattern) end
macro glob_mstr(pattern) GlobMatch(pattern) end

"""
@g"GLOB"

Create a Cmd object based on GLOB, allowing string interpolation.

Relative globs are based on `pwd()`.
"""
macro g_str(pattern) :(do_g($(esc(Meta.parse("\"$(escape_string(pattern))\""))))) end

function do_g(pattern)
isempty(pattern) && throw(ErrorException("Glob strings cannot be empty"))
pattern == "/" && return Cmd(["/"])
dir = pwd()
if pattern[1] == '/'
pattern = pattern[2:end]
dir = "/"
end
Cmd(glob(Glob.GlobMatch(pattern), dir))
end

struct GlobMatch
pattern::Vector
GlobMatch(pattern) = isempty(pattern) ? error("GlobMatch pattern cannot be an empty vector") : new(pattern)
Expand Down