Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support positional arguments #91

Open
rvesse opened this issue Apr 15, 2019 · 5 comments
Open

Support positional arguments #91

rvesse opened this issue Apr 15, 2019 · 5 comments
Assignees
Labels
enhancement Proposed Enhancement/Feature user-experience Improves user experience
Milestone

Comments

@rvesse
Copy link
Owner

rvesse commented Apr 15, 2019

Currently @Arguments is a general annotation that can only be applied to a single field and collects all non-option values into that field. There are various use cases where it might be nicer to support true positional arguments i.e. a new @PositionalArgument annotation such that arguments could be captured on separate fields and provide more detailed help specific to each argument

e.g.

@Command(name = "pos-args")
public class PositionalArgumentExample {

  @PositionalArgument(title = "Source", description = "The source file", position = { 0 })
  private String source;

  @PositionalArgument(title = "Target", description = "The target file", position = { 1 })
  private String target;

  @Arguments(title = "ExtraArg", description = "Extra arguments")
  private List<String> extraArgs = new ArrayList();
}

Which would be used as follows:

> pos-args source.txt target.txt foo bar

Where source.txt would be set to the source field, target.txt set to the target field and the additional arguments passed to the extraArgs field

@rvesse rvesse self-assigned this Apr 15, 2019
@rvesse rvesse added enhancement Proposed Enhancement/Feature user-experience Improves user experience labels Apr 15, 2019
@rvesse rvesse added this to the Future Feature Release milestone Apr 15, 2019
@rvesse
Copy link
Owner Author

rvesse commented Apr 15, 2019

Concrete tasks:

  • New @PositionalArgument annotation
  • New PositionalArgumentMetadata to hold the metadata for a positional argument
  • Extend CommandMetadata with positional arguments support
  • Extend AbstractCommandParser with positional arguments support
  • Help generations updated to generate help for new positional arguments ArgumentMetadata
    • CLI
    • HTML
    • Markdown
    • Man
    • Bash
  • ArgumentsRestriction extended to work with positional arguments as well
    • Implementations updated appropriately
    • Unit test coverage for the restrictions
  • Migration Guide updated for behavioural changes around positional arguments

rvesse added a commit that referenced this issue Apr 15, 2019
- Adds `@PositionalArgument` annotation
- Adds new `ArgumentMetadata` class
- MetadataLoader collects positional arguments
rvesse added a commit that referenced this issue Apr 15, 2019
- Capture positional arguments during parsing
- Add PositionalArgumentMetadata variant to ArgumentsRestriction methods
- Modify ParserUtils to also provide injection of positional arguments
- Clean up some deprecation warnings
rvesse added a commit that referenced this issue Apr 16, 2019
- Select correct target Java type to convert to based on the current
  positional argument being parsed
- Use correct title for both positional and non-positional arguments
rvesse added a commit that referenced this issue Apr 16, 2019
All built-in restrictions should now support positional arguments
rvesse added a commit that referenced this issue Apr 16, 2019
- CLI command help includes positional arguments in its output
- Additional tests for using @PositionalArgument without @arguments
  present and associated bug fix
rvesse added a commit that referenced this issue Apr 16, 2019
Starts working on CLI command group usage generator
rvesse added a commit that referenced this issue Apr 17, 2019
rvesse added a commit that referenced this issue Apr 17, 2019
@rvesse
Copy link
Owner Author

rvesse commented Apr 26, 2019

Moved out to 2.8

rvesse added a commit that referenced this issue Apr 29, 2019
- Adds `@PositionalArgument` annotation
- Adds new `ArgumentMetadata` class
- MetadataLoader collects positional arguments
rvesse added a commit that referenced this issue Apr 29, 2019
- Capture positional arguments during parsing
- Add PositionalArgumentMetadata variant to ArgumentsRestriction methods
- Modify ParserUtils to also provide injection of positional arguments
- Clean up some deprecation warnings
rvesse added a commit that referenced this issue Apr 29, 2019
- Select correct target Java type to convert to based on the current
  positional argument being parsed
- Use correct title for both positional and non-positional arguments
rvesse added a commit that referenced this issue Apr 29, 2019
All built-in restrictions should now support positional arguments
rvesse added a commit that referenced this issue Apr 29, 2019
- CLI command help includes positional arguments in its output
- Additional tests for using @PositionalArgument without @arguments
  present and associated bug fix
rvesse added a commit that referenced this issue Apr 29, 2019
Starts working on CLI command group usage generator
rvesse added a commit that referenced this issue Apr 29, 2019
rvesse added a commit that referenced this issue Apr 29, 2019
rvesse added a commit that referenced this issue Apr 29, 2019
@rvesse rvesse modified the milestones: 2.8.x, 3.x Release Apr 29, 2019
@rvesse
Copy link
Owner Author

rvesse commented Apr 29, 2019

Moved to 3.x branch

@gsmet
Copy link

gsmet commented Apr 10, 2022

Hey @rvesse ,

I'm working on integrating Airline into Quarkus GitHub App (it's a framework used to develop GitHub Apps) to parse commands included in GitHub comments (basically to have a comment-based commands bot).

This @PositionalArgument feature is THE missing feature I would need to make things completely smooth.

Anything I can do to help make it happen? AFAICS, you have made a lot of progress on this already.

And btw, a good opportunity to thank you for your work on this: it was exactly what I was looking for and it's flexible enough to meet my requirement even if it's not the typical use case of this library.

@rvesse
Copy link
Owner Author

rvesse commented Apr 11, 2022

Hey @gsmet,

So the core implementation was done a long time ago as the commits show, this was being done in aid of $dayjob usage of this library but priorities changed and we never ended up adopting this feature so it didn't get finished up. I would really like to finish it and get a 3.x release out at some point.

The main areas of this feature that need finishing are:

  • Converting all the help generators to include support for documenting positional arguments (Bash auto-complete being particularly thorny looking at my commit history). This is partially done.
  • Making sure the unit test coverage verified that the built-in restrictions continue to work with.

There are Alpha builds available via https://central.sonatype.org/publish/publish-guide/#accessing-repositories if you want to experiment with it in your project. Note Airline counts as a legacy project so you'll need to use the older oss.sonatype.org URLs. Most recent Alpha version is 3.0.0-alpha-2-SNAPSHOT

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement Proposed Enhancement/Feature user-experience Improves user experience
Projects
None yet
Development

No branches or pull requests

2 participants