Package: gio

Class gio:application-command-line

Superclasses

gobject:object, common-lisp:standard-object, common-lisp:t

Documented Subclasses

None

Direct Slots

arguments
The arguments property of type g:variant (Write / Construct Only)
The command line that caused the "command-line" signal emission.
Note: This property is not directly accessible from the Lisp side, but through the corresponding g:application-command-line-arguments function.
is-remote
The is-remote property of type :boolean (Read)
True if this is a remote command line.
Default value: false
options
The options property of type g:variant (Write / Construct Only)
The options sent along with the command line.
Note: This property is not directly accessible from the Lisp side, but through the corresponding g:application-command-line-options-dict function.
platform-data
The platform-data property of type g:variant (Write / Construct Only)
Platform-specific data for the command line.
Note: This property is not directly accessible from the Lisp side, but through the corresponding g:application-command-line-platform-data function.

Details

The g:application-command-line class represents a command line invocation of an application. It is created by the g:application instance and emitted in the "command-line" signal and virtual function.

The class contains the list of arguments that the program was invoked with. It is also possible to query if the command line invocation was local, that is, the current process is running in direct response to the invocation, or remote, that is, some other process forwarded the command line to this process.

The g:application-command-line instance can provide the command line arguments for use with the g:option-context command line parsing API, with the g:application-command-line-arguments function.

The exit status of the originally invoked process may be set and messages can be printed to stdout or stderr of that process. The life cycle of the originally invoked process is tied to the life cycle of this object, that is, the process exits when the last reference is dropped.

The main use for the g:application-command-line instance, and the "command-line" signal, is 'Emacs server' like use cases. You can set the EDITOR environment variable to have, for example GIT, use your favourite editor to edit commit messages, and if you already have an instance of the editor running, the editing will happen in the running instance, instead of opening a new one. An important aspect of this use case is that the process that gets started by GIT does not return until the editing is done.

Examples

Normally, the command line is completely handled in the "command-line" signal handler. The launching instance exits once the signal handler in the primary instance has returned, and the return value of the signal handler becomes the exit status of the launching instance.
(defun application-cmdline (&rest argv)
  (let ((app (make-instance 'g:application
                            :application-id
                            "com.crategus.application-cmdline"
                            :flags :handles-command-line))
        (argv (or argv (uiop:command-line-arguments))))
    ;; Print info about the application
    (format t "Start application~%")
    (format t "       argv : ~a~%" argv)
    (format t "    prgname : ~a~%" (g:prgname))
    ;; Signal handler "command-line"
    (g:signal-connect app "command-line"
        (lambda (application cmdline)
          (declare (ignore application))
          (let ((args (g:application-command-line-arguments cmdline)))
            (format t "Signal handler COMMAND-LINE~%")
            (format t "  arguments : ~a~%" args)
            ;; Return the exit status
            0)))
    ;; Run the application
    (g:application-run app argv)))    
This is the output, when executing the example from the Lisp prompt:
(gio-example:application-cmdline "file1" "file2")
=> Start application
        argv : (file1 file2)
     prgname : sbcl
   Signal handler COMMAND-LINE
         arguments : (file1 file2)
   0    
A stand-alone executable for the example has the following output:
./application-cmdline file1 file2
=> Start application
          argv : (file1 file2)
       prgname : application-cmdline
   Signal handler COMMAND-LINE
     arguments : (file1 file2)    
 

Slot Access Functions

Inherited Slot Access Functions

See also

2025-2-3