Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

don't allow passing of values that are look very similar to an existing option (WIP) #1423

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions easybuild/tools/options.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,13 @@ class EasyBuildOptions(GeneralOption):
ALLOPTSMANDATORY = False # allow more than one argument
CONFIGFILES_RAISE_MISSING = True # don't allow non-existing config files to be specified

# don't allow passing of values that are look very similar to an existing option (due to a typo)
# require to use --longopt=value instead to remove ambiguity and unexpected behaviour due to small typos
ALLOW_OPTION_NAME_AS_VALUE = False # exact match for option name (without the '-') as value
ALLOW_OPTION_AS_VALUE = False # exact match for option as value
ALLOW_DASH_AS_VALUE = False # any value starting with a '-'
ALLOW_TYPO_AS_VALUE = False # value with similarity score from difflib.get_close_matches

def __init__(self, *args, **kwargs):
"""Constructor."""

Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,5 +107,5 @@ def find_rel_test():
provides=["eb"] + easybuild_packages,
test_suite="test.framework.suite",
zip_safe=False,
install_requires=["vsc-base >= 2.2.4"],
install_requires=["vsc-base >= 2.4.1"],
)
9 changes: 8 additions & 1 deletion test/framework/options.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
from easybuild.tools.filetools import mkdir, read_file, write_file
from easybuild.tools.github import fetch_github_token
from easybuild.tools.modules import modules_tool
from easybuild.tools.options import EasyBuildOptions
from easybuild.tools.options import EasyBuildOptions, parse_options
from easybuild.tools.toolchain.utilities import TC_CONST_PREFIX
from easybuild.tools.version import VERSION
from vsc.utils import fancylogger
Expand Down Expand Up @@ -1898,6 +1898,13 @@ def test_review_pr(self):
self.mock_stdout(False)
self.assertTrue(re.search(r"^Comparing zlib-1.2.8\S* with zlib-1.2.8", txt))

def test_allow_values_that_are_probably_meant_to_be_options(self):
"""Test detecting typos or ambiguities on the eb command line."""
common_args = []

eb_go = parse_options(args=common_args + ['-r', 'f'])
self.assertFalse('f' in eb_go.options.robot)


def suite():
""" returns all the testcases in this module """
Expand Down