RT 5.0.3 Documentation
RT::Interface::CLI
NAME
RT::Interface::CLI - helper functions for creating a commandline RT interface
SYNOPSIS
use lib "/opt/rt5/local/lib", "/opt/rt5/lib";
use RT::Interface::CLI qw(GetCurrentUser Init loc);
# Create a hash to hold parsed values
my %OPT = (
"id" => 1,
);
# Process command-line arguments, load the configuration, and connect
# to the database. See below for options provided by default.
Init(
\%OPT,
"id=i", # Getopt::Long options
);
print "Got an id: " . $OPT{'id'};
# Get the current user all loaded
my $CurrentUser = GetCurrentUser();
print loc('Hello!'); # Synonym of $CurrentUser->loc('Hello!');
DESCRIPTION
The following methods can be loaded in your RT CLI script.
METHODS
GetCurrentUser
Figures out the uid of the current user and returns an RT::CurrentUser object loaded with that user. if the current user isn't found, returns a copy of RT::Nobody.
loc
Synonym of $CurrentUser->loc().
Init
A shim for "GetOptions" in Getopt::Long which automatically adds a --help
option if it is not supplied. It then calls "LoadConfig" in RT and "Init" in RT.
It sets the LogToSTDERR
setting to warning
, to ensure that the user sees all relevant warnings. It also adds --quiet
and --verbose
options, which adjust the LogToSTDERR
value to error
or debug
, respectively.
If debug
is provided as a parameter, it added as an alias for --verbose
.
statement-log
provides a command-line version of the $StatementLog
option in the main RT config file. This allows users to log SQL for queries run in a CLI script in the same manner as the web UI. It accepts log levels like $StatementLog
:
--statement-log=debug
← Back to index