function varargout = setupExample(arg,workDir)
% 

%   Copyright 2017-2020 The MathWorks, Inc.

metadata = findExample(arg);

% Determine workDir
if nargin < 2 || ...
        isempty(workDir) || ...
        (isstring(workDir) && length(workDir) == 1 && strlength(workDir)==0)
    workDir = matlab.internal.examples.getWorkDir(metadata);
else
    workDir = matlab.internal.examples.validateWorkDir(workDir);
end

% Setup workdir.
matlab.internal.examples.setupWorkDir(workDir);

% Main file.
matlab.internal.examples.setupMainFile(metadata, workDir);

% Supporting files.
matlab.internal.examples.setupSupportingFiles(metadata, workDir);

if nargout
	varargout{1} = workDir;
    varargout{2} = metadata;
end
end

