rvesse / airline

Java annotation-based framework for parsing Git like command line structures with deep extensibility
https://rvesse.github.io/airline/
Apache License 2.0
131 stars 20 forks source link

Combining Alias Overriding and Chaining should not lead to errors #72

Closed rvesse closed 6 years ago

rvesse commented 6 years ago

As discovered while writing examples for the User Guide (#35) there is a possible behaviour that can occur when apparently logically consistent alias definitions are used for CLIs that enable both overriding of built-ins and chaining.

If a user overrides a built-in and also tries to define aliases in terms of the same command this results in a circular reference exception because Airline always tries to resolve further aliases so will treat the override always as an alias E.g.

logs=logs --format Json
json=logs --format Json
xml=logs --format Xml

Tries to make the default format Json and provide json and xml aliases for convenience. However this breaks because logs is always treated as an alias resulting in a circular reference.

To fix this we should change the behaviour so that an override can only occur if the alias to be resolved was not previously seen i.e. only the first instance of an alias can override a built-in, any subsequent references would simply invoke the built-in.

It may also be useful to provide explicit syntax for this e.g. !logs would always indicate that the built-in should be invoked ignoring any overrides.

rvesse commented 6 years ago

Decided that an explicit syntax was better than special casing overriding and chaining combination behaviour. The existing behaviour remains and a new explicit force built-in prefix is introduced defaulting to ! that allows definitions to be made that override a built-in will still leaving that built-in accessible. So the example definitions become:

logs=!logs --format Json
json=!logs --format Json
xml=logs --format Xml

Where ! is the default prefix that can be overridden as desired.