Skip to content

[Nice to have][FSharp] Option name overlaps with FSharp Core Type Option #2676

@shayanhabibi

Description

@shayanhabibi

Greetings, love how everything is coming along.

Issue

The type Option is used as a core type in Microsoft.FSharp.Core.

We are able to delineate the two quite simply despite this, as the alias option is more commonly used. The issue relates more to tooling suggestions and inlay hints at types, which can be confusing when using both option and System.CommandLine.Option.

Note

I will refer to FSharps Option henceforth exclusively as option, and CommandLines Option as Option.


One method of resolving the above would be to have Option in a module/namespace not automatically opened or connected to the System.CommandLine. This way it can be aliased safely for FSharp consumers.

This seems like a pretty subpar method of resolution.


Another method of resolution is of course to rename Option to something like CommandOption. But I believe there have been efforts already to reduce the verbosity of the names with useless prefixes such as that already with Beta 5.

This would be an ideal method of resolution for FSharp consumers, but at the cost of the prefix inclusion for the majority of consumers (CSharp).


A simple method of resolution is a single namespace file which exposes the root namespace types and methods, with the alias for Option being modified to CommandOption.

This is currently how I consume the library to provide a better tooling experience.

namespace System.CommandLine.FSharp

open System.CommandLine

type Argument = System.CommandLine.Argument
type ArgumentArity = System.CommandLine.ArgumentArity
type ArgumentValidation = System.CommandLine.ArgumentValidation
type Argument<'T> = System.CommandLine.Argument<'T>
type Command = System.CommandLine.Command
type CompletionSourceExtensions = System.CommandLine.CompletionSourceExtensions
type DiagramDirective = System.CommandLine.DiagramDirective
type Directive = System.CommandLine.Directive
type EnvironmentVariablesDirective = System.CommandLine.EnvironmentVariablesDirective
type InvocationConfiguration = System.CommandLine.InvocationConfiguration
type CommandOption = System.CommandLine.Option
type CommandOptionValidation = System.CommandLine.OptionValidation
type CommandOption<'T> = System.CommandLine.Option<'T>
type ParserConfiguration = System.CommandLine.ParserConfiguration
type ParseResult = System.CommandLine.ParseResult
type RootCommand = System.CommandLine.RootCommand
type Symbol = System.CommandLine.Symbol
type VersionOption = System.CommandLine.VersionOption

There are consequences to using aliases for F#, as we cannot attach member methods to an alias. But it is satisfactory.

An advantage of this is that we can also contribute F# related utilities directly to this namespace without polluting the rest of the codebase.


Related #2643

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions