Fork me on GitHub

Example: Array as option argument

package example.case5;

import java.util.Arrays;

import org.hyphenType.wrapper.StandAloneAppWrapper;

public class MyProgram extends StandAloneAppWrapper {

    public void main(MyOptions opt) {
        System.out.println("x = " + opt.x());
        System.out.println("xStrings = " + Arrays.toString(opt.xStrings()));
        System.out.println("y = " + opt.y());
        System.out.println("yStrings = " + Arrays.toString(opt.yStrings()));
    }
}

package example.case5;

import org.hyphenType.datastructure.Options;
import org.hyphenType.datastructure.annotations.Option;
import org.hyphenType.datastructure.annotations.OptionArgument;

@SuppressWarnings("unchecked")
public interface MyOptions extends Options {

    @Option
    boolean x();

    @OptionArgument(option="x", index=0)
    String[] xStrings();
   
    @Option
    boolean y();
 
    @OptionArgument(option="y", index=0)
    String[] yStrings();
   
}
_> java example.case5.MyProgram --x a b c --y d e f
x = true
xStrings = [a, b, c]
y = true
yStrings = [d, e, f]
_> java example.case5.MyProgram --y d e f
x = false
xStrings = []
y = true
yStrings = [d, e, f]
_> java example.case5.MyProgram a b --y d e f
x = false
xStrings = []
y = true
yStrings = [d, e, f]
_> java example.case5.MyProgram a b --y d e f --x g h
x = true
xStrings = [g, h]
y = true
yStrings = [d, e, f]