Add jobs commands help

git-svn-id: https://svn.apache.org/repos/asf/felix/trunk@1736023 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/gogo/jline/src/main/java/org/apache/felix/gogo/jline/Builtin.java b/gogo/jline/src/main/java/org/apache/felix/gogo/jline/Builtin.java
index b0b10a7..74f4291 100644
--- a/gogo/jline/src/main/java/org/apache/felix/gogo/jline/Builtin.java
+++ b/gogo/jline/src/main/java/org/apache/felix/gogo/jline/Builtin.java
@@ -459,6 +459,20 @@
     }
 
     public void jobs(CommandSession session, String[] argv) {
+        final String[] usage = {"jobs - list jobs",
+                "Usage: jobs [OPTIONS]",
+                "  -? --help                show help",
+        };
+        Options opt = Options.compile(usage).parse(argv);
+        if (opt.isSet("help")) {
+            opt.usage(System.err);
+            return;
+        }
+        if (!opt.args().isEmpty()) {
+            System.err.println("usage: jobs");
+            session.error(2);
+            return;
+        }
         List<Job> jobs = session.jobs();
         Job current = session.currentJob();
         for (Job job : jobs) {
@@ -470,6 +484,20 @@
     }
 
     public void fg(CommandSession session, String[] argv) {
+        final String[] usage = {"fg - put job in foreground",
+                "Usage: fg [OPTIONS] [jobid]",
+                "  -? --help                show help",
+        };
+        Options opt = Options.compile(usage).parse(argv);
+        if (opt.isSet("help")) {
+            opt.usage(System.err);
+            return;
+        }
+        if (opt.args().size() > 1) {
+            System.err.println("usage: fg [jobid]");
+            session.error(2);
+            return;
+        }
         List<Job> jobs = session.jobs();
         Collections.reverse(jobs);
         Job current = session.currentJob();
@@ -480,6 +508,7 @@
                 job.foreground();
             } else {
                 System.err.println("fg: no current job");
+                session.error(1);
             }
         } else {
             Job job = jobs.stream().filter(j -> j != current && argv[0].equals(Integer.toString(j.id())))
@@ -488,11 +517,26 @@
                 job.foreground();
             } else {
                 System.err.println("fg: job not found: " + argv[0]);
+                session.error(1);
             }
         }
     }
 
     public void bg(CommandSession session, String[] argv) {
+        final String[] usage = {"bg - put job in background",
+                "Usage: bg [OPTIONS] [jobid]",
+                "  -? --help                show help",
+        };
+        Options opt = Options.compile(usage).parse(argv);
+        if (opt.isSet("help")) {
+            opt.usage(System.err);
+            return;
+        }
+        if (opt.args().size() > 1) {
+            System.err.println("usage: bg [jobid]");
+            session.error(2);
+            return;
+        }
         List<Job> jobs = session.jobs();
         Collections.reverse(jobs);
         Job current = session.currentJob();
@@ -502,7 +546,8 @@
             if (job != null) {
                 job.background();
             } else {
-                System.err.println("fg: no current job");
+                System.err.println("bg: no current job");
+                session.error(1);
             }
         } else {
             Job job = jobs.stream().filter(j -> j != current && argv[0].equals(Integer.toString(j.id())))
@@ -510,7 +555,8 @@
             if (job != null) {
                 job.background();
             } else {
-                System.err.println("fg: job not found: " + argv[0]);
+                System.err.println("bg: job not found: " + argv[0]);
+                session.error(1);
             }
         }
     }
diff --git a/gogo/jline/src/main/resources/gosh_profile b/gogo/jline/src/main/resources/gosh_profile
index 068f5d1..22ccf22 100644
--- a/gogo/jline/src/main/resources/gosh_profile
+++ b/gogo/jline/src/main/resources/gosh_profile
@@ -240,6 +240,15 @@
   complete -c gogo:tmux -e
   complete -c gogo:tmux -d "Terminal multiplexer"
 
+  complete -c gogo:bg -e
+  complete -c gogo:bg -d "Put job in background"
+
+  complete -c gogo:fg -e
+  complete -c gogo:fg -d "Put job in foreground"
+
+  complete -c gogo:jobs -e
+  complete -c gogo:jobs -d "List jobs"
+
   # print welcome message
   cat ($0 resolve motd)
 } {