AlloyTools / org.alloytools.alloy

Alloy is a language for describing structures and a tool for exploring them. It has been used in a wide range of applications from finding holes in security mechanisms to designing telephone switching networks. This repository contains the code for the tool.
Other
712 stars 123 forks source link

Changes to share the command line #166

Closed pkriens closed 2 years ago

pkriens commented 2 years ago

There are numerous upcoming contestants for 'owning' the command line. Traditionally this is hard coded but this has the disadvantage that it creates a highly coupled network, which is hard to maintain.

This patch uses an annotation and some OSGi/bnd tooling to find all classes that want to add a command to the command line. The AlloyDispatcher gathers all those commands and then parses the command line. A library is used that uses an interface as specification for the options/flags and arguments. The library can then parse the command line, do error reporting, and provide extensive help.

Adding a new main looks like:

 @AlloyMain( name="new" )
 @AlloyMain( name="old" )
 public class OldAndNew {

     @Description("This is an old command")
     interface OldCommand extends Options {
             @Description("This is an old command")
              boolean backup();
     }            

     public void _old(OldCommand options) {
          if ( options.backup() ) 
             ....
     }
 }

Any class in the build will be picked up.

The AlloyDispatcher can set the user A4Preferences, default log level, and class specific loglevels. A few commands like version and prefs are provided to show how the mechanism work.

pkriens commented 2 years ago

@aleksandarmilicevic @eskang @grayswandyr are you ok if these commits that do not affect the language in any way, if I just commit them? We can always revert ... Just want to make a few more infra structure changes so Alloy will be easier to extend in the future.