Skip to content

Commit

Permalink
CliRunCommand增加input参数
Browse files Browse the repository at this point in the history
  • Loading branch information
entropy-cloud committed Jan 16, 2025
1 parent d5f5066 commit 86bded9
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
13 changes: 10 additions & 3 deletions nop-cli-core/src/main/java/io/nop/cli/commands/CliRunCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
import io.nop.api.core.exceptions.NopException;
import io.nop.commons.concurrent.executor.GlobalExecutors;
import io.nop.commons.util.FileHelper;
import io.nop.commons.util.StringHelper;
import io.nop.core.lang.eval.IEvalScope;
import io.nop.core.lang.json.JsonTool;
import io.nop.core.resource.component.ResourceComponentManager;
import io.nop.xlang.api.XLang;
import io.nop.xlang.api.XplModel;
Expand All @@ -22,7 +22,6 @@
import java.io.File;
import java.io.IOException;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
import java.util.concurrent.Callable;
import java.util.concurrent.ConcurrentHashMap;
Expand All @@ -44,7 +43,9 @@ public class CliRunCommand implements Callable<Integer> {
@CommandLine.Parameters(index = "0", description = "脚本文件路径或者脚本文件目录。如果是目录,则会运行目录下所有的xrun文件")
File file;

@CommandLine.Option(names = {"-i", "--interval"}, description = "循环运行的时间间隔")
@CommandLine.Option(names = {"-i", "--input"}, description = "输入参数")
String input;
@CommandLine.Option(names = {"-t", "--interval"}, description = "循环运行的时间间隔")
int interval;

public Integer call() {
Expand All @@ -55,6 +56,11 @@ public Integer call() {
}

Map<String, Object> globalState = new ConcurrentHashMap<>();
if (input != null) {
Map<String, Object> map = (Map<String, Object>) JsonTool.parseNonStrict(null, input);
if (map != null)
globalState.putAll(map);
}

runTasks(globalState);

Expand Down Expand Up @@ -98,6 +104,7 @@ private void runFile(File file, Map<String, Object> globalState) {
String path = FileHelper.getFileUrl(file);
XplModel xpl = (XplModel) ResourceComponentManager.instance().loadComponentModel(path);
IEvalScope scope = XLang.newEvalScope();
scope.setLocalValues(globalState);
scope.setLocalValue("globalState", globalState);
xpl.invoke(scope);
}
Expand Down
1 change: 1 addition & 0 deletions nop-cli-core/src/main/resources/nop-vfs-index.txt
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@
/nop/core/xlib/biz!when.xlib
/nop/core/xlib/biz-gen.xlib
/nop/core/xlib/biz.xlib
/nop/core/xlib/dsl-gen.xlib
/nop/core/xlib/file.xlib
/nop/core/xlib/filter.xlib
/nop/core/xlib/meta-gen.xlib
Expand Down

0 comments on commit 86bded9

Please sign in to comment.