Skip to content

Commit 131a79c

Browse files
committed
🐛 make sure legacy copy targets are executed along with normal targets. v0.4.1 or earlier, copy targets are executed in a separate handler, meaning at least the counter, the number of templated files are reset, and there will be two stastistics. And this change make cli target a clear priority. fix #180
1 parent 5133306 commit 131a79c

File tree

1 file changed

+20
-26
lines changed

1 file changed

+20
-26
lines changed

moban/mobanfile/__init__.py

+20-26
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,14 @@ def find_default_moban_file():
3636
def handle_moban_file_v1(moban_file_configurations, command_line_options):
3737
merged_options = None
3838

39-
targets = moban_file_configurations.get(constants.LABEL_TARGETS)
40-
target = extract_target(command_line_options)
39+
targets = moban_file_configurations.get(constants.LABEL_TARGETS, [])
40+
if constants.LABEL_COPY in moban_file_configurations:
41+
legacy_copy_targets = handle_copy(
42+
merged_options, moban_file_configurations[constants.LABEL_COPY]
43+
)
44+
targets += legacy_copy_targets
45+
46+
cli_target = extract_target(command_line_options)
4147

4248
if constants.LABEL_CONFIG in moban_file_configurations:
4349
merged_options = merge(
@@ -68,27 +74,16 @@ def handle_moban_file_v1(moban_file_configurations, command_line_options):
6874
if template_types:
6975
plugins.ENGINES.register_options(template_types)
7076

71-
if targets:
72-
if target:
73-
targets = target
74-
# If template specified via CLI flag `-t:
75-
# 1. Only update the specified template
76-
# 2. Do not copy
77-
if constants.LABEL_COPY in moban_file_configurations:
78-
del moban_file_configurations[constants.LABEL_COPY]
79-
number_of_templated_files = handle_targets(merged_options, targets)
77+
if cli_target:
78+
number_of_templated_files = handle_targets(
79+
merged_options, [cli_target])
80+
elif targets:
81+
number_of_templated_files = handle_targets(
82+
merged_options, targets)
8083
else:
8184
number_of_templated_files = 0
8285

83-
if constants.LABEL_COPY in moban_file_configurations:
84-
number_of_copied_files = handle_copy(
85-
merged_options, moban_file_configurations[constants.LABEL_COPY]
86-
)
87-
else:
88-
number_of_copied_files = 0
89-
exit_code = reporter.convert_to_shell_exit_code(
90-
number_of_templated_files + number_of_copied_files
91-
)
86+
exit_code = reporter.convert_to_shell_exit_code(number_of_templated_files)
9287
reporter.report_up_to_date()
9388
return exit_code
9489

@@ -100,12 +95,11 @@ def handle_copy(merged_options, copy_config):
10095
copy_targets.append(
10196
{
10297
constants.LABEL_TEMPLATE: src,
103-
constants.LABEL_CONFIG: None,
10498
constants.LABEL_OUTPUT: dest,
10599
constants.LABEL_TEMPLATE_TYPE: constants.TEMPLATE_COPY,
106100
}
107101
)
108-
return handle_targets(merged_options, copy_targets)
102+
return copy_targets
109103

110104

111105
def _iterate_list_of_dicts(list_of_dict):
@@ -134,6 +128,7 @@ def handle_targets(merged_options, targets):
134128
target.set_template_type(primary_template_type)
135129

136130
jobs_for_each_engine[primary_template_type].append(target)
131+
print(target)
137132

138133
count = 0
139134
for template_type in jobs_for_each_engine.keys():
@@ -172,15 +167,14 @@ def extract_target(options):
172167
"Please specify a output file name for %s." % template
173168
)
174169
if config:
175-
result = [
176-
{
170+
result = {
177171
constants.LABEL_TEMPLATE: template,
178172
constants.LABEL_CONFIG: config,
179173
constants.LABEL_OUTPUT: output,
180174
}
181-
]
175+
182176
else:
183-
result = [{output: template}]
177+
result = {output: template}
184178
return result
185179

186180

0 commit comments

Comments
 (0)