Example #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)));
        }
Example #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
            });
        }
Example #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));
 }
Example #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
            });
        }
Example #5
0
        static bool TakesSingleParameter <T>(Sidi.CommandLine.Action a)
        {
            var pi = a.MethodInfo.GetParameters();

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

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

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