Commit 804f5076 authored by Laurent Peuch's avatar Laurent Peuch
Browse files

refactor: remove -c/-k for -t <target> and rename -C/-K to -c/-k

parent 11dcc5027583
......@@ -120,6 +120,13 @@ All commands share the same CLI arguments. They are:
Default value: None (unused)
-t, --target
Can has the value "cubes", "core" or "clients". Will select the family
of projects specified. Can also be used with "auto-mr" and will skip
refactoring commands not meant for the specified family
Default value: cubes
Sparql query reference
----------------------
......
......@@ -324,8 +324,7 @@ class Command:
number=None,
additional_checks=None,
project=None,
clients_projects=False,
core_projects=False,
target="cubes",
branch_name=None,
commit_message=None,
other_args=None,
......@@ -344,12 +343,13 @@ class Command:
if project:
cubes = [get_project(project)]
elif clients_projects:
cubes = get_all_clients(query)
elif core_projects:
cubes = get_all_core_projects(query)
else:
cubes = get_all_cubes(query)
targets = {
"cubes": get_all_cubes,
"clients": get_all_clients,
"core": get_all_core_projects,
}
cubes = targets[target](query)
number = int(number) if number is not None else None
cube_number_x = 0
......
......@@ -30,7 +30,7 @@ def hg_command(dir, command):
subprocess.check_call(f"cd {dir} && {command}", shell=True)
def auto_mr(merge_when_pipeline_succeeds, clients_projects, core_projects):
def auto_mr(merge_when_pipeline_succeeds, target):
def doesnt_already_have_a_mr_from_another_command(cube):
# if we already have a MR from at least one command, returns
if branch_names.intersection({x.name for x in cube.branches.list()}):
......@@ -59,24 +59,10 @@ def auto_mr(merge_when_pipeline_succeeds, clients_projects, core_projects):
)
continue
if clients_projects and "clients" not in command.__self__.__class__.TARGETS:
if target not in command.__self__.__class__.TARGETS:
logger.info(
f"skip command {command.__self__.__class__.__name__} because it is not meant to "
"work on client projects"
)
continue
if not clients_projects and "cubes" not in command.__self__.__class__.TARGETS:
logger.info(
f"skip command {command.__self__.__class__.__name__} because it is not meant to "
"work on cubes"
)
continue
if core_projects and "core" not in command.__self__.__class__.TARGETS:
logger.info(
f"skip command {command.__self__.__class__.__name__} because it is not meant to "
"work on core projects"
"work on {target} projects"
)
continue
......@@ -87,8 +73,7 @@ def auto_mr(merge_when_pipeline_succeeds, clients_projects, core_projects):
interactif=False,
merge_when_pipeline_succeeds=merge_when_pipeline_succeeds,
additional_checks=[doesnt_already_have_a_mr_from_another_command],
clients_projects=clients_projects,
core_projects=core_projects,
target=target,
)
except EmptyCubeQueryResult:
# it's actually good that we don't have any result
......@@ -127,19 +112,16 @@ def main():
parser.add_argument("-q", "--query", default="")
parser.add_argument("-p", "--project", default=None)
parser.add_argument(
"-c", "--clients", action="store_true", default=False
) # works on clients projects
parser.add_argument(
"-k", "--core", action="store_true", default=False
) # works on core projects
"-t", "--target", choices=["clients", "cubes", "core"], default="cubes"
)
# advanced usage
parser.add_argument("-b", "--branch-name", type=str, default=None)
parser.add_argument("-C", "--commit-message", type=str, default=None)
parser.add_argument("-c", "--commit-message", type=str, default=None)
parser.add_argument("-s", "--script", type=str, default=None)
parser.add_argument(
"-K", "--command", type=str, default=None, dest="script_command"
"-k", "--command", type=str, default=None, dest="script_command"
)
args = parser.parse_args()
......@@ -147,8 +129,7 @@ def main():
if args.command == "auto-mr":
auto_mr(
merge_when_pipeline_succeeds=args.merge_when_pipeline_succeeds,
clients_projects=args.clients,
core_projects=args.core,
target=args.target,
)
else:
commands[args.command](
......@@ -158,8 +139,7 @@ def main():
number=args.number,
query=args.query,
project=args.project,
clients_projects=args.clients,
core_projects=args.core,
target=args.target,
branch_name=args.branch_name,
commit_message=args.commit_message,
other_args=args,
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment