Example #1
0
        public UsageGraph(string appName, Type commandType)
        {
            _appName = appName;
            _commandType = commandType;
            _inputType = commandType.FindInterfaceThatCloses(typeof (IFubuCommand<>)).GetGenericArguments().First();

            _commandName = CommandFactory.CommandNameFor(commandType);
            _commandType.ForAttribute<CommandDescriptionAttribute>(att => { _description = att.Description; });

            if (_description == null) _description = _commandType.Name;

            _handlers = InputParser.GetHandlers(_inputType);

            _commandType.ForAttribute<UsageAttribute>(att =>
            {
                _usages.Add(buildUsage(att));
            });

            if (!_usages.Any())
            {
                var usage = new CommandUsage()
                {
                    AppName = _appName,
                    CommandName = _commandName,
                    UsageKey = "default",
                    Description = _description,
                    Arguments = _handlers.OfType<Argument>(),
                    ValidFlags = _handlers.Where(x => !(x is Argument))
                };

                _usages.Add(usage);
            }
        }
Example #2
0
            public UsageExpression(UsageGraph parent, string description)
            {
                _parent = parent;

                _commandUsage = new CommandUsage
                {
                    Description = description,
                    Arguments   = new Argument[0],
                    ValidFlags  = _parent.Handlers.Where(x => !x.GetType().CanBeCastTo <Argument>()).ToArray() // Hokum.
                };

                _parent._usages.Add(_commandUsage);
            }
Example #3
0
        public UsageGraph(string appName, Type commandType)
        {
            _appName     = appName;
            _commandType = commandType;
            _inputType   = commandType.FindInterfaceThatCloses(typeof(IFubuCommand <>)).GetGenericArguments().First();

            _commandName = CommandFactory.CommandNameFor(commandType);
            _commandType.ForAttribute <CommandDescriptionAttribute>(att => { _description = att.Description; });

            if (_description == null)
            {
                _description = _commandType.Name;
            }

            _handlers = InputParser.GetHandlers(_inputType);

            _commandType.ForAttribute <UsageAttribute>(att =>
            {
                _usages.Add(buildUsage(att));
            });

            if (!_usages.Any())
            {
                var usage = new CommandUsage()
                {
                    AppName     = _appName,
                    CommandName = _commandName,
                    UsageKey    = "default",
                    Description = _description,
                    Arguments   = _handlers.OfType <Argument>(),
                    ValidFlags  = _handlers.Where(x => !(x is Argument))
                };

                _usages.Add(usage);
            }
        }