Skip to content
Raymond Chen edited this page Mar 30, 2019 · 1 revision

struct reader

The xlang::cmd::reader structure is defined in cmd_reader.h and parses a command line (provided in argc, argv format) according to the specified command line options.

struct reader constructor

reader(int argc, char** argv, const option options[]) noexcept(false)

Parses the command line according to the specified options. The options must be a classic C array. (See example.)

If the command line parameters are not valid according to the options, a std::invalid_argument exception is thrown. The message is suitable for display to the user.

operator bool

operator bool() const noexcept

Returns true if the command line was nonempty.

exists

bool exists(std::string_view const& name) const noexcept

Returns true if the named option (no leading hyphen) was present on the command line.

values

const std::vector<std::string>& values(std::string_view const& name) const noexcept;

Returns a vector of strings representing the values associated with the named option (no leading hyphen). If the option was not present on the command line at all, an empty vector is returned.

value

std::string
value(std::string_view const& name, std::string_view const& default_value = {}) const;

Returns the first value given to the named option (no leading hyphen). If the option has more than one value, only the first is returned. If the option has no values, or if it doesn't exist, then the default_value is returned as a std::string.

Complexity: O(n) where n is the number of options.

Exceptions: Throws std::bad_alloc if out of memory.

files

std::set<std::string> files(std::string_view const& name) const

template<typename F>
std::set<std::string> files(std::string_view const& name, F directory_filter) const

Takes the values associated with a named option (no leading hyphen) and converts them to a list of file names.

The optional directory_filter functor is called with a std::string representing the full path to a file found in a directory, and it returns true if the file should be added. If omitted, then all files are accepted.

For each value associated with the named option:

  • If the value is the path to a directory, then the contents of the directory are enumerated, and each file is passed to the directory_filter. If the filter returns true, then the file is added to the set.
  • If the value is the path to a file, then the file is added to the set. The directory_filter is not consulted.
  • If the value is the literal string local, then all files in the %windir%\System32\WinMetadata directory are added, subject to the directory_filter.
  • If the value is the literal string sdk, then the files in the current SDK are added. The directory_filter is not consulted.
  • If the value is the literal string sdk+, then the files in the current SDK are added, as well as files in the extension SDKs. The directory_filter is not consulted.
  • If the value is a literal string of the form a.b.c.d, then the files from that version of the SDK are added. The directory_filter is not consulted.
  • If the value is the literal string sdk+, then the files from that version of the SDK are added, as well as files in the extension SDKs. The directory_filter is not consulted.

The "current SDK" is defined as follows:

  • If the program is running from a directory whose full path contains a version string pattern (a.b.c.d), then that version is used as the SDK version.
  • Otherwise, the highest-numbered installed SDK is used.
  • If no installed SDK can be found, then a ``std::invalid_argumentexception is thrown. Themessage` is suitable for display to the user.
Clone this wiki locally