public ICommand CreateCommand(string[] args) { var hashes = new List<Func<IHashCodeProvider>>(); var decorators = new List<IStreamDecorator>(); IRememberHashCodes history = null; _options.Update<string>(Args.Name, v => hashes.Add(() => new FileNameHashCodeProvider())); _options.Update<string>(Args.Size, v => hashes.Add(() => new FileSizeHashCodeProvider(_fileSystem))); _options.Update<string>(Args.Content, v => hashes.Add(() => new FileContentHashCodeProvider(_fileSystem, decorators.ToArray()))); _options.Update(Args.Head, (long v) => decorators.Add(new HeadStreamDecorator(v))); _options.Update(Args.Tail, (long v) => decorators.Add(new TailStreamDecorator(v))); _options.Update<string>(Args.History, v => history = new DatabaseHistory(v, _fileSystem)); var directories = _options.Parse(args); var messages = Missing(hashes, "The comparison type is missing") .Union(Missing(directories, "No directories to compare")) .Union(Missing(history, "No history file was specified")); if (messages.Any()) { throw new CommandLineParserException(messages); } var finder = new DuplicateFinder(directories.Select(x => (IFileFinder) new RecursiveFileFinder(_fileSystem, x)), hashes.Select(x => x()), _output, new NullHistory()); return new PruneHistoryCommand(_output, finder, history); }
public ICommand CreateCommand(string[] args) { var hashes = new List<Func<IHashCodeProvider>>(); var decorators = new List<IStreamDecorator>(); var deletionSelector = (ISelectFilesToDelete) new AllButFirstDuplicateSelector(); var deleter = (IFileDeleter) new FileDeleter(_fileSystem, _output); var history = (IRememberHashCodes) new NullHistory(); var applyWhatIf = new Action(() => { }); _options.Update<string>(Args.Name, v => hashes.Add(() => new FileNameHashCodeProvider())); _options.Update<string>(Args.Size, v => hashes.Add(() => new FileSizeHashCodeProvider(_fileSystem))); _options.Update<string>(Args.Content, v => hashes.Add(() => new FileContentHashCodeProvider(_fileSystem, decorators.ToArray()))); _options.Update(Args.Head, (long v) => decorators.Add(new HeadStreamDecorator(v))); _options.Update(Args.Tail, (long v) => decorators.Add(new TailStreamDecorator(v))); _options.Update<string>(Args.Keep, v => deletionSelector = new KeepOneCopyInDirectorySelector(v)); _options.Update<string>(Args.History, v => history = new DatabaseHistory(v, _fileSystem)); _options.Update<string>(Args.WhatIf, _ => { applyWhatIf = () => { deleter = new WhatIfFileDeleter(_output); if (history != null) { history = new ReadOnlyHistory(history); } }; }); var directories = _options.Parse(args); applyWhatIf(); var messages = Missing(hashes, "The comparison type is missing") .Union(Missing(directories, "No directories to compare")); if (messages.Any()) { throw new CommandLineParserException(messages); } var finder = new DuplicateFinder(directories.Select(x => (IFileFinder) new RecursiveFileFinder(_fileSystem, x)), hashes.Select(x => x()), _output, history, new TaskbarProgress()); return new FindDuplicatesCommand(_output, finder, deletionSelector, deleter); }