fsprojects / Argu

A declarative CLI argument parser for F#
https://fsprojects.github.io/Argu
MIT License
453 stars 75 forks source link

Support union names without underscores #161

Closed LiteracyFanatic closed 3 years ago

LiteracyFanatic commented 3 years ago

Description

Union names in F# are typically written in pascal case rather than snake case. Right now I have to add underscores to my union names if I want dashes to appear between words in the generated command line options. This isn't a huge deal by any means, but it does make the linter in my editor angry.

A regex like this is all that would be needed

Regex.Replace(name, @"(?<!^)(\p{Lu})", "-$1").ToLowerInvariant()

The only real issue I can think of is the question of how it would interact with the current underscore splitting behavior. I think it would make sense to let the existing behavior take precedence and only split on capital letters if the name contains no underscores.

If this sounds like a reasonable change to you, I'd be glad to open a pull request.

eiriktsarpalis commented 3 years ago

Related to https://github.com/fsprojects/Argu/pull/158#issuecomment-731216799. I think fundamentally this is a breaking change so I wouldn't support it. Is there a way disable the linter for the particular source file?

LiteracyFanatic commented 3 years ago

I completely agree regarding #158; the generated options should follow standard conventions. I would just like it if these two snippets both parsed to --no-open.

type ReadArgs =
    | Title of string
    | Last
    | Port of int
    | No_Open // --no-open
type ReadArgs =
    | Title of string
    | Last
    | Port of int
    | NoOpen // --noopen

It is technically a breaking change though and as you mentioned I can disable the lint rule, so I understand your preference to leave things as is.