Skip to content
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

Default --version option is not working for subcommands #1567

Open
ericsuhong opened this issue Jun 13, 2024 · 2 comments
Open

Default --version option is not working for subcommands #1567

ericsuhong opened this issue Jun 13, 2024 · 2 comments
Labels
bug Something isn't working needs triage ⭐ top bug Top bug.

Comments

@ericsuhong
Copy link

Information

  • OS: Windows
  • Version: 0.47.0
  • Terminal: Windows Terminal

Describe the bug
--version option is working for the root command as expected.

However, when I run --version option for any subcommands, it does not print version and --version option is ignored.

mycommand --version
1.0.0

mycommand subcommand --version
... runs the subcommand without printing out the version

This is confusing because --help option displays --version as a valid option for all subcommands by default.

mycommand subcommand --help

USAGE:
    mycommand subcommand [OPTIONS]

OPTIONS:
                     DEFAULT
    -h, --help                           Prints help information
    -v, --version                        Prints version information
    -o, --output     test                   My custom option

To Reproduce
Run any spectre subcommands with --version.

Expected behavior
--version MUST NOT be displayed by default as part of --help output for subcommands that do not have explicitly defined --version option.


Please upvote 👍 this issue if you are interested in it.

@ericsuhong ericsuhong added bug Something isn't working needs triage labels Jun 13, 2024
@github-actions github-actions bot added the ⭐ top bug Top bug. label Jun 14, 2024
@ericsuhong
Copy link
Author

ericsuhong commented Jun 14, 2024

The issue does not occur when I enable StrictParsing, but I believe this behavior should still be fixed for normal, default case.

@MangelMaxime
Copy link

MangelMaxime commented Jun 18, 2024

I feel like I have a similar issue when using a "default command".

Main file

module CommitLinter.Main

open Spectre.Console.Cli
open CommitLinter.Commands

[<EntryPoint>]
let main args =

    let app = CommandApp<GenerateCommand>()

    app
        .WithDescription("Generate changelog based on the Git history.")
        .Configure(fun config ->
            config.Settings.ApplicationName <- "changelog-gen" // Find a name
        )

    app.Run(args)

Command file

namespace CommitLinter.Commands

open Spectre.Console
open Spectre.Console.Cli
open System.ComponentModel
open System.IO

type GenerateSettings() =
    inherit CommandSettings()

    [<CommandOption("-c|--config")>]
    [<Description("Path to the configuration file")>]
    member val Config: string option = None with get, set

type GenerateCommand() =
    inherit Command<GenerateSettings>()
    interface ICommandLimiter<GenerateSettings>

    override __.Execute(context, settings) =
        printfn "Generate command"
        0

Then if I run dotnet run --project myProject.fsproj -- --version it will prints Generate command when I expect it to print the version number of the tool.

Use strict parsing doesn't help, it only report an issue because --version is unknown probably because it is using the options config from the Generate command only ?

Or perhaps my issue was related to #1216?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working needs triage ⭐ top bug Top bug.
Projects
Status: Todo 🕑
Development

No branches or pull requests

2 participants