コード例 #1
0
ファイル: WebDAVCommand.cs プロジェクト: ralgh/sfcc-tools
        private void LsCommandHandler(CommandLineApplication lsCmd)
        {
            lsCmd.Description = "List directory";
            var sortByTime = lsCmd.Option("-t", "Sort by modified time", CommandOptionType.NoValue);
            var filter     = lsCmd.Argument("filter", "Regular expression to filter by");

            lsCmd.OnExecuteAsync(async token =>
            {
                var contents = await _client.ListDirectory(_location, _workingDirectory.AbsolutePath);

                if (!string.IsNullOrEmpty(filter.Value))
                {
                    var filterRegex = new Regex(filter.Value);
                    contents        = contents.Where(f => filterRegex.IsMatch(f.Filename)).ToList();
                }

                contents = sortByTime.HasValue()
                    ? contents.OrderByDescending(f => f.LastModifiedDate).ToList()
                    : contents.OrderBy(f => f.Filename).ToList();

                foreach (var file in contents)
                {
                    _console.Write($"{file.LastModifiedDate:s}\t");
                    _console.Write($"{file.Length,10}\t");
                    if (file.IsDirectory)
                    {
                        _console.Blue($"{file.Filename}");
                    }
                    else
                    {
                        _console.WriteLine($"{file.Filename}");
                    }
                }

                return(0);
            });
        }