classdef DockerOptions < compiler.internal.package.docker.SharedDockerOptions
%COMPILER.PACKAGE.DOCKEROPTIONS  Create a docker options object
%
%    OPTS = COMPILER.PACKAGE.DOCKEROPTIONS(RESULTS) creates an
%        DOCKEROPTIONS object OPTS using the compiler.build.Results
%        object RESULTS. The RESULTS object is created by a
%        compiler.build.standaloneApplication function. The DOCKEROPTIONS
%        object is passed as an input to the compiler.package.docker
%        function.
%
%    OPTS = COMPILER.PACKAGE.DOCKEROPTIONS(RESULTS,NAME,VALUE) creates
%        a DOCKEROPTIONS object OPTS using the compiler.build.Results
%        object RESULTS and additional customizations specified by
%        name-value pairs. The RESULTS object is created by a
%        compiler.build.standaloneApplication function. The DOCKEROPTIONS
%        object is passed as an input to the compiler.package.docker
%        function.
%
%    OPTS = COMPILER.PACKAGE.DOCKEROPTIONS('ImageName',IMAGENAME)
%        creates a default DOCKEROPTIONS object OPTS with image name
%        specified by IMAGENAME. The DOCKEROPTIONS object is passed as an
%        input to the compiler.package.docker function.
%
%    OPTS = COMPILER.PACKAGE.DOCKEROPTIONS('ImageName',IMAGENAME,NAME,VALUE)
%        creates a DOCKEROPTIONS object OPTS with image name specified by
%        IMAGENAME and additional customizations specified by name-value
%        pairs. The DOCKEROPTIONS object is passed as an input to the
%        compiler.package.docker function.
%
%    INPUT ARGUMENTS:
%
%    - RESULTS (A scalar compiler.build.Results object)
%        Build results, created by a compiler.build.standaloneApplication
%        function.
%
%    - IMAGENAME (A row char vector or a string scalar)
%        Name of the docker image. It must comply with docker naming rules.
%
%    OUTPUT ARGUMENTS:
%
%    - OPTS (A scalar compiler.package.DockerOptions object)
%        Docker options, specified as a DOCKEROPTIONS object.
%
%    NAME-VALUE PAIR ARGUMENTS:
%
%    - AdditionalInstructions (A row char vector, a string vector, or a cellstr vector)
%        Lines of text to be added to the Dockerfile that generates the
%        application image.
%
%    - AdditionalPackages (A row char vector, a string vector, or a cellstr vector)
%        List of Ubuntu 22.04 packages to install into the application
%        image.
%
%    - ContainerUser (A row char vector or a string scalar)
%        Name of the Linux user the Docker container will run as.
%
%    - DockerContext (A row char vector or a string scalar)
%        Path to folder where the docker image is built.
%
%    - EntryPoint (A row char vector or a string scalar)
%        Name of command to be executed at image start-up.
%
%    - ExecuteDockerBuild ('on'/'off', true/false, or 1/0)
%        Determines if the function will build the docker image. This is
%        set to 'on' by default. If set to 'off' the function will populate
%        the DockerContext folder without calling 'docker build'.
%
%    - ImageName (A row char vector or a string scalar)
%        Name of the docker image.
%
%    - RuntimeImage (A row char vector or a string scalar)
%        Name of a MATLAB Runtime docker image.
%
%    - VerbosityLevel ('none', 'concise' or 'verbose')
%
%        'none' - Option for no screen output.
%
%        'concise' - Option for enabling update information but no Docker
%        screen output.
%
%        'verbose' (default) - Option for all screen output, including
%        Docker output that occurs from "docker pull" and "docker build".
%
%    EXAMPLES:
%
%    % Create a DOCKEROPTIONS object using the output of the
%    % compiler.build.standaloneApplication command.
%    buildResults = compiler.build.standaloneApplication('mymagic.m');
%    opts = COMPILER.PACKAGE.DOCKEROPTIONS(buildResults);
%
%    % Create a DOCKEROPTIONS object with an image name and additional options
%    % specified as name-value pairs.
%    opts = COMPILER.PACKAGE.DOCKEROPTIONS( ...
%        'ImageName','create_magic_square','DockerContext','./myDockerStuff');
%
%    % Create a DOCKEROPTIONS object with an image name and additional
%    % options specified using dot notation.
%    opts = COMPILER.PACKAGE.DOCKEROPTIONS( ...
%        'ImageName','create_magic_square');
%    opts.DockerContext = './myDockerStuff';
%
%    See also compiler.package.docker, compiler.build.standaloneApplication, mcc

%   Copyright 2020-2023 The MathWorks, Inc.

    % public
    properties
        EntryPoint = ''
    end

    % define abstract
    properties(Constant,Access = protected)
        ImageNameDecoration = ''
        OutputDirTag = 'docker'
    end
    
    % constructor
    methods
        function obj = DockerOptions(varargin)
            obj = obj@compiler.internal.package.docker.SharedDockerOptions(varargin{:});
        end
    end
    
    % set
    methods
        function obj = set.EntryPoint(obj,command)
            
            if isempty(command)
                obj.EntryPoint = '';
                return
            end
            
            compiler.internal.validate.propertyIsScalarText(command,'EntryPoint')
            obj.EntryPoint = char(command);
        end
    end
    
    % define abstract
    methods(Static,Hidden)
        function nvpairs = updateInputsFromResultsObject(resultsobj,varargin)

            if ~strcmp(resultsobj.BuildType,char(compiler.internal.build.BuildTypes.standaloneApplication))
                error(message('Compiler:package:docker:mustBeStandalone'))
            end
            
            nvpairs = varargin;

            decoration = compiler.package.DockerOptions.ImageNameDecoration;
            nvpairs = compiler.internal.package.docker.SharedDockerOptions.updateImageNameFromResultsObject(resultsobj,decoration,nvpairs);
            
            if ~compiler.internal.validate.nameValuePairsHaveProperty('EntryPoint',varargin{:})
                nvpairs = ['EntryPoint',resultsobj.Options.getName,nvpairs];
            end
        end
    end

end
