Search in sources :

Example 1 with CliContext

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

the class OptionLoader method load.

@Override
public Object load(Object cachedBean, ActContext<?> context, boolean noDefaultValue) {
    CliContext ctx = (CliContext) context;
    String optVal = ctx.paramVal(bindName);
    if (S.blank(optVal) && required) {
        optVal = getFirstArgument(ctx);
    }
    Object val = null;
    if (S.notBlank(optVal)) {
        val = resolve(optVal);
    }
    if (null == val && null != cachedBean) {
        val = cachedBean;
    }
    if (null == val) {
        if (!required) {
            val = S.notBlank(defVal) ? resolve(defVal) : resolve(null);
        }
    }
    if (null != val && required) {
        ctx.parsingContext().foundRequired(requiredGroup);
    }
    return val;
}
Also used : CliContext(act.cli.CliContext)

Example 2 with CliContext

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

the class CliArgumentLoader method load.

@Override
public Object load(Object cached, ActContext<?> context, boolean noDefaultValue) {
    CliContext ctx = (CliContext) context;
    int id = ctx.parsingContext().curArgId().getAndIncrement();
    String optVal = ctx.commandLine().argument(id);
    Object val = null;
    if (S.notBlank(optVal)) {
        val = resolver.resolve(optVal);
    }
    if (null == val && null != cached) {
        val = cached;
    }
    return val;
}
Also used : CliContext(act.cli.CliContext)

Example 3 with CliContext

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

the class RequestScope method get.

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

Example 4 with CliContext

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

the class SessionScope method get.

@Override
public <T> T get(String key) {
    ActionContext actionContext = ActionContext.current();
    if (null != actionContext) {
        H.Session session = actionContext.session();
        T t = session.cached(key);
        if (null != t) {
            session.cache(key, t, TTL);
        }
        return t;
    }
    CliContext cliContext = CliContext.current();
    if (null != cliContext) {
        CliSession cliSession = cliContext.session();
        return cliSession.attribute(key);
    }
    return null;
}
Also used : H(org.osgl.http.H) ActionContext(act.app.ActionContext) CliContext(act.cli.CliContext) CliSession(act.cli.CliSession)

Example 5 with CliContext

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

the class SessionScope method put.

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

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