1   /*
2    * SPDX-FileCopyrightText: none
3    * SPDX-License-Identifier: CC0-1.0
4    */
5   
6   package gov.nist.secauto.metaschema.cli.processor.command;
7   
8   import gov.nist.secauto.metaschema.cli.processor.CLIProcessor.CallingContext;
9   import gov.nist.secauto.metaschema.cli.processor.ExitStatus;
10  
11  import org.apache.commons.cli.CommandLine;
12  
13  import edu.umd.cs.findbugs.annotations.NonNull;
14  
15  public interface ICommandExecutor {
16    @NonNull
17    ExitStatus execute();
18  
19    @NonNull
20    static ICommandExecutor using(
21        @NonNull CallingContext callingContext,
22        @NonNull CommandLine commandLine,
23        @NonNull ExecutionFunction function) {
24      return new ICommandExecutor() {
25        @Override
26        public ExitStatus execute() {
27          return function.execute(callingContext, commandLine);
28        }
29  
30      };
31    }
32  
33    @FunctionalInterface
34    interface ExecutionFunction {
35      @NonNull
36      ExitStatus execute(
37          @NonNull CallingContext callingContext,
38          @NonNull CommandLine commandLine);
39    }
40  }