File: Show-manpage-if-help-is-invoked.patch

package info (click to toggle)
starjava-ttools 3.5.2-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 22,924 kB
  • sloc: java: 170,407; xml: 19,581; javascript: 670; python: 641; sh: 107; makefile: 27
file content (69 lines) | stat: -rw-r--r-- 2,314 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
From: Ole Streicher <olebole@debian.org>
Date: Thu, 9 Mar 2017 12:34:25 +0100
Subject: Show manpage if help is invoked

---
 .../uk/ac/starlink/ttools/task/LineInvoker.java    | 36 ++++++++++++++++++++--
 1 file changed, 34 insertions(+), 2 deletions(-)

diff --git a/src/main/uk/ac/starlink/ttools/task/LineInvoker.java b/src/main/uk/ac/starlink/ttools/task/LineInvoker.java
index bb006d6..2b52606 100644
--- a/src/main/uk/ac/starlink/ttools/task/LineInvoker.java
+++ b/src/main/uk/ac/starlink/ttools/task/LineInvoker.java
@@ -86,7 +86,11 @@ public class LineInvoker {
                      arg.equals( "-h" ) ) {
                     it.remove();
                     String topic = it.hasNext() ? it.next() : null;
-                    out.println( "\n" + getUsage( topic ) );
+		    try {
+			externalManpage(topic);
+		    } catch (Exception e) {
+			out.println( "\n" + getUsage( topic ) );
+		    }
                     return 0;
                 }
                 else if ( arg.equals( "-version" ) ) {
@@ -423,7 +427,12 @@ public class LineInvoker {
             if ( arg.equals( "-help" ) ||
                  arg.equals( "-h" ) ||
                  arg.equalsIgnoreCase( "help" ) ) {
-                return getTaskUsage( env, task, taskName );
+		try {
+		    externalManpage(taskName);
+		    return "";
+		} catch (Exception e) {
+		    return getTaskUsage( env, task, taskName );
+		}
             }
             else if ( arg.toLowerCase().startsWith( "-help=" ) ) {
                 helpFor = arg.substring( 6 ).trim().toLowerCase();
@@ -621,6 +630,29 @@ public class LineInvoker {
         return sbuf.toString();
     }
 
+    /**
+     * Call the stilts manpage with the "man" command.
+     *
+     */
+    private void externalManpage(String topic) throws IOException {
+	String manpage = "stilts";
+	if ((topic != null)  && topic.length() > 0) {
+	    manpage += "-" + topic;
+	}
+	String[] cmd = new String[3];
+	cmd[0] = "sh";
+	cmd[1] = "-c";
+	cmd[2] = "man " + manpage + " < /dev/tty > /dev/tty";
+	Process p = Runtime.getRuntime().exec(cmd);
+	try {
+	    p.waitFor();
+	} catch (InterruptedException e) {
+	}
+	if (p.exitValue() != 0) {
+	    throw new IOException("man call error");
+	}
+    }
+
     /**
      * Returns a usage string for a task known to this application.
      *