Skip to content

Make SRC/CODE mandatory and mutually exclusive #2360

Closed
@felix-hilden

Description

Is your feature request related to a problem? Please describe.
From #2356, which made (assuming it got merged) SRC appear as a mandatory CLI parameter: Strictly speaking, SRC is optional both in the way that Black accepts no arguments (and then prints "nothing to do") and with --code "". I think accepting SRC and then skipping it when -c is passed is a bit confusing.

Describe the solution you'd like
I'll propose we make SRC and --code mutually exclusive and require one of them.

So, something like this:

> black
BLACK IS MAD: specify one of SRC / --code

> black --code "" .
BLACK IS FURIOUS: are you trying to confuse me?

I wonder if Click has some way of documenting call modes. Maybe something like:

> black --help

black [opts] src
black [opts] --code CODE

Options:
...

The "nothing to do" message could be emitted when the supplied path doesn't contain any valid files, like it is currently.

Ideally though, we would have a flag to turn the source to code I think. If I'm thinking about it from a documentation perspective, it would be much easier to explain:

> black --help

black [opts] src

SRC     Sources to be formatted as directories or files.
        If --code was passed, treat SRC as Python text.

Options:
code    Treat SRC as Python text.

I don't know what multiple sources of Python text would do then. Maybe different lines, or we could require only one source in that case. Anyways, this is kind of an addon to my proposition, not the main thing.

Additional context
Also, relevant discussion in #861: SRC is currently undocumented on the CLI help. We should definitely document it while we're at it (if it doesn't get documented earlier).

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions