Exemplo n.º 1
0
        static bool IsVisible(IContext context, Sidi.CommandLine.Action a)
        {
            var m = a.MethodInfo;
            var visibilityCondition = m.GetCustomAttributes <VisibilityConditionAttribute>();

            return(visibilityCondition != null && visibilityCondition.All(_ => _.GetIsVisible(context)));
        }
Exemplo n.º 2
0
        static IAction ToIAction(IContext context, Sidi.CommandLine.Action a, string args)
        {
            if (!IsVisible(context, a))
            {
                return(null);
            }

            args = args.Trim();

            return(new SimpleAction(
                       context.LastExecutedStore,
                       a.Name,
                       String.Format("{0} ({2})", DisplayText(a), args, a.Usage),
                       () =>
            {
                if (TakesSingleString(a.MethodInfo))
                {
                    a.Handle(new List <string> {
                        args
                    }, true);
                }
                else
                {
                    a.Handle(Tokenizer.ToList(args), true);
                }
            })
            {
                Icon = _icon
            });
        }
Exemplo n.º 3
0
 static IAction ToIActionPathList(IContext context, Sidi.CommandLine.Action a, PathList arg1, string arg1String = null)
 {
     if (TakesSingleParameter <LPath>(a))
     {
         return(ToIAction <LPath>(context, a, arg1.First(), GetNiceText(arg1)));
     }
     return(ToIAction <PathList>(context, a, arg1, arg1String));
 }
Exemplo n.º 4
0
        static IAction ToIAction <T>(IContext context, Sidi.CommandLine.Action a, T arg1, string arg1String = null)
        {
            if (!IsVisible(context, a))
            {
                return(null);
            }

            if (arg1String == null)
            {
                arg1String = arg1.ToString();
            }

            return(new SimpleAction(
                       context.LastExecutedStore,
                       a.Name,
                       String.Format("{0} argument: {1} ({2})", DisplayText(a), arg1String.OneLine(128), a.Usage),
                       () =>
            {
                a.MethodInfo.Invoke(a.Source.Instance, new object[] { arg1 });
            })
            {
                Icon = _icon
            });
        }
Exemplo n.º 5
0
        static bool TakesSingleParameter <T>(Sidi.CommandLine.Action a)
        {
            var pi = a.MethodInfo.GetParameters();

            return(pi.Length == 1 && pi[0].ParameterType == typeof(T));
        }
Exemplo n.º 6
0
        static string GetMatchText(Sidi.CommandLine.Action a)
        {
            var sourceName = a.Source.Instance.GetType().Name;

            return($"#{sourceName} {a.Name} {a.UsageText}");
        }
Exemplo n.º 7
0
        static string DisplayText(Sidi.CommandLine.Action a)
        {
            var className = a.Source.Instance.GetType().Name;

            return($"#command #{className} {a.Name}");
        }