public CommandContext(ICommandExecutor executor, CommandLine commandLine, CommandTreeNode commandNode, object parameter, IDictionary <string, object> items = null) : base(executor, commandNode, parameter, items)
        {
            _commandLine = commandLine;

            if (commandLine == null)
            {
                _options = new CommandOptionCollection(this.Command);
            }
            else
            {
                _options = new CommandOptionCollection(this.Command, (System.Collections.IDictionary)commandLine.Options);
            }
        }
示例#2
0
        public CommandExpression(Zongsoft.IO.PathAnchor anchor, string name, string path, IDictionary <string, string> options, params string[] arguments)
        {
            if (string.IsNullOrWhiteSpace(name))
            {
                throw new ArgumentNullException(nameof(name));
            }

            //修缮传入的路径参数值
            path = path.Trim('/', ' ', '\t', '\r', '\n');

            _anchor = anchor;
            _name   = name.Trim();

            switch (anchor)
            {
            case IO.PathAnchor.Root:
                if (string.IsNullOrEmpty(path))
                {
                    _path = "/";
                }
                else
                {
                    _path = "/" + path + "/";
                }
                break;

            case IO.PathAnchor.Current:
                if (string.IsNullOrEmpty(path))
                {
                    _path = "./";
                }
                else
                {
                    _path = "./" + path + "/";
                }
                break;

            case IO.PathAnchor.Parent:
                if (string.IsNullOrEmpty(path))
                {
                    _path = "../";
                }
                else
                {
                    _path = "../" + path + "/";
                }
                break;

            default:
                if (string.IsNullOrEmpty(path))
                {
                    _path = string.Empty;
                }
                else
                {
                    _path = path + "/";
                }
                break;
            }

            _fullPath = _path + _name;

            if (options == null || options.Count == 0)
            {
                _options = new CommandOptionCollection();
            }
            else
            {
                _options = new CommandOptionCollection(options);
            }

            _arguments = arguments ?? new string[0];
        }