use of org.apache.felix.service.command.Process in project felix by apache.
the class Builtin method setopt.
public void setopt(CommandSession session, String[] argv) {
Process process = Process.Utils.current();
Commands.setopt(Shell.getReader(session), process.out(), process.err(), argv);
}
use of org.apache.felix.service.command.Process in project felix by apache.
the class Builtin method widget.
public void widget(final CommandSession session, String[] argv) throws Exception {
java.util.function.Function<String, Widget> creator = func -> () -> {
try {
session.execute(func);
} catch (Exception e) {
// TODO: log exception ?
return false;
}
return true;
};
Process process = Process.Utils.current();
Commands.widget(Shell.getReader(session), process.out(), process.err(), creator, argv);
}
use of org.apache.felix.service.command.Process in project felix by apache.
the class Builtin method fg.
public void fg(CommandSession session, String[] argv) {
final String[] usage = { "fg - put job in foreground", "Usage: fg [OPTIONS] [jobid]", " -? --help show help" };
Process process = Process.Utils.current();
Options opt = Options.compile(usage).parse(argv);
if (opt.isSet("help")) {
opt.usage(process.err());
return;
}
if (opt.args().size() > 1) {
process.err().println("usage: fg [jobid]");
process.error(2);
return;
}
List<Job> jobs = new ArrayList<>(session.jobs());
Collections.reverse(jobs);
Job current = Job.Utils.current();
if (argv.length == 0) {
Job job = jobs.stream().filter(j -> j != current).findFirst().orElse(null);
if (job != null) {
job.foreground();
} else {
process.err().println("fg: no current job");
process.error(1);
}
} else {
Job job = jobs.stream().filter(j -> j != current && argv[0].equals(Integer.toString(j.id()))).findFirst().orElse(null);
if (job != null) {
job.foreground();
} else {
process.err().println("fg: job not found: " + argv[0]);
process.error(1);
}
}
}
use of org.apache.felix.service.command.Process in project felix by apache.
the class Posix method less.
protected void less(CommandSession session, Process process, String[] argv) throws Exception {
String[] usage = { "less - file pager", "Usage: less [OPTIONS] [FILES]", " -? --help Show help", " -e --quit-at-eof Exit on second EOF", " -E --QUIT-AT-EOF Exit on EOF", " -F --quit-if-one-screen Exit if entire file fits on first screen", " -q --quiet --silent Silent mode", " -Q --QUIET --SILENT Completely silent", " -S --chop-long-lines Do not fold long lines", " -i --ignore-case Search ignores lowercase case", " -I --IGNORE-CASE Search ignores all case", " -x --tabs Set tab stops", " -N --LINE-NUMBERS Display line number for each line", " --no-init Disable terminal initialization", " --no-keypad Disable keypad handling" };
boolean hasExtendedOptions = false;
try {
Less.class.getField("quitIfOneScreen");
hasExtendedOptions = true;
} catch (NoSuchFieldException e) {
List<String> ustrs = new ArrayList<>(Arrays.asList(usage));
ustrs.removeIf(s -> s.contains("--quit-if-one-screen") || s.contains("--no-init") || s.contains("--no-keypad"));
usage = ustrs.toArray(new String[ustrs.size()]);
}
Options opt = parseOptions(session, usage, argv);
List<Source> sources = new ArrayList<>();
if (opt.args().isEmpty()) {
opt.args().add("-");
}
for (String arg : opt.args()) {
if ("-".equals(arg)) {
sources.add(new StdInSource(process));
} else {
sources.add(new PathSource(session.currentDir().resolve(arg), arg));
}
}
if (!process.isTty(1)) {
for (Source source : sources) {
try (BufferedReader reader = new BufferedReader(new InputStreamReader(source.read()))) {
cat(process, reader, opt.isSet("LINE-NUMBERS"));
}
}
return;
}
Less less = new Less(Shell.getTerminal(session));
less.quitAtFirstEof = opt.isSet("QUIT-AT-EOF");
less.quitAtSecondEof = opt.isSet("quit-at-eof");
less.quiet = opt.isSet("quiet");
less.veryQuiet = opt.isSet("QUIET");
less.chopLongLines = opt.isSet("chop-long-lines");
less.ignoreCaseAlways = opt.isSet("IGNORE-CASE");
less.ignoreCaseCond = opt.isSet("ignore-case");
if (opt.isSet("tabs")) {
less.tabs = opt.getNumber("tabs");
}
less.printLineNumbers = opt.isSet("LINE-NUMBERS");
if (hasExtendedOptions) {
Less.class.getField("quitIfOneScreen").set(less, opt.isSet("quit-if-one-screen"));
Less.class.getField("noInit").set(less, opt.isSet("no-init"));
Less.class.getField("noKeypad").set(less, opt.isSet("no-keypad"));
}
less.run(sources);
}
use of org.apache.felix.service.command.Process in project felix by apache.
the class Builtin method complete.
public void complete(CommandSession session, String[] argv) {
Process process = Process.Utils.current();
Commands.complete(Shell.getReader(session), process.out(), process.err(), Shell.getCompletions(session), argv);
}
Aggregations