예제 #1
0
 public Command(ImmutableArray <string> literals,
                string description,
                IArgBinder <IEntryPoint> binder)
 {
     Literals    = literals;
     Binder      = binder;
     Description = description;
 }
예제 #2
0
파일: CommandLine.cs 프로젝트: vokhub/Arqs
        public static Task <int> RunAsync(string[] args, IArgBinder <IEntryPoint> binder)
        {
            var(entryPoint, tail) = binder.Bind(args);
            switch (entryPoint.Mode)
            {
            case EntryPointMode.ShowHelp:
                binder.Describe(Console.Out);
                return(Task.FromResult(0));

            default:
                return(entryPoint.Main(tail));
            }
        }
예제 #3
0
파일: CommandLine.cs 프로젝트: vokhub/Arqs
        public static Task <int> RunAsync(IEnumerable <string> args, IArgBinder <IEntryPoint> @default, params Command[] commands)
        {
            using var arg = args.GetEnumerator();

            if (!arg.MoveNext())
            {
                foreach (var command in commands)
                {
                    Console.WriteLine(string.Join(" ", command.Literals));
                }

                return(Task.FromResult(0));
            }

            var(count, binder) =
                commands.OrderByDescending(cmd => cmd.Literals.Length)
                .Where(cmd => cmd.Literals.SequenceEqual(args.Take(cmd.Literals.Length)))
                .Select(cmd => (cmd.Literals.Length, cmd.Binder))
                .DefaultIfEmpty((0, @default))
                .First();

            return(RunAsync(args.Skip(count).ToArray(), binder));
        }
예제 #4
0
파일: CommandLine.cs 프로젝트: vokhub/Arqs
 Bind <T>(this IArgBinder <T> binder, params string[] args) =>
예제 #5
0
파일: CommandLine.cs 프로젝트: vokhub/Arqs
 public static int Run(IEnumerable <string> args, IArgBinder <IEntryPoint> @default, params Command[] commands) =>
 RunAsync(args, @default, commands).GetAwaiter().GetResult();
예제 #6
0
파일: CommandLine.cs 프로젝트: vokhub/Arqs
 public static Command Command(string name, IArgBinder <IEntryPoint> binder) =>
 new Command(ImmutableArray.Create(name.Split((char[])null, StringSplitOptions.RemoveEmptyEntries)), null, binder);
예제 #7
0
파일: CommandLine.cs 프로젝트: vokhub/Arqs
 public static int Run(string[] args, IArgBinder <IEntryPoint> binder) =>
 RunAsync(args, binder).GetAwaiter().GetResult();
예제 #8
0
파일: ArgBinder.cs 프로젝트: vokhub/Arqs
 public static IArgBinder <(T, U)> Zip <T, U>(this IArgBinder <T> first, IArgBinder <U> second) =>