ApplicationCommandLine

class ApplicationCommandLine(**properties: Any)

Superclasses: Object

Constructors:

ApplicationCommandLine(**properties)

Methods

class ApplicationCommandLine
create_file_for_arg(arg: str) File

Creates a File corresponding to a filename that was given as part of the invocation of cmdline.

This differs from new_for_commandline_arg() in that it resolves relative pathnames using the current working directory of the invoking process rather than the local process.

Added in version 2.36.

Parameters:

arg – an argument from cmdline

done() None

Signals that command line processing is completed.

For remote invocation, it causes the invoking process to terminate.

For local invocation, it does nothing.

This method should be called in the command_line handler, after the exit status is set and all messages are printed.

After this call, set_exit_status() has no effect. Subsequent calls to this method are no-ops.

This method is automatically called when the ApplicationCommandLine object is disposed — so you can omit the call in non-garbage collected languages.

Added in version 2.80.

get_arguments() list[str]

Gets the list of arguments that was passed on the command line.

The strings in the array may contain non-UTF-8 data on UNIX (such as filenames or arguments given in the system locale) but are always in UTF-8 on Windows.

If you wish to use the return value with OptionContext, you must use parse_strv().

The return value is None-terminated and should be freed using strfreev().

Added in version 2.28.

get_cwd() str | None

Gets the working directory of the command line invocation. The string may contain non-utf8 data.

It is possible that the remote application did not send a working directory, so this may be None.

The return value should not be modified or freed and is valid for as long as cmdline exists.

Added in version 2.28.

get_environ() list[str]

Gets the contents of the ‘environ’ variable of the command line invocation, as would be returned by get_environ(), ie as a None-terminated list of strings in the form ‘NAME=VALUE’. The strings may contain non-utf8 data.

The remote application usually does not send an environment. Use SEND_ENVIRONMENT to affect that. Even with this flag set it is possible that the environment is still not available (due to invocation messages from other applications).

The return value should not be modified or freed and is valid for as long as cmdline exists.

See getenv() if you are only interested in the value of a single environment variable.

Added in version 2.28.

get_exit_status() int

Gets the exit status of cmdline. See set_exit_status() for more information.

Added in version 2.28.

get_is_remote() bool

Determines if cmdline represents a remote invocation.

Added in version 2.28.

get_options_dict() VariantDict

Gets the options that were passed to g_application_command_line().

If you did not override local_command_line() then these are the same options that were parsed according to the OptionEntry added to the application with add_main_option_entries() and possibly modified from your GApplication::handle-local-options handler.

If no options were sent then an empty dictionary is returned so that you don’t need to check for None.

The data has been passed via an untrusted external process, so the types of all values must be checked before being used.

Added in version 2.40.

get_platform_data() Variant | None

Gets the platform data associated with the invocation of cmdline.

This is a Variant dictionary containing information about the context in which the invocation occurred. It typically contains information like the current working directory and the startup notification ID.

It comes from an untrusted external process and hence the types of all values must be validated before being used.

For local invocation, it will be None.

Added in version 2.28.

get_stdin() InputStream | None

Gets the stdin of the invoking process.

The InputStream can be used to read data passed to the standard input of the invoking process. This doesn’t work on all platforms. Presently, it is only available on UNIX when using a D-Bus daemon capable of passing file descriptors. If stdin is not available then None will be returned. In the future, support may be expanded to other platforms.

You must only call this function once per commandline invocation.

Added in version 2.34.

getenv(name: str) str | None

Gets the value of a particular environment variable of the command line invocation, as would be returned by getenv(). The strings may contain non-utf8 data.

The remote application usually does not send an environment. Use SEND_ENVIRONMENT to affect that. Even with this flag set it is possible that the environment is still not available (due to invocation messages from other applications).

The return value should not be modified or freed and is valid for as long as cmdline exists.

Added in version 2.28.

Parameters:

name – the environment variable to get

print_literal(message: str) None

Prints a message using the stdout print handler in the invoking process.

Unlike print(), message is not a printf()-style format string. Use this function if message contains text you don’t have control over, that could include printf() escape sequences.

Added in version 2.80.

Parameters:

message – the message

printerr_literal(message: str) None

Prints a message using the stderr print handler in the invoking process.

Unlike printerr(), message is not a printf()-style format string. Use this function if message contains text you don’t have control over, that could include printf() escape sequences.

Added in version 2.80.

Parameters:

message – the message

set_exit_status(exit_status: int) None

Sets the exit status that will be used when the invoking process exits.

The return value of the Application::command-line signal is passed to this function when the handler returns. This is the usual way of setting the exit status.

In the event that you want the remote invocation to continue running and want to decide on the exit status in the future, you can use this call. For the case of a remote invocation, the remote process will typically exit when the last reference is dropped on cmdline. The exit status of the remote process will be equal to the last value that was set with this function.

In the case that the commandline invocation is local, the situation is slightly more complicated. If the commandline invocation results in the mainloop running (ie: because the use-count of the application increased to a non-zero value) then the application is considered to have been ‘successful’ in a certain sense, and the exit status is always zero. If the application use count is zero, though, the exit status of the local ApplicationCommandLine is used.

This method is a no-op if done() has been called.

Added in version 2.28.

Parameters:

exit_status – the exit status

Properties

class ApplicationCommandLine
props.arguments: Variant

The type of the None singleton.

Added in version 2.28.

props.is_remote: bool

The type of the None singleton.

Added in version 2.28.

props.options: Variant

The type of the None singleton.

Added in version 2.28.

props.platform_data: Variant

The type of the None singleton.

Added in version 2.28.

Virtual Methods

class ApplicationCommandLine
do_done() None

Signals that command line processing is completed.

For remote invocation, it causes the invoking process to terminate.

For local invocation, it does nothing.

This method should be called in the command_line handler, after the exit status is set and all messages are printed.

After this call, set_exit_status() has no effect. Subsequent calls to this method are no-ops.

This method is automatically called when the ApplicationCommandLine object is disposed — so you can omit the call in non-garbage collected languages.

Added in version 2.80.

do_get_stdin() InputStream | None

Gets the stdin of the invoking process.

The InputStream can be used to read data passed to the standard input of the invoking process. This doesn’t work on all platforms. Presently, it is only available on UNIX when using a D-Bus daemon capable of passing file descriptors. If stdin is not available then None will be returned. In the future, support may be expanded to other platforms.

You must only call this function once per commandline invocation.

Added in version 2.34.

do_print_literal(message: str) None

Prints a message using the stdout print handler in the invoking process.

Unlike print(), message is not a printf()-style format string. Use this function if message contains text you don’t have control over, that could include printf() escape sequences.

Added in version 2.80.

Parameters:

message – the message

do_printerr_literal(message: str) None

Prints a message using the stderr print handler in the invoking process.

Unlike printerr(), message is not a printf()-style format string. Use this function if message contains text you don’t have control over, that could include printf() escape sequences.

Added in version 2.80.

Parameters:

message – the message

Fields

class ApplicationCommandLine
parent_instance
priv