-
Notifications
You must be signed in to change notification settings - Fork 11
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
Improve CLI handling of configuration file arguments #131
Improve CLI handling of configuration file arguments #131
Conversation
This updates the stylist CLI to make the -configuration compulsory. This will cause the command to fail early if the configuration is incorrect, allowing ArgumentParser to display a meaningful error message.
This updates the CLI to check whether the configuration file exists and whether it has a valid python extension. This allows ArgumentParser to display a meaningful error if the configuration is not valid.
As per the guidance, I have added my name to the list of contributors.
I have created issue #132 to capture potential future requirements. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not a big fan of making optional (starting with a hyphen) arguments compulsory but given that #132 exists and we therefore might make it optional again I think it is acceptable.
I have one request which is that you look into using PyTest's magic fixtures as they may tidy up the test code a little.
Create an overload method which shallow merges the pipes and styles attributes of a second Configuration into the current instance. This is intended to be used to allow per-site, per-user, and per-project configurations to be combined into a single entity.
Reviewer has suggested changing the argument handling to prevent the user from having to specify an option because this is contrary to spirit of making the flag voluntary. Instead, the code checks a variety of locations before raising an exception if the configuration cannot be found. This also improves temporary directory handling in tests as recommended by the reviewer, replacing clunky custom code with a function provide pytest.
The __configure() function return value in the main script had the wrong type hinting. This changes the hinting to match None in the event of a configuration problem.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this change is ready for trunk.
A combination of issues #129 and #130, this makes the
-configuration
command line argument compulsory, checks that that file passed as an argument exists, and confirms that the suffix matches a valid python file. This allows the CLI's ArgumentParser to return an error to the user fairly early on, rather than allowing a StylistException to propagate to the top level as happened previously.