@@ -39,12 +39,12 @@ defmodule Mix.Tasks.Zig.Get do
39
39
40
40
- `TAR_COMMAND`: path to a tar executable that is equivalent to gnu tar.
41
41
only useful for non-windows architectures.
42
- - `NO_VERIFY`: disable signature verification of the downloaded file.
43
- Not recommended.
42
+ - `NO_VERIFY`: disable signature verification of the downloaded file.
43
+ Not recommended.
44
44
- `ZIG_ARCHIVE_PATH`: path to desired directory to achive the zig compiler toolchain.
45
45
"""
46
46
47
- defstruct ~w( version path arch os url file verify hash) a
47
+ defstruct ~w( version path arch os url file verify hash force ) a
48
48
49
49
def run ( app_opts ) do
50
50
# Elixir 1.14 cannot take a list of applications for this function
@@ -86,6 +86,10 @@ defmodule Mix.Tasks.Zig.Get do
86
86
parse_opts ( rest , % { so_far | arch: arch } )
87
87
end
88
88
89
+ defp parse_opts ( [ "--force" | rest ] , so_far ) do
90
+ parse_opts ( rest , % { so_far | force: true } )
91
+ end
92
+
89
93
defp set_archive_path ( opts ) do
90
94
case System . get_env ( "ZIG_ARCHIVE_PATH" , "" ) do
91
95
"" -> opts
@@ -102,7 +106,8 @@ defmodule Mix.Tasks.Zig.Get do
102
106
version: @ default_version ,
103
107
path: :filename . basedir ( :user_cache , ~C" zigler" ) ,
104
108
os: os ,
105
- arch: arch
109
+ arch: arch ,
110
+ force: false
106
111
}
107
112
end
108
113
@@ -127,13 +132,16 @@ defmodule Mix.Tasks.Zig.Get do
127
132
defp ensure_destination ( opts ) do
128
133
target_directory = Path . join ( opts . path , "zig-#{ opts . os } -#{ opts . arch } -#{ opts . version } " )
129
134
130
- if File . exists? ( target_directory ) do
131
- Mix . raise (
132
- "destination directory #{ target_directory } already exists. Please remove it and try again."
133
- )
135
+ cond do
136
+ File . exists? ( target_directory ) && opts . force ->
137
+ File . rm_rf! ( target_directory )
138
+ File . exists? ( target_directory ) ->
139
+ Mix . shell ( ) . info ( "zig is already installed, rerun with --force to overwrite" )
140
+ System . halt ( )
141
+ true -> :nothing_to_do
134
142
end
135
143
136
- File . mkdir_p ( opts . path )
144
+ File . mkdir_p! ( opts . path )
137
145
138
146
opts
139
147
end
0 commit comments