Package: gio

Class g-application-command-line

Superclasses

g-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 this "command-line" signal emission.
Allowed values: GVariant<aay>
Default value: nil
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.
Allowed values: GVariant<a{sv}>
Default value: nil
platform-data
The platform-data property of type g-variant (Write / Construct Only)
Platform-specific data for the command line.
Allowed values: GVariant<a{sv}>
Default value: NULL

Details

The g-application-command-line class represents a command line invocation of an application. It is created by the g-application object 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, i.e. the current process is running in direct response to the invocation, or remote, i.e. some other process forwarded the command line to this process.

The g-application-command-line object can provide the command line arguments for use with the g-option-context command line parsing API, with the g-application-command-line-get-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, i.e. the process exits when the last reference is dropped.

The main use for the g-application-command-line object, and the "command-line" signal, is 'Emacs server' like use cases: You can set the EDITOR environment variable to have e.g. 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.

Example

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 (if argv 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-get-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

2021-9-18