package picocli.examples.parseresult;

import picocli.CommandLine;
import picocli.CommandLine.Command;
import picocli.CommandLine.Model.CommandSpec;
import picocli.CommandLine.Option;
import picocli.CommandLine.Parameters;
import picocli.CommandLine.ParseResult;
import picocli.CommandLine.Spec;

import java.util.List;

@Command(name = "myapp", mixinStandardHelpOptions = true, version = "myapp 0.1")
public class ParseResultDemo implements Runnable {
    @Spec CommandSpec spec;

    @Option(names = "-x")
    int x = 10;

    @Option(names = "-y", defaultValue = "20")
    int y;

    @Parameters
    List<String> positionalParams;

    @Override
    public void run() {
        ParseResult pr = spec.commandLine().getParseResult();

        System.out.println(pr.expandedArgs());
        System.out.println(pr.originalArgs());

        String[] options = {"x", "y"};
        for (String name : options) {
            System.out.printf("%s was specified: %s%n", name, pr.hasMatchedOption(name));
            System.out.printf("%s=%s (-1 means this option was not matched on command line)%n", name, pr.matchedOptionValue(name, -1));
            System.out.printf("%s=%s (arg value or default)%n", name, spec.findOption(name).getValue());
            System.out.println();
        }

        System.out.printf("-x=%s (field value)%n", x);
        System.out.printf("-y=%s (field value)%n", y);
    }

    public static void main(String[] args) {
        new CommandLine(new ParseResultDemo()).execute(args);
    }
}

@@ -142,16 +142,61 @@
 ndSpec;%0A
+import picocli.CommandLine.Model.OptionSpec;%0A
 import p
@@ -882,37 +882,49 @@
     
-String%5B%5D options = %7B%22x%22, %22y%22%7D
+List%3COptionSpec%3E options = spec.options()
 ;%0A  
@@ -938,19 +938,22 @@
 or (
-String name
+OptionSpec opt
  : o
@@ -1013,29 +1013,62 @@
 fied: %25s%25n%22,
- n
+%0A                    opt.longestN
 ame
+()
 , pr.hasMatc
@@ -1077,20 +1077,19 @@
 dOption(
-name
+opt
 ));%0A    
@@ -1179,21 +1179,55 @@
 ine)%25n%22,
- n
+%0A                    opt.shortestN
 ame
+()
 , pr.mat
@@ -1242,20 +1242,33 @@
 onValue(
-n
+opt.longestN
 ame
+()
 , -1));%0A
@@ -1334,36 +1334,51 @@
 %25n%22,
- name, spec.findOption(name)
+%0A                    opt.longestName(), opt
 .get

Print values for all options