package examples.dustin.commandline.jbock;

import static java.lang.System.out;

import net.jbock.CommandLineArguments;
import net.jbock.Description;
import net.jbock.LongName;
import net.jbock.ShortName;

import java.util.Optional;

/**
 * Demonstrates use of jbock to process command-line
 * arguments in a Java application.
 */
public class Main
{
   private boolean verbose;
   private String file;

   @CommandLineArguments
   public Main(
      @ShortName('v') @LongName("verbose") @Description("Verbosity enabled?")
      final boolean newVerbose,
      @ShortName('f') @LongName("file") @Description("File name and path")
      final Optional<String> newFileName)
   {
      verbose = newVerbose;
      file = newFileName.orElse("");
   }

   public String getFile()
   {
      return file;
   }

   public boolean isVerbose()
   {
      return verbose;
   }

   public static void main(final String[] arguments)
   {
      if (arguments.length < 1)
      {
         Main_Parser.printUsage(out, 3);
         System.exit(-1);
      }
      final Main_Parser.Binder binder = Main_Parser.parse(arguments);
      final Main main = binder.bind();
      out.println("The file '" + main.getFile() + "' was provided and verbosity is set to '" + main.isVerbose() + "'.");
   }
}

@@ -429,20 +429,45 @@
 %0A   
-public Main(
+abstract static class Arguments%0A   %7B%0A
 %0A   
@@ -547,21 +547,24 @@
 )%0A      
-final
+abstract
  boolean
@@ -568,19 +568,19 @@
 ean 
-newV
+v
 erbose
-,
+();%0A
 %0A   
@@ -657,21 +657,24 @@
 )%0A      
-final
+abstract
  Optiona
@@ -683,27 +683,64 @@
 String%3E 
-newFileName
+file();%0A   %7D%0A%0A   public Main(Arguments arguments
 )%0A   %7B%0A 
@@ -758,18 +758,27 @@
 e = 
-newV
+arguments.v
 erbose
+()
 ;%0A  
@@ -792,19 +792,24 @@
 e = 
-newFileName
+arguments.file()
 .orE
@@ -1051,24 +1051,34 @@
        Main_
+Arguments_
 Parser.print
@@ -1146,98 +1146,63 @@
 Main
-_Parser.Binder binder = Main_Parser.parse(arguments);%0A      final Main main = binder.bind(
+ main = new Main(Main_Arguments_Parser.parse(arguments)
 );%0A 

update to jbock 2.1