@@ -8,9 +8,24 @@ defmodule Bootleg.Config do
8
8
9
9
defmacro __using__ ( _ ) do
10
10
quote do
11
- import Bootleg.Config , only: [ role: 2 , role: 3 , config: 2 , config: 1 , config: 0 ,
12
- before_task: 2 , after_task: 2 , invoke: 1 , task: 2 , remote: 1 , remote: 2 ,
13
- remote: 3 , load: 1 , upload: 3 , download: 3 ]
11
+ import Bootleg.Config ,
12
+ only: [
13
+ role: 2 ,
14
+ role: 3 ,
15
+ config: 2 ,
16
+ config: 1 ,
17
+ config: 0 ,
18
+ before_task: 2 ,
19
+ after_task: 2 ,
20
+ invoke: 1 ,
21
+ task: 2 ,
22
+ remote: 1 ,
23
+ remote: 2 ,
24
+ remote: 3 ,
25
+ load: 1 ,
26
+ upload: 3 ,
27
+ download: 3
28
+ ]
14
29
end
15
30
end
16
31
@@ -45,20 +60,24 @@ defmodule Bootleg.Config do
45
60
if name == :all do
46
61
raise ArgumentError , ":all is reserved by bootleg and refers to all defined roles."
47
62
end
63
+
48
64
user = Keyword . get ( options , :user , System . get_env ( "USER" ) )
49
- ssh_options = Enum . filter ( options , & Enum . member? ( SSH . supported_options , elem ( & 1 , 0 ) ) == true )
65
+
66
+ ssh_options =
67
+ Enum . filter ( options , & ( Enum . member? ( SSH . supported_options ( ) , elem ( & 1 , 0 ) ) == true ) )
68
+
69
+ # identity needs to be present in both options lists
50
70
role_options =
51
- options -- ssh_options
71
+ ( options -- ssh_options )
52
72
|> Keyword . put ( :user , user )
53
- # identity needs to be present in both options lists
54
73
|> Keyword . put ( :identity , ssh_options [ :identity ] )
55
74
|> Keyword . get_and_update ( :identity , fn val ->
56
- if val || Keyword . has_key? ( ssh_options , :identity ) do
57
- { val , val || ssh_options [ :identity ] }
58
- else
59
- :pop
60
- end
61
- end )
75
+ if val || Keyword . has_key? ( ssh_options , :identity ) do
76
+ { val , val || ssh_options [ :identity ] }
77
+ else
78
+ :pop
79
+ end
80
+ end )
62
81
|> elem ( 1 )
63
82
64
83
quote bind_quoted: binding ( ) do
@@ -73,6 +92,7 @@ defmodule Bootleg.Config do
73
92
hosts: [ ] ,
74
93
options: role_options
75
94
}
95
+
76
96
role =
77
97
:roles
78
98
|> Bootleg.Config.Agent . get ( )
@@ -165,19 +185,29 @@ defmodule Bootleg.Config do
165
185
defp add_callback ( task , position , caller , do: block ) do
166
186
file = caller . file ( )
167
187
line = caller . line ( )
188
+
168
189
quote do
169
190
hook_number = Bootleg.Config.Agent . increment ( :next_hook_number )
170
- module_name = String . to_atom ( "Elixir.Bootleg.DynamicCallbacks." <>
171
- String . capitalize ( "#{ unquote ( position ) } " ) <> String . capitalize ( "#{ unquote ( task ) } " ) <>
172
- "#{ hook_number } " )
191
+
192
+ module_name =
193
+ String . to_atom (
194
+ "Elixir.Bootleg.DynamicCallbacks." <>
195
+ String . capitalize ( "#{ unquote ( position ) } " ) <>
196
+ String . capitalize ( "#{ unquote ( task ) } " ) <> "#{ hook_number } "
197
+ )
198
+
173
199
defmodule module_name do
174
200
@ file unquote ( file )
175
201
def execute , do: unquote ( block )
176
202
def location , do: { unquote ( file ) , unquote ( line ) }
177
203
hook_list_name = :"#{ unquote ( position ) } _hooks"
178
204
hooks = Keyword . get ( Bootleg.Config.Agent . get ( hook_list_name ) , unquote ( task ) , [ ] )
179
- Bootleg.Config.Agent . merge ( hook_list_name , unquote ( task ) , hooks ++
180
- [ [ module_name , :execute ] ] )
205
+
206
+ Bootleg.Config.Agent . merge (
207
+ hook_list_name ,
208
+ unquote ( task ) ,
209
+ hooks ++ [ [ module_name , :execute ] ]
210
+ )
181
211
end
182
212
end
183
213
end
@@ -283,9 +313,12 @@ defmodule Bootleg.Config do
283
313
284
314
if Code . ensure_compiled? ( module_name ) do
285
315
{ orig_file , orig_line } = module_name . location
286
- UI . warn "warning: task '#{ unquote ( task ) } ' is being redefined. " <>
287
- "The most recent definition will win, but this is probably not what you meant to do. " <>
288
- "The previous definition was at: #{ orig_file } :#{ orig_line } "
316
+
317
+ UI . warn (
318
+ "warning: task '#{ unquote ( task ) } ' is being redefined. " <>
319
+ "The most recent definition will win, but this is probably not what you meant to do. " <>
320
+ "The previous definition was at: #{ orig_file } :#{ orig_line } "
321
+ )
289
322
end
290
323
291
324
original_opts = Code . compiler_options ( )
@@ -300,6 +333,7 @@ defmodule Bootleg.Config do
300
333
after
301
334
Code . compiler_options ( original_opts )
302
335
end
336
+
303
337
:ok
304
338
end
305
339
end
@@ -309,7 +343,7 @@ defmodule Bootleg.Config do
309
343
agent_key
310
344
|> Bootleg.Config.Agent . get ( )
311
345
|> Keyword . get ( task , [ ] )
312
- |> Enum . each ( fn ( [ module , fnref ] ) -> apply ( module , fnref , [ ] ) end )
346
+ |> Enum . each ( fn [ module , fnref ] -> apply ( module , fnref , [ ] ) end )
313
347
end
314
348
315
349
@ spec module_for_task ( atom ) :: atom
@@ -352,6 +386,7 @@ defmodule Bootleg.Config do
352
386
invoke_task_callbacks ( task , :before_hooks )
353
387
354
388
module_name = module_for_task ( task )
389
+
355
390
if Code . ensure_compiled? ( module_name ) do
356
391
apply ( module_name , :execute , [ ] )
357
392
end
@@ -460,6 +495,7 @@ defmodule Bootleg.Config do
460
495
"""
461
496
defmacro remote ( role , options , lines ) do
462
497
roles = unpack_role ( role )
498
+
463
499
quote bind_quoted: binding ( ) do
464
500
Enum . reduce ( roles , [ ] , fn role , outputs ->
465
501
role
@@ -480,9 +516,12 @@ defmodule Bootleg.Config do
480
516
@ spec load ( binary | charlist ) :: :ok | { :error , :enoent }
481
517
def load ( file ) do
482
518
case File . regular? ( file ) do
483
- true -> Code . eval_file ( file )
484
- :ok
485
- false -> { :error , :enoent }
519
+ true ->
520
+ Code . eval_file ( file )
521
+ :ok
522
+
523
+ false ->
524
+ { :error , :enoent }
486
525
end
487
526
end
488
527
@@ -527,6 +566,7 @@ defmodule Bootleg.Config do
527
566
defmacro upload ( role , local_path , remote_path ) do
528
567
{ roles , filters } = split_roles_and_filters ( role )
529
568
roles = unpack_role ( roles )
569
+
530
570
quote bind_quoted: binding ( ) do
531
571
Enum . each ( roles , fn role ->
532
572
role
@@ -580,6 +620,7 @@ defmodule Bootleg.Config do
580
620
defmacro download ( role , remote_path , local_path ) do
581
621
{ roles , filters } = split_roles_and_filters ( role )
582
622
roles = unpack_role ( roles )
623
+
583
624
quote bind_quoted: binding ( ) do
584
625
Enum . each ( roles , fn role ->
585
626
role
@@ -614,8 +655,8 @@ defmodule Bootleg.Config do
614
655
@ doc false
615
656
@ spec cache_project_config ( atom ) :: any
616
657
def cache_project_config ( prop ) do
617
- unless Project . umbrella? do
618
- val = Project . config [ prop ]
658
+ unless Project . umbrella? ( ) do
659
+ val = Project . config ( ) [ prop ]
619
660
Bootleg.Config.Agent . merge ( :config , prop , val )
620
661
val
621
662
else
@@ -640,14 +681,15 @@ defmodule Bootleg.Config do
640
681
@ spec split_roles_and_filters ( atom | keyword ) :: { [ atom ] , keyword }
641
682
defp split_roles_and_filters ( role ) do
642
683
role
643
- |> List . wrap
684
+ |> List . wrap ( )
644
685
|> Enum . split_while ( fn term -> ! is_tuple ( term ) end )
645
686
end
646
687
647
688
@ doc false
648
689
@ spec unpack_role ( atom | keyword ) :: tuple
649
690
defp unpack_role ( role ) do
650
691
wrapped_role = List . wrap ( role )
692
+
651
693
if Enum . any? ( wrapped_role , fn role -> role == :all end ) do
652
694
quote do: Keyword . keys ( Bootleg.Config.Agent . get ( :roles ) )
653
695
else
0 commit comments