Search in sources :

Example 6 with CliContext

use of act.cli.CliContext in project actframework by actframework.

the class CliOverHttp method run.

@PostAction("cmd")
public Result run(String cmd, ActionContext context) throws IOException {
    CliHandler handler = handler(cmd);
    ByteArrayOutputStream os = new ByteArrayOutputStream();
    CliContext cliContext = new CliOverHttpContext(context, os);
    handler.handle(cliContext);
    cliContext.flush();
    String txt = new String(os.toByteArray(), "UTF-8");
    txt = txt.replace("^J", "\n");
    return text(txt);
}
Also used : CliOverHttpContext(act.cli.CliOverHttpContext) ByteArrayOutputStream(java.io.ByteArrayOutputStream) CliHandler(act.handler.CliHandler) CliContext(act.cli.CliContext) PostAction(org.osgl.mvc.annotation.PostAction)

Example 7 with CliContext

use of act.cli.CliContext in project actframework by actframework.

the class RequestScope method put.

public <T> void put(String key, T t) {
    if (null == t) {
        return;
    }
    ActionContext actionContext = ActionContext.current();
    if (null != actionContext) {
        actionContext.attribute(key, t);
    }
    CliContext cliContext = CliContext.current();
    if (null != cliContext) {
        cliContext.attribute(key, t);
    }
}
Also used : ActionContext(act.app.ActionContext) CliContext(act.cli.CliContext)

Example 8 with CliContext

use of act.cli.CliContext in project actframework by actframework.

the class CliVarArgumentLoader method load.

@Override
public Object load(Object cached, ActContext<?> context, boolean noDefaultValue) {
    CliContext ctx = (CliContext) context;
    List list = new ArrayList();
    CliContext.ParsingContext parsingContext = ctx.parsingContext();
    CommandLineParser parser = ctx.commandLine();
    while (parsingContext.hasArguments(parser)) {
        int id = ctx.parsingContext().curArgId().getAndIncrement();
        list.add(resolver.resolve(parser.argument(id)));
    }
    return ArrayLoader.listToArray(list, componentType);
}
Also used : ArrayList(java.util.ArrayList) List(java.util.List) ArrayList(java.util.ArrayList) CommandLineParser(act.cli.util.CommandLineParser) CliContext(act.cli.CliContext)

Aggregations

CliContext (act.cli.CliContext)8 ActionContext (act.app.ActionContext)4 CliSession (act.cli.CliSession)2 CliOverHttpContext (act.cli.CliOverHttpContext)1 CommandLineParser (act.cli.util.CommandLineParser)1 CliHandler (act.handler.CliHandler)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 H (org.osgl.http.H)1 PostAction (org.osgl.mvc.annotation.PostAction)1