diff --git a/tasks/emacs.py b/tasks/emacs.py index 3c91d4ab1d9cf..96f9ba984cafc 100644 --- a/tasks/emacs.py +++ b/tasks/emacs.py @@ -6,14 +6,24 @@ from invoke import task -from tasks.build_tags import build_tags, filter_incompatible_tags, get_build_tags, get_default_build_tags +from tasks.build_tags import ( + build_tags, + filter_incompatible_tags, + get_build_tags, + get_default_build_tags, +) from tasks.flavor import AgentFlavor -@task +@task( + help={ + "targets": f"Comma separated list of targets to include. Possible values: all, {', '.join(build_tags[AgentFlavor.base].keys())}. Default: all", + "flavor": f"Agent flavor to use. Possible values: {', '.join(AgentFlavor.__members__.keys())}. Default: {AgentFlavor.base.name}", + } +) def set_buildtags( _, - target="agent", + targets="all", build_include=None, build_exclude=None, flavor=AgentFlavor.base.name, @@ -23,21 +33,24 @@ def set_buildtags( """ flavor = AgentFlavor[flavor] - if target not in build_tags[flavor]: - print("Must choose a valid target. Valid targets are: \n") - print(f'{", ".join(build_tags[flavor].keys())} \n') - return + if targets == "all": + targets = build_tags[flavor].keys() + else: + targets = targets.split(",") + if not set(targets).issubset(build_tags[flavor]): + print("Must choose valid targets. Valid targets are:") + print(f'{", ".join(build_tags[flavor].keys())}') + return + + if build_include is None: + build_include = [] + for target in targets: + build_include.extend(get_default_build_tags(build=target, flavor=flavor)) + else: + build_include = filter_incompatible_tags(build_include.split(",")) - build_include = ( - get_default_build_tags(build=target, flavor=flavor) - if build_include is None - else filter_incompatible_tags(build_include.split(",")) - ) build_exclude = [] if build_exclude is None else build_exclude.split(",") use_tags = get_build_tags(build_include, build_exclude) with open(".dir-locals.el", "w") as f: - f.write(f'((go-mode . ((lsp-go-build-flags . ["-tags", "{",".join(use_tags)}"])\n') - f.write( - ' (eval . (lsp-register-custom-settings \'(("gopls.allowImplicitNetworkAccess" t t)))))))\n' - ) + f.write(f'((go-mode . ((lsp-go-build-flags . ["-tags" "{",".join(sorted(use_tags))}"]))))\n') diff --git a/tasks/vim.py b/tasks/vim.py index 663063b700735..7b571f0f9168d 100644 --- a/tasks/vim.py +++ b/tasks/vim.py @@ -15,10 +15,15 @@ from tasks.flavor import AgentFlavor -@task +@task( + help={ + "targets": f"Comma separated list of targets to include. Possible values: all, {', '.join(build_tags[AgentFlavor.base].keys())}. Default: all", + "flavor": f"Agent flavor to use. Possible values: {', '.join(AgentFlavor.__members__.keys())}. Default: {AgentFlavor.base.name}", + } +) def set_buildtags( _, - target="agent", + targets="all", build_include=None, build_exclude=None, flavor=AgentFlavor.base.name, @@ -28,18 +33,24 @@ def set_buildtags( """ flavor = AgentFlavor[flavor] - if target not in build_tags[flavor]: - print("Must choose a valid target. Valid targets are: \n") - print(f'{", ".join(build_tags[flavor].keys())} \n') - return + if targets == "all": + targets = build_tags[flavor].keys() + else: + targets = targets.split(",") + if not set(targets).issubset(build_tags[flavor]): + print("Must choose valid targets. Valid targets are:") + print(f'{", ".join(build_tags[flavor].keys())}') + return + + if build_include is None: + build_include = [] + for target in targets: + build_include.extend(get_default_build_tags(build=target, flavor=flavor)) + else: + build_include = filter_incompatible_tags(build_include.split(",")) - build_include = ( - get_default_build_tags(build=target, flavor=flavor) - if build_include is None - else filter_incompatible_tags(build_include.split(",")) - ) build_exclude = [] if build_exclude is None else build_exclude.split(",") use_tags = get_build_tags(build_include, build_exclude) with open(".vimrc", "w") as f: - f.write(f"let g:ale_go_gopls_init_options = {{'buildFlags': ['-tags', '{','.join(use_tags)}']}}\n") + f.write(f"let g:ale_go_gopls_init_options = {{'buildFlags': ['-tags', '{','.join(sorted(use_tags))}']}}\n") diff --git a/tasks/vscode.py b/tasks/vscode.py index 9288e9a0293e7..c4b545b47c33c 100644 --- a/tasks/vscode.py +++ b/tasks/vscode.py @@ -15,7 +15,12 @@ from invoke import Context, task from invoke.exceptions import Exit -from tasks.build_tags import build_tags, filter_incompatible_tags, get_build_tags, get_default_build_tags +from tasks.build_tags import ( + build_tags, + filter_incompatible_tags, + get_build_tags, + get_default_build_tags, +) from tasks.flavor import AgentFlavor from tasks.libs.common.color import Color, color_message from tasks.libs.json import JSONWithCommentsDecoder @@ -25,10 +30,15 @@ VSCODE_EXTENSIONS_FILE = "extensions.json" -@task +@task( + help={ + "targets": f"Comma separated list of targets to include. Possible values: all, {', '.join(build_tags[AgentFlavor.base].keys())}. Default: all", + "flavor": f"Agent flavor to use. Possible values: {', '.join(AgentFlavor.__members__.keys())}. Default: {AgentFlavor.base.name}", + } +) def set_buildtags( _, - target="agent", + targets="all", build_include=None, build_exclude=None, flavor=AgentFlavor.base.name, @@ -38,16 +48,22 @@ def set_buildtags( """ flavor = AgentFlavor[flavor] - if target not in build_tags[flavor]: - print("Must choose a valid target. Valid targets are: \n") - print(f'{", ".join(build_tags[flavor].keys())} \n') - return + if targets == "all": + targets = build_tags[flavor].keys() + else: + targets = targets.split(",") + if not set(targets).issubset(build_tags[flavor]): + print("Must choose valid targets. Valid targets are:") + print(f'{", ".join(build_tags[flavor].keys())}') + return + + if build_include is None: + build_include = [] + for target in targets: + build_include.extend(get_default_build_tags(build=target, flavor=flavor)) + else: + build_include = filter_incompatible_tags(build_include.split(",")) - build_include = ( - get_default_build_tags(build=target, flavor=flavor) - if build_include is None - else filter_incompatible_tags(build_include.split(",")) - ) build_exclude = [] if build_exclude is None else build_exclude.split(",") use_tags = get_build_tags(build_include, build_exclude) @@ -60,7 +76,7 @@ def set_buildtags( with open(fullpath) as sf: settings = json.load(sf, object_pairs_hook=OrderedDict) - settings["go.buildTags"] = ",".join(use_tags) + settings["go.buildTags"] = ",".join(sorted(use_tags)) with open(fullpath, "w") as sf: json.dump(settings, sf, indent=4, sort_keys=False, separators=(',', ': '))