guix-commits
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[dmd] 01/05: deco: "deco status" is equivalent to "deco status dmd".


From: Ludovic Courtès
Subject: [dmd] 01/05: deco: "deco status" is equivalent to "deco status dmd".
Date: Sat, 09 Jan 2016 14:48:37 +0000

civodul pushed a commit to branch master
in repository dmd.

commit b54ed34c64bef280578ac754b01a58d748c7f97f
Author: Ludovic Courtès <address@hidden>
Date:   Fri Jan 8 22:27:30 2016 +0100

    deco: "deco status" is equivalent to "deco status dmd".
    
    * modules/deco.scm (run-command): New procedure.
    (main): Use it.  Allow the 'service' argument to be omitted for the
    "status" and "detailed-status" actions.
    * tests/basic.sh, tests/respawn.sh: Use "deco status" instead of "deco
    status dmd" in some places.
    * dmd.texi (Jump Start): Simplify the examples accordingly.
    (Invoking deco): Document the change.
---
 dmd.texi         |   19 ++++++++++++-----
 modules/deco.scm |   58 +++++++++++++++++++++++++++--------------------------
 tests/basic.sh   |   10 ++++----
 tests/respawn.sh |    2 +-
 4 files changed, 49 insertions(+), 40 deletions(-)

diff --git a/dmd.texi b/dmd.texi
index 97ed341..e958ab3 100644
--- a/dmd.texi
+++ b/dmd.texi
@@ -172,14 +172,14 @@ will automatically be started as well.  The current 
status of all the
 services defined in the configuration file can be queried like this:
 
 @example
-deco status dmd
+deco status
 @end example
 
 @noindent
 Or, to get additional details about each service, run:
 
 @example
-deco detailed-status dmd
+deco detailed-status
 @end example
 
 @noindent
@@ -431,12 +431,19 @@ running instance of @command{dmd} (@pxref{Invoking dmd}). 
 It has the
 following synopsis:
 
 @example
-deco address@hidden@dots{}] @var{action} @var{service} address@hidden@dots{}]
+deco address@hidden@dots{}] @var{action} address@hidden address@hidden@dots{}]]
 @end example
 
-It causes the @var{action} of the @var{service} to be invoked.  For each
-action, you should pass the appropriate @var{arg}s.  Actions that are
-available for every service are @code{start}, @code{stop},
+It causes the @var{action} of the @var{service} to be invoked.  When
address@hidden is omitted and @var{action} is @code{status} or
address@hidden, the @code{dmd} service is address@hidden
+shorthand does not work for other actions such as @code{stop}, because
+inadvertently typing @code{deco stop} would stop all the services, which
+could be pretty annoying.} (@pxref{The dmd and unknown services}, for
+more information on the @code{dmd} service.)
+
+For each action, you should pass the appropriate @var{arg}s.  Actions
+that are available for every service are @code{start}, @code{stop},
 @code{restart}, @code{status}, @code{enable}, @code{disable}, and
 @code{doc}.
 
diff --git a/modules/deco.scm b/modules/deco.scm
index 30e4f82..2af1207 100644
--- a/modules/deco.scm
+++ b/modules/deco.scm
@@ -1,6 +1,6 @@
 ;; deco.scm -- The `DaEmon COntrol' program.
-;; Copyright (C) 2013, 2014 Ludovic Court�s <address@hidden>
-;; Copyright (C) 2002, 2003 Wolfgang J�hrling <address@hidden>
+;; Copyright (C) 2013, 2014, 2016 Ludovic Courtès <address@hidden>
+;; Copyright (C) 2002, 2003 Wolfgang Jährling <address@hidden>
 ;;
 ;; This file is part of GNU dmd.
 ;;
@@ -33,6 +33,25 @@
 
 
 
+(define (run-command socket-file action service args)
+  "Perform ACTION with ARGS on SERVICE, and display the result.  Connect to
+the daemon via SOCKET-FILE."
+  (with-system-error-handling
+   (let ((sock (open-connection socket-file)))
+     ;; Send the command.
+     (write-command (dmd-command (string->symbol action)
+                                 (string->symbol service)
+                                 #:arguments args)
+                    sock)
+
+     ;; Receive output.
+     (setvbuf sock _IOLBF)
+     (let loop ((line (read-line sock)))
+       (unless (eof-object? line)
+         (display line)
+         (newline)
+         (loop (read-line sock)))))))
+
 ;; Main program.
 (define (main . args)
   (false-if-exception (setlocale LC_ALL ""))
@@ -54,29 +73,12 @@
                    #:action (lambda (file)
                               (set! socket-file file))))
 
-    ;; Make sure we got at least two arguments.
-    (when (< (length command-args) 2)
-      (format (current-error-port)
-              (l10n "Usage: deco ACTION SERVICE OPTIONS...~%"))
-      (exit 1))
-
-    (set! command-args (reverse command-args))
-
-    (with-system-error-handling
-     (let ((sock (open-connection socket-file)))
-       ;; Send the command.
-       (match command-args
-         ((action service args ...)
-          (write-command (dmd-command (string->symbol action)
-                                      (string->symbol service)
-                                      #:arguments args)
-                         sock)))
-
-       ;; Receive output.
-       (setvbuf sock _IOLBF)
-       (let loop ((line (read-line sock)))
-         (unless (eof-object? line)
-           (display line)
-           (newline)
-           (loop (read-line sock))))))))
-
+    (match (reverse command-args)
+      (((and action (or "status" "detailed-status"))) ;one argument
+       (run-command socket-file action "dmd" '()))
+      ((action service args ...)
+       (run-command socket-file action service args))
+      (_
+       (format (current-error-port)
+               (l10n "Usage: deco ACTION [SERVICE [OPTIONS...]]~%"))
+       (exit 1)))))
diff --git a/tests/basic.sh b/tests/basic.sh
index a1825de..c160345 100644
--- a/tests/basic.sh
+++ b/tests/basic.sh
@@ -1,5 +1,5 @@
 # GNU dmd --- Test basic communication capabilities.
-# Copyright © 2013, 2014 Ludovic Courtès <address@hidden>
+# Copyright © 2013, 2014, 2016 Ludovic Courtès <address@hidden>
 # Copyright © 2014 Alex Sassmannshausen <address@hidden>
 #
 # This file is part of GNU dmd.
@@ -83,15 +83,15 @@ $deco status test-2 | grep started
 
 # Unload one service, make sure the other it still around.
 $deco unload dmd test
-$deco status dmd | grep "Stopped: (test-2)"
+$deco status | grep "Stopped: (test-2)"
 
 $deco reload dmd "$conf"
-test "`$deco status dmd`" == "$pristine_status"
+test "`$deco status`" == "$pristine_status"
 
 # Unload everything and make sure only 'dmd' is left.
 $deco unload dmd all
-$deco status dmd | grep "Stopped: ()"
-$deco status dmd | grep "Started: (dmd)"
+$deco status | grep "Stopped: ()"
+$deco status | grep "Started: (dmd)"
 
 $deco stop dmd
 ! kill -0 $dmd_pid
diff --git a/tests/respawn.sh b/tests/respawn.sh
index b98ce4f..4d0f5a7 100644
--- a/tests/respawn.sh
+++ b/tests/respawn.sh
@@ -91,7 +91,7 @@ dmd_pid="`cat $pid`"
 
 kill -0 $dmd_pid
 test -S "$socket"
-$deco status dmd
+$deco status
 $deco status test1 | grep started
 $deco status test2 | grep started
 



reply via email to

[Prev in Thread] Current Thread [Next in Thread]