ZeroInstall.Publish.Capture.CommandMapper.CommandMapper C# (CSharp) Method

CommandMapper() public method

Creates a new command provider.
public CommandMapper ( [ installationDir, [ commmands ) : System
installationDir [ The fully qualified path to the installation directory.
commmands [ A list of all known-commands available within the installation directory.
return System
        public CommandMapper([NotNull] string installationDir, [NotNull, ItemNotNull] IEnumerable<Command> commmands)
        {
            #region Sanity checks
            if (string.IsNullOrEmpty(installationDir)) throw new ArgumentNullException(nameof(installationDir));
            if (commmands == null) throw new ArgumentNullException(nameof(commmands));
            #endregion

            InstallationDir = installationDir;

            // Associate each command with its command-line
            foreach (var command in commmands)
            {
                string path = Path.Combine(installationDir, command.Path.Replace('/', Path.DirectorySeparatorChar));
                string arguments = command.Arguments.Select(arg => arg.ToString()).JoinEscapeArguments();

                _commmands.Add(GetCommandTuple(installationDir, command, escapePath: true));

                // Only add a version without escaping if it causes no ambiguities
                if (!path.ContainsWhitespace() || string.IsNullOrEmpty(arguments))
                    _commmands.Add(GetCommandTuple(installationDir, command, escapePath: false));
            }

            // Sort backwards to make sure the most specific matches are selected first
            _commmands.Sort((tuple1, tuple2) => string.CompareOrdinal(tuple2.CommandLine, tuple1.CommandLine));
        }