Ejemplo n.º 1
0
        public static CommandResult ListCommand(CommandLineProto proto, CommandLine args)
        {
            var app = ConsoleApp.Instance;

            try
            {
                PathFolderOptions options = GetPathFolderOptions(args);
                PathFolders       folders = new PathFolders(options);
                folders.Fill();
                var    f0      = folders.ToArray();
                string pattern = args.GetResolvedValue <string>(Names.FilterSwitch, Names.FilterMnemonic);
                if (pattern != null)
                {
                    Regex r = new Regex(pattern);
                    f0 = (from f in f0 where r.IsMatch(f.Path) select f).ToArray();
                }
                if (args.HasSwitch(Names.SortSwitch))
                {
                    Array.Sort(f0);
                }
                folders = new PathFolders(f0);
                bool isVerbose = args.HasSwitch(Names.VerboseSwitch, Names.VerboseMnemonic);
                bool isInline  = args.HasSwitch(Names.InlineSwitch, Names.InlineMnemonic);
                if (isVerbose && isInline)
                {
                    return(new CommandResult(false, "--Verbose and --Inline are incompatible options"));
                }
                if (!isInline)
                {
                    app.WriteOut(isVerbose ? folders.ToVerboseString() : folders.ToString());
                }
                else
                {
                    app.WriteOut(folders.ToInlineString());
                }
                return(new CommandResult());
            }
            catch (Exception ex)
            {
                return(new CommandResult(false, "Unable to list PATH elements", ex));
            }
        }