// file      : load/load.cli
// license   : MIT; see accompanying LICENSE file

include <vector>;
include <string>;
include <cstdint>; // uint16_t

include <libbrep/types.hxx>;

"\section=1"
"\name=brep-load"
"\summary=load repositories into brep package database"

{
  "<options> <loadtab>",

  "\h|SYNOPSIS|

   \c{\b{brep-load --help}\n
      \b{brep-load --version}\n
      \b{brep-load} [<options>] <loadtab>}

   \h|DESCRIPTION|

   \cb{brep-load} reads the list of repositories from the specified <loadtab>
   configuration file, fetches their manifest files, and loads the repository
   and package information into the \cb{package} database, suitable for
   consumption by the \cb{brep} web module.

   Note that \cb{brep-load} expects the \cb{package} database schema to have
   already been created using \l{brep-migrate(1)}.

   Also note that \cb{brep-load} requires \l{bpkg(1)} to fetch repository
   information. See \cb{--bpkg} for more information on the package manager
   program."
}

class options
{
  "\h|OPTIONS|"

  bool --ignore-unknown
  {
    "Ignore unknown manifest entries."
  }

  bool --force
  {
    "Reload package information regardless of the repository manifest file
     timestamps."
  };

  bool --shallow
  {
    "Don't load package information from prerequisite or complement
     repositories, don't fail if unable to resolve a package dependency, and
     don't detect package dependency cycles."
  };

  std::string --tenant
  {
    "<id>",
    "Tenant the package and repository information should be loaded in. If not
     specified, then the single-tenant mode is assumed."
  };

  bool --private
  {
    "Display the tenant packages in the web interface only in the tenant view
     mode."
  };

  std::string --interactive
  {
    "<bkp>",
    "Build the tenant packages interactively, stopping builds at the specified
     breakpoint. Implies \cb{--private}."
  };

  brep::path --overrides-file
  {
    "<file>",
    "Read package manifest overrides from the specified manifest fragment
     file and apply them to packages being loaded."
  }

  std::string --db-user|-u
  {
    "<user>",
    "Database user name. If not specified, then operating system (login)
     name is used."
  }

  std::string --db-password
  {
    "<pass>",
    "Database password. If not specified, then login without password is
     expected to work."
  }

  std::string --db-name|-n = "brep_package"
  {
    "<name>",
    "Database name. If not specified, then \cb{brep_package} is used by
     default."
  }

  std::string --db-host|-h
  {
    "<host>",
    "Database host name, address, or socket. If not specified, then connect
     to \cb{localhost} using the operating system-default mechanism
     (Unix-domain socket, etc)."
  }

  std::uint16_t --db-port|-p = 0
  {
    "<port>",
    "Database port number. If not specified, the default port is used."
  }

  brep::path --bpkg = "bpkg"
  {
    "<path>",
    "The package manager program to be used to fetch repository information.
     This should be the path to the \cb{bpkg} executable. You can also specify
     additional options that should be passed to the package manager program
     with \cb{--bpkg-option}. If the package manager program is not explicitly
     specified, then \cb{brep-load} will use \cb{bpkg} by default."
  }

  brep::strings --bpkg-option
  {
    "<opt>",
    "Additional option to be passed to the package manager program. See
     \cb{--bpkg} for more information on the package manager program. Repeat
     this option to specify multiple package manager options."
  }

  std::string --pager // String to allow empty value.
  {
    "<path>",
    "The pager program to be used to show long text. Commonly used pager
     programs are \cb{less} and \cb{more}. You can also specify additional
     options that should be passed to the pager program with
     \cb{--pager-option}. If an empty string is specified as the pager
     program, then no pager will be used. If the pager program is not
     explicitly specified, then \cb{brep-load} will try to use \cb{less}. If
     it is not available, then no pager will be used."
  }

  std::vector<std::string> --pager-option
  {
    "<opt>",
    "Additional option to be passed to the pager program. See \cb{--pager}
     for more information on the pager program. Repeat this option to
     specify multiple pager options."
  }

  bool --help {"Print usage information and exit."}
  bool --version {"Print version and exit."}
};

"\h|EXIT STATUS|

\dl|

\li|\cb{0}

Success.|

\li|\cb{1}

Fatal error.|

\li|\cb{2}

An instance of \cb{brep-load} or some other \cb{brep} utility is already
running. Try again.|

\li|\cb{3}

Recoverable database error. Try again.||
"