Skip to content

Allow to configure the base for Integer parsing #1462

@ccremer

Description

@ccremer

Checklist

  • Are you running the latest v2 release? The list of releases is here.
  • Did you check the manual for your release? The v2 manual is here.
  • Did you perform a search about this feature? Here's the Github guide about searching.

What problem does this solve?

We pass a year and month as CLI flags/envs (each have their own flag/env var).
Unfortunately, when passing a month with preceding 0 like 08 for August it gets attempted to be parsed as octal, because of `strconv.ParseInt(..., 0, ...) (see

valInt, err := strconv.ParseInt(val, 0, 64)
) it's set to autodetect (https://pkg.go.dev/strconv#ParseInt).
In cases where the flag or env var is set by another tool with preceding 0, this can lead to unexpected issues like vshn/appuio-odoo-adapter#57.

If we could configure which base the parser should use, it would solve our issue.
See playground here: https://go.dev/play/p/a8VllHp_Z6D

Solution description

Add a property to all Int flags to let us explicitly configure the base for our parsing, e.g. Base or ParseBase (name tbd) that is then used in ParseInt.
Since Go's default value for Integers are 0, it would match what is currently used in ParseInt, thus I don't think it causes a breaking change.

Describe alternatives you've considered

  • Configure the month flag as StringFlag and do the parsing explicitly within the Before/Action functions.

Other workarounds are all outside of urface/cli:

  • Combine the year and month flag into a Timestamp flag with format ("yyyy-mm"), this would be a breaking change for the user.
  • Force any external tool (or human user) that provide the value for the month to omit leading zeroes when invoking the CLI. Depending on the tool used this might not always be possible.

Metadata

Metadata

Assignees

No one assigned

    Labels

    area/v2relates to / is being considered for v2status/triagemaintainers still need to look into this

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions