azure-cli icon indicating copy to clipboard operation
azure-cli copied to clipboard

Args parsing unexpected behavior and prints incorrect error messages

Open djyou opened this issue 8 years ago • 3 comments

Describe the bug When providing an arg in the format -abcdef (i.e., single dash with multiple letters), the CLI parses it into

-a bcdef

and thus prints incorrect error messages.

To Reproduce

The command az group -name foo is parsed into az group -n ame foo and thus prints the error:

az group: 'foo' is not an az group command. See 'az group --help'.

If I have a resource group called foo, running az group show -nfoo is equavalent to running az group show -n foo.

Expected behavior Running az group show -nfoo should error out because -nfoo is not a valid.

Environment summary azure-cli (2.0.38)

acr (2.0.28) acs (2.1.1) advisor (0.5.1) ams (0.1.1) appservice (0.1.35) backup (1.1.1) batch (3.2.4) batchai (0.3.0) billing (0.1.8) cdn (0.0.14) cloud (2.0.14) cognitiveservices (0.1.13) configure (2.0.16) consumption (0.3.1) container (0.1.24) core (2.0.38) cosmosdb (0.1.21) dev-tools (0.1.1) dla (0.1.0) dls (0.0.22) dms (0.0.1) eventgrid (0.1.12) eventhubs (0.1.3) extension (0.0.15) feedback (2.1.2) find (0.2.10) interactive (0.3.23) iot (0.1.21) keyvault (2.0.22) lab (0.0.22) maps (0.2.0) monitor (0.1.7) network (2.1.4) nspkg (3.0.2) policyinsights (0.1.0) profile (2.0.26) rdbms (0.2.4) redis (0.2.13) reservations (0.2.0) resource (2.0.31) role (2.0.26) servicebus (0.1.2) servicefabric (0.0.12) sql (2.0.27) storage (2.0.35) testsdk (0.1.3) vm (2.0.34)

Additional context Add any other context about the problem here.

djyou avatar Jun 20 '18 18:06 djyou

This is standard argparse behavior and is expected. It is also part of the reason that multi-character short options are not allowed in the CLI.

tjprescott avatar Jun 20 '18 18:06 tjprescott

It however seems to me that multi-character short options are allowed because of this behavior. If they are truly not allowed, shouldn't they always error out?

It really puzzled me when az group show -nfoo gives me back the resource group foo.

djyou avatar Jun 20 '18 18:06 djyou

For whatever strange reason, argparse allows them, but for all the weird ambiguity that can result, we do not allow them in the CLI. There is a linter rule that will prevent them from being checked in. I routinely make use of the short-option "feature" when I'm using output formats (i.e.: az group list -otable)

tjprescott avatar Jun 20 '18 19:06 tjprescott