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

@Version usage on top-level Cli? #57

Closed
stephenh opened this issue Sep 25, 2016 · 7 comments
Closed

@Version usage on top-level Cli? #57

stephenh opened this issue Sep 25, 2016 · 7 comments
Assignees
Labels
annotations Java Annotations enhancement Proposed Enhancement/Feature help Help System user-experience Improves user experience
Milestone

Comments

@stephenh
Copy link

Hi,

I'd like to use the @Version annotation, but it seems to assume it's on a command object?

E.g. I have a Cli setup like:

@Cli(
  name = "mirror",
  description = "two-way, real-time sync of files across machines",
  commands = { MirrorClientCommand.class, MirrorServerCommand.class },
  defaultCommand = Help.class)
@Version(sources = { "/META-INF/MANIFEST.MF" }, suppressOnError = false)
public class Mirror {

  public static void main(String[] args) throws Exception {
    com.github.rvesse.airline.Cli<Runnable> cli = new com.github.rvesse.airline.Cli<>(Mirror.class);
    cli.parse(args).run();
  }

I am admittedly source a MF sources (see my other ticket), but I was expecting this to blow up, and then I'd poke around at gradle to make a properties file instead.

But instead it looks like the @Version annotation here isn't getting found at all.

I was thinking maybe I should make a subclass of the airline Help.class, and add my @Version there? ...well, no, that didn't work.

Basically what I'd like is for when users run:

  • mirror with no args, or
  • mirror -v

That they see the version information.

Right now the output is just:

usage: mirror <command> [ <args> ]

Commands are:
    client   two-way real-time sync
    server   starts a server for the remote client to connect to

See 'mirror help <command>' for more information on a specific command.

Is what I'm looking for already doable? Or something that's easy to support?

@rvesse rvesse added the enhancement Proposed Enhancement/Feature label Sep 26, 2016
@rvesse rvesse added this to the 2.3.0 milestone Sep 26, 2016
@rvesse rvesse added the help Help System label Sep 26, 2016
@rvesse
Copy link
Owner

rvesse commented Sep 26, 2016

What you are trying to do won't just work at the moment though it is definitely something I would like to do in the future. Annotations like @Version currently only work when applied directly to @Command classes though they may be applied to any class in the inheritance hierarchy.

Ideally we should also allow them on @Cli annotated classes with any instances in the @Command hierarchy able to override these.

All @Version does currently is add an extra section into the command specific help hence why you don't see any difference in output even when you extend Help and add the annotation. The behaviour of the Help command when the user does not specify command is to give the CLI help which does not include any extra annotation driven sections like @Version provides.

The best way to do this currently would be to create a Version command in a similar vein to Help which could then inspect the @Version annotation and generate appropriate output. As for a -v option you would need to add that as an option yourself. You could choose to do something similar to HelpOption for this.

I will probably aim to have something built in in the future but I can't give you a time frame on that.

@stephenh
Copy link
Author

Hi Rob,

Thanks for the response. That makes sense...

HelpOption looks interesting, although I think it has the same wrinkle like @Version, where it'd have to be on each command.

I think a VersionCommand is probably what I'll go with, and maybe even have the command name be "-v", and have it hidden, so that mirror -v works, but then it doesn't show up in the list of regular commands. Or maybe I'll just call it version, to be more consistent with the other commands.

Having these on the top-level @Cli in the long run makes sense...it does seem kind of tricky, in that invocations like mirror -v and mirror -h would be kind of one-off/top-level commands that are parsed/handled separately/short-circuit the regular mirror command <args> approach.

@rvesse
Copy link
Owner

rvesse commented Sep 27, 2016

Agreed, this probably also relates to #53 which covers special handling for options like -h which currently require users to jump through some extra hoops

@rvesse
Copy link
Owner

rvesse commented Sep 27, 2016

HelpOption looks interesting, although I think it has the same wrinkle like @Version, where it'd have to be on each command.

Yes although any and all option definitions within a class hierarchy will be discovered. So personally I usually define a abstract class with all my common options and there have all my other commands extend from that.

@rvesse rvesse added the annotations Java Annotations label Sep 27, 2016
@rvesse rvesse modified the milestones: 2.4.0, 2.3.0 Feb 20, 2017
@rvesse rvesse modified the milestones: 2.4.0, 2.5.0 Jul 27, 2017
@rvesse rvesse added the user-experience Improves user experience label Jul 4, 2018
rvesse added a commit that referenced this issue Jul 11, 2018
@rvesse
Copy link
Owner

rvesse commented Jul 11, 2018

Using help section annotations on @Cli classes are now supported in the latest SNAPSHOT builds (2.5.1-SNAPSHOT)

Still need to incorporate use of help sections in CLI help

@rvesse rvesse self-assigned this Jul 11, 2018
rvesse added a commit that referenced this issue Jul 12, 2018
Help sections defined at the @cli level are now incorporated into the
output of GlobalUsageGenerator implementations (CLI, Man, Markdown)

Includes unit tests for this
@rvesse
Copy link
Owner

rvesse commented Jul 12, 2018

Help sections added at the @Cli level are now incorporated in the global help output in the latest snapshots

rvesse added a commit that referenced this issue Jul 13, 2018
@rvesse
Copy link
Owner

rvesse commented Jul 13, 2018

Here's example output with latest SNAPSHOT:

usage: test <command> [ <args> ]

Commands are:
    Args1   args1 description

See 'test help <command>' for more information on a specific command.

VERSION
            Component: Airline Test
            Version: 1.2.3
            Build: 12345abcde

@rvesse rvesse closed this as completed in 7b68284 Jul 13, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
annotations Java Annotations enhancement Proposed Enhancement/Feature help Help System user-experience Improves user experience
Projects
None yet
Development

No branches or pull requests

2 participants