Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Distinguish between blank string flag and absence of flag #239

@Gerg

Description

@Gerg

Feature Request

It would be useful if there was a way to distinguish between passing a string flag a blank string (command -f "") and the absence of the flag (command).

Currently both will return "" from c.String("f")

Our use case:

We have a command to update a resource via an API. Fields that can be updated are represented by different CLI flags. One of the fields on the resource is a string that can be blank. We would like users to be able to set the field to the blank string.

#Setting the field to non-blank string
command -f "string"

#Setting the field to blank string
command -f ""

To do this currently we have to have another flag to reset the field.

command --clear-field

This is annoying because it means we have two flags for a single field and have to handle cases where both flags are passed.

Thanks!

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