/**
 * Copyright 1&1 Internet AG, https://github.com/1and1/
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package net.oneandone.stool.cli;

import net.oneandone.stool.util.Session;
import net.oneandone.sushi.fs.file.FileNode;

public class Help {
    private final FileNode manpath;
    private final String command;

    public Help(Session session, String command) {
        this.manpath = session.lib.join("man");
        this.command = command;
    }

    public void run() throws Exception {
        ProcessBuilder builder;
        Process process;

        builder = new ProcessBuilder();
        builder.environment().put("MANPATH", manpath.getAbsolute());
        builder.directory(null /* use current directory */);
        builder.command("man", command == null ? "stool" : "stool-" + command);
        builder.inheritIO();
        process = builder.start();
        process.waitFor();
    }
}

@@ -685,60 +685,203 @@
 til.
-Session;%0Aimport net.oneandone.sushi.fs.file.FileNode
+Files;%0Aimport net.oneandone.stool.util.Session;%0Aimport net.oneandone.sushi.fs.World;%0Aimport net.oneandone.sushi.fs.file.FileNode;%0A%0Aimport java.io.InputStream;%0Aimport java.util.zip.GZIPInputStream
 ;%0A%0Ap
@@ -921,24 +921,19 @@
 nal 
-FileNode manpath
+World world
 ;%0A  
@@ -1029,23 +1029,21 @@
    this.
-manpath
+world
  = sessi
@@ -1049,23 +1049,13 @@
 ion.
-lib.join(%22man%22)
+world
 ;%0A  
@@ -1188,16 +1188,38 @@
 process;
+%0A        FileNode tmp;
 %0A%0A      
@@ -1272,152 +1272,943 @@
 der.
-environment().put(%22MANPATH%22, manpath.getAbsolute());%0A        builder.directory(null /* use current directory */);%0A        builder.command(%22man%22,
+directory(null /* use current directory */);%0A        builder.command(%22less%22);%0A        tmp = format();%0A        builder.redirectInput(tmp.toPath().toFile());%0A        builder.redirectOutput(ProcessBuilder.Redirect.INHERIT);%0A        builder.redirectError(ProcessBuilder.Redirect.INHERIT);%0A        process = builder.start();%0A        process.waitFor();%0A    %7D%0A%0A    private FileNode format() throws Exception %7B%0A        ProcessBuilder builder;%0A        Process process;%0A        String name;%0A        FileNode tmp;%0A%0A        builder = new ProcessBuilder();%0A        builder.directory(null /* use current directory */);%0A        builder.command(%22groff%22, %22-man%22, %22-Tascii%22);%0A        tmp = world.getTemp().createTempFile();%0A        builder.redirectInput(ProcessBuilder.Redirect.PIPE);%0A        builder.redirectOutput(tmp.toPath().toFile());%0A        builder.redirectError(ProcessBuilder.Redirect.INHERIT);%0A        process = builder.start();%0A        name =
  com
@@ -2250,17 +2250,16 @@
  command
-)
 ;%0A      
@@ -2264,60 +2264,312 @@
     
-builder.inheritIO();%0A        process = builder.start
+try (InputStream src = world.resource(%22templates/man/man1/%22 + name + %22.1.gz%22).newInputStream()) %7B%0A            try (GZIPInputStream unzip = new GZIPInputStream(src)) %7B%0A                world.getBuffer().copy(unzip, process.getOutputStream());%0A            %7D%0A        %7D%0A        process.getOutputStream().close
 ();%0A
@@ -2591,20 +2591,40 @@
 .waitFor();%0A
+        return tmp;%0A
     %7D%0A%7D%0A

fix internal man pages