function targetObject = get(targetType, varargin)
%TARGET.GET    Retrieve target object from internal database.
%   targetObject = TARGET.GET(targetType) retrieves all target objects
%   from an internal database. If no target objects exist in the database,
%   an empty array is returned.
%
%   targetObject = TARGET.GET(targetType, targetObjectId) uses the
%   specified class and identifier to retrieve a target object from the
%   database. If the target object does not exist in database, an empty
%   array is returned.
%
%   targetObject = TARGET.GET(..., Name, Value) retrieves from the
%   database the target objects that match the specified name-value pair
%   arguments. If no such target objects exist in the database, an empty
%   array is returned.
%   Supported argument names include:
%
%   CaseSensitive       If value is true (default), string matching is case
%                       sensitive. If value is false, string matching is
%                       not case sensitive.
%
%   'propertyName'      Retrieve a target object for which the specified
%                       property is equal to the specified value.
%
%   See also TARGET.CREATE, TARGET.ADD, TARGET.REMOVE

%   Copyright 2018-2022 The MathWorks, Inc.

    arguments
        targetType {mustBeTextScalar, target.internal.validators.mustBeTarget}
    end
    arguments (Repeating)
        varargin
    end

    [varargin{:}] = targetframework.internal.user.commandline.matlab.Helpers.unwrapValues(varargin{:});

    % Catch any error thrown by the internal APIs and rethrow it by hiding
    % the stack.
    try
        internalTargetObject = target.internal.get(targetType, varargin{:});
    catch exception
        throwAsCaller(exception);
    end

    targetObject = targetframework.internal.user.commandline.matlab.Helpers.wrapValues(internalTargetObject);
end
