Skip to content

Commit

Permalink
Add echo command
Browse files Browse the repository at this point in the history
  • Loading branch information
neilcsmith-net committed Feb 28, 2024
1 parent 82127a4 commit d55bef2
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,9 @@

import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
import org.praxislive.core.Value;
import org.praxislive.core.types.PString;
import org.praxislive.script.Command;
import org.praxislive.script.CommandInstaller;
import org.praxislive.script.Env;
Expand All @@ -36,22 +38,24 @@
/**
*
*/
public class VariableCmds implements CommandInstaller {
public class BaseCmds implements CommandInstaller {

private static final VariableCmds instance = new VariableCmds();
private static final Command SET = new Set();
private final static System.Logger log = System.getLogger(VariableCmds.class.getName());
private static final System.Logger LOG = System.getLogger(BaseCmds.class.getName());
private static final Set SET = new Set();
private static final Echo ECHO = new Echo();
private static final BaseCmds INSTANCE = new BaseCmds();

private VariableCmds() {
private BaseCmds() {
}

@Override
public void install(Map<String, Command> commands) {
commands.put("set", SET);
commands.put("echo", ECHO);
}

public static VariableCmds getInstance() {
return instance;
public static BaseCmds getInstance() {
return INSTANCE;
}

private static class Set implements InlineCommand {
Expand All @@ -67,11 +71,24 @@ public List<Value> process(Env context, Namespace namespace, List<Value> args) t
if (var != null) {
var.setValue(val);
} else {
log.log(Level.TRACE, () -> "SET COMMAND : Adding variable " + varName + " to namespace " + namespace);
LOG.log(Level.TRACE, () -> "SET COMMAND : Adding variable " + varName + " to namespace " + namespace);
namespace.createVariable(varName, val);
}
return List.of(val);

}
}

private static class Echo implements InlineCommand {

@Override
public List<Value> process(Env context, Namespace namespace, List<Value> args) throws Exception {
return List.of(PString.of(
args.stream()
.map(Value::toString)
.collect(Collectors.joining())));
}

}

}
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,15 @@
*/
public class CoreCommandsInstaller implements CommandInstaller {

@Override
public void install(Map<String, Command> commands) {
BaseCmds.getInstance().install(commands);
ArrayCmds.getInstance().install(commands);
AtCmds.getInstance().install(commands);
ConnectionCmds.getInstance().install(commands);
FileCmds.getInstance().install(commands);
ResourceCmds.getInstance().install(commands);
ScriptCmds.getInstance().install(commands);
VariableCmds.getInstance().install(commands);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
/**
*
*/
public class EvalStackFrame implements StackFrame {
class EvalStackFrame implements StackFrame {

private static final System.Logger log = System.getLogger(EvalStackFrame.class.getName());

Expand Down

0 comments on commit d55bef2

Please sign in to comment.