influxdata / influxdata/influx-cli

flag values that start with a hyphen are interpreted as short options and cause option parse errors.

Open
#269 0 comments 0 reactions 0 assignees View on GitHub
bug
Dominant language
Go
Stars
75
Forks
22
PR merge metrics
No merged PRs in 30d

Description

It's not possible to use long option arguments starting with `-`, when the long option is in the form `--opt arg`. The command line parsing library attempts to interpret the argument as a short option. For example:

```
+ ./bin/linux/influx query --host http://thurston05:8086/ --org monitor --token -3PpF_ISBadt4tS7e0BaKte1zDxryDwwb86cTQnUPmwau2UWe18rhCmMAHyJB-OZRZpfMp-3eYfEXQV_Au6I2A== 'from( bucket: "apps" ) |> range( start: 2021-09-14T19:03:20.021849485Z )'
Incorrect Usage: flag provided but not defined: -3PpF_ISBadt4tS7e0BaKte1zDxryDwwb86cTQnUPmwau2UWe18rhCmMAHyJB-OZRZpfMp-3eYfEXQV_Au6I2A
```

Removing the `-` from the token and adding it to the org causes a different error, likely the same root cause:

```
+ ./bin/linux/influx query --host http://thurston05:8086/ --org -monitor --token 3PpF_ISBadt4tS7e0BaKte1zDxryDwwb86cTQnUPmwau2UWe18rhCmMAHyJB-OZRZpfMp-3eYfEXQV_Au6I2A== 'from( bucket: "apps" ) |> range( start: 2021-09-14T19:03:20.021849485Z )'
Error: at most 1 query string can be specified as an argument, got 3
```

And finally, no leading `-` in any long option argument, option parsing succeeds:

```
+ ./bin/linux/influx query --host http://thurston05:8086/ --org monitor --token 3PpF_ISBadt4tS7e0BaKte1zDxryDwwb86cTQnUPmwau2UWe18rhCmMAHyJB-OZRZpfMp-3eYfEXQV_Au6I2A== 'from( bucket: "apps" ) |> range( start: 2021-09-14T19:03:20.021849485Z )'
Error: failed to execute query: 401 Unauthorized: unauthorized access
```

@danxmoran found this PR that attempted to fix it, but it was closed as stale due to edge cases.

https://github.com/urfave/cli/pull/1135

As a workaround, the option can be specified as `--opt=arg`.

Contributor guide

No contributing guide indexed for this repository

Research direction

Start with the command-line parsing used by ./bin/linux/influx and review urfave/cli PR 1135 for the attempted fix and its edge cases. Reproduce the query command with a long option argument beginning with `-`, compare it with the documented `--opt=arg` workaround, and verify that the space-separated form works without breaking existing option parsing.

Written by the indexing model from the issue text.

Assessment

Tech stack
go
Domain
cli
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.