-
Notifications
You must be signed in to change notification settings - Fork 2.5k
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
Make SRC or code mandatory and mutually exclusive (#2360) #2804
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,11 +4,11 @@ Foundational knowledge on using and configuring Black. | |
|
||
_Black_ is a well-behaved Unix-style command-line tool: | ||
|
||
- it does nothing if no sources are passed to it; | ||
- it does nothing if it finds no sources to format; | ||
- it will read from standard input and write to standard output if `-` is used as the | ||
filename; | ||
- it only outputs messages to users on standard error; | ||
- exits with code 0 unless an internal error occurred (or `--check` was used). | ||
- exits with code 0 unless an internal error occurred or a CLI option prompted it. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We already had |
||
|
||
## Usage | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -431,6 +431,17 @@ def main( | |
) -> None: | ||
"""The uncompromising code formatter.""" | ||
ctx.ensure_object(dict) | ||
|
||
if src and code is not None: | ||
out( | ||
main.get_usage(ctx) | ||
+ "\n\n'SRC' and 'code' cannot be passed simultaneously." | ||
) | ||
ctx.exit(1) | ||
if not src and code is None: | ||
out(main.get_usage(ctx) + "\n\nOne of 'SRC' or 'code' is required.") | ||
ctx.exit(1) | ||
|
||
root, method = find_project_root(src) if code is None else (None, None) | ||
ctx.obj["root"] = root | ||
|
||
|
@@ -569,7 +580,6 @@ def get_sources( | |
) -> Set[Path]: | ||
"""Compute the set of files to be formatted.""" | ||
sources: Set[Path] = set() | ||
path_empty(src, "No Path provided. Nothing to do 😴", quiet, verbose, ctx) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Shouldn't happen anymore because the check is done above. |
||
|
||
if exclude is None: | ||
exclude = re_compile_maybe_verbose(DEFAULT_EXCLUDES) | ||
|
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.
New with this PR. With previous discussions about passing no sources I think it should be considered user error. Finding no files to format still passes and returns success.