Exemplo n.º 1
0
 internal static void WriteRenameCommand(RenameCommandOptions options)
 {
     WriteOption("ask", options.AskMode == AskMode.File);
     WriteOption("attributes", options.Attributes);
     WriteOption("attributes to skip", options.AttributesToSkip);
     WriteOption("conflict resolution", options.ConflictResolution);
     WriteFilter("content filter", options.ContentFilter);
     WriteEncoding("default encoding", options.DefaultEncoding);
     WriteFilter("directory filter", options.DirectoryFilter, options.DirectoryNamePart);
     WriteDisplayFormat("display", options.Format);
     WriteOption("dry run", options.DryRun);
     WriteOption("empty", options.EmptyOption);
     WriteEvaluator("evaluator", options.ReplaceOptions.MatchEvaluator);
     WriteFilter("extension filter", options.ExtensionFilter);
     WriteFilePropertyFilter(
         "file properties",
         options.SizePredicate,
         options.CreationTimePredicate,
         options.ModifiedTimePredicate);
     WriteOption("highlight options", options.HighlightOptions);
     WriteOption("interactive", options.Interactive);
     WriteOption("max matching files", options.MaxMatchingFiles);
     WriteReplaceModify("modify", options.ReplaceOptions);
     WriteFilter("name filter", options.NameFilter, options.NamePart);
     WritePaths("paths", options.Paths);
     WriteOption("progress", options.Progress);
     WriteOption("recurse subdirectories", options.RecurseSubdirectories);
     WriteOption("replacement", options.ReplaceOptions.Replacement);
     WriteOption("search target", options.SearchTarget);
     WriteSortOptions("sort", options.SortOptions);
 }
Exemplo n.º 2
0
        private static int Rename(RenameCommandLineOptions commandLineOptions)
        {
            var options = new RenameCommandOptions();

            if (!commandLineOptions.TryParse(options))
            {
                return(2);
            }

            return(Execute(new RenameCommand(options)));
        }
Exemplo n.º 3
0
        public bool TryParse(RenameCommandOptions options)
        {
            var baseOptions = (DeleteOrRenameCommandOptions)options;

            if (!TryParse(baseOptions))
            {
                return(false);
            }

            options = (RenameCommandOptions)baseOptions;

            if (!TryParseHighlightOptions(
                    Highlight,
                    out HighlightOptions highlightOptions,
                    defaultValue: HighlightOptions.Replacement,
                    provider: OptionValueProviders.RenameHighlightOptionsProvider))
            {
                return(false);
            }

            if (!FilterParser.TryParse(
                    Name,
                    OptionNames.Name,
                    OptionValueProviders.PatternOptionsWithoutGroupAndNegativeProvider,
                    out Filter? nameFilter,
                    out FileNamePart namePart,
                    namePartProvider: OptionValueProviders.NamePartKindProvider_WithoutFullName))
            {
                return(false);
            }

            if (!FilterParser.TryParse(
                    Content,
                    OptionNames.Content,
                    OptionValueProviders.PatternOptionsWithoutPartProvider,
                    out Filter? contentFilter,
                    allowNull: true))
            {
                return(false);
            }

            if (!TryParseReplacement(Replacement, out string?replacement, out MatchEvaluator? matchEvaluator))
            {
                return(false);
            }

            if (matchEvaluator == null &&
                Evaluator != null)
            {
                LogHelpers.WriteObsoleteWarning(
                    $"Option '{OptionNames.GetHelpText(OptionNames.Evaluator)}' is obsolete. "
                    + $"Use option '{OptionNames.GetHelpText(OptionNames.Replacement)}' instead.");

                if (!DelegateFactory.TryCreateFromAssembly(Evaluator, typeof(string), typeof(Match), out matchEvaluator))
                {
                    return(false);
                }
            }

            if (!TryParseReplaceOptions(
                    Modify,
                    OptionNames.Modify,
                    replacement,
                    matchEvaluator,
                    out ReplaceOptions? replaceOptions))
            {
                return(false);
            }

            if (!TryParseAsEnum(
                    Conflict,
                    OptionNames.Conflict,
                    out ConflictResolution conflictResolution,
                    defaultValue: ConflictResolution.Ask,
                    provider: OptionValueProviders.ConflictResolutionProvider_WithoutSuffix))
            {
                return(false);
            }

            if (!TryParseDisplay(
                    values: Display,
                    optionName: OptionNames.Display,
                    contentDisplayStyle: out ContentDisplayStyle? contentDisplayStyle,
                    pathDisplayStyle: out PathDisplayStyle? pathDisplayStyle,
                    lineDisplayOptions: out LineDisplayOptions lineDisplayOptions,
                    lineContext: out LineContext lineContext,
                    displayParts: out DisplayParts displayParts,
                    fileProperties: out ImmutableArray <FileProperty> fileProperties,
                    indent: out string?indent,
                    separator: out string?separator,
                    noAlign: out bool noAlign,
                    contentDisplayStyleProvider: OptionValueProviders.ContentDisplayStyleProvider,
                    pathDisplayStyleProvider: OptionValueProviders.PathDisplayStyleProvider_Rename))
            {
                return(false);
            }

            if (pathDisplayStyle == PathDisplayStyle.Relative &&
                options.Paths.Length > 1 &&
                options.SortOptions != null)
            {
                pathDisplayStyle = PathDisplayStyle.Full;
            }

            options.Format = new OutputDisplayFormat(
                contentDisplayStyle: contentDisplayStyle ?? ContentDisplayStyle.Omit,
                pathDisplayStyle: pathDisplayStyle ?? PathDisplayStyle.Full,
                lineOptions: lineDisplayOptions,
                lineContext: lineContext,
                displayParts: displayParts,
                fileProperties: fileProperties,
                indent: indent,
                separator: separator,
                alignColumns: !noAlign);

            options.HighlightOptions   = highlightOptions;
            options.SearchTarget       = GetSearchTarget();
            options.ReplaceOptions     = replaceOptions;
            options.AskMode            = (Ask) ? AskMode.File : AskMode.None;
            options.DryRun             = DryRun;
            options.NameFilter         = nameFilter;
            options.NamePart           = namePart;
            options.ContentFilter      = contentFilter;
            options.MaxMatchingFiles   = MaxCount;
            options.ConflictResolution = conflictResolution;
            options.Interactive        = Interactive;

            return(true);
        }
Exemplo n.º 4
0
        public bool TryParse(RenameCommandOptions options)
        {
            var baseOptions = (DeleteOrRenameCommandOptions)options;

            if (!TryParse(baseOptions))
            {
                return(false);
            }

            options = (RenameCommandOptions)baseOptions;

            if (!TryParseAsEnumFlags(Highlight, OptionNames.Highlight, out HighlightOptions highlightOptions, defaultValue: HighlightOptions.Replacement, provider: OptionValueProviders.RenameHighlightOptionsProvider))
            {
                return(false);
            }

            if (!FilterParser.TryParse(Name, OptionNames.Name, OptionValueProviders.PatternOptionsWithoutGroupAndNegativeProvider, out Filter? nameFilter, out FileNamePart namePart, namePartProvider: OptionValueProviders.NamePartKindProvider_WithoutFullName))
            {
                return(false);
            }

            if (!FilterParser.TryParse(Content, OptionNames.Content, OptionValueProviders.PatternOptionsWithoutPartProvider, out Filter? contentFilter, allowNull: true))
            {
                return(false);
            }

            if (!TryParseReplacement(Replacement, out string?replacement))
            {
                return(false);
            }

            if (!DelegateFactory.TryCreateMatchEvaluator(Evaluator, out MatchEvaluator? matchEvaluator))
            {
                return(false);
            }

            if (replacement != null && matchEvaluator != null)
            {
                WriteError($"Options '{OptionNames.GetHelpText(OptionNames.Replacement)}' and '{OptionNames.GetHelpText(OptionNames.Evaluator)}' cannot be set both at the same time.");
                return(false);
            }

            if (!TryParseReplaceOptions(Modify, OptionNames.Modify, replacement, matchEvaluator, out ReplaceOptions? replaceOptions))
            {
                return(false);
            }

            if (!TryParseAsEnum(Conflict, OptionNames.Conflict, out ConflictResolution conflictResolution, defaultValue: ConflictResolution.Ask, provider: OptionValueProviders.ConflictResolutionProvider_WithoutSuffix))
            {
                return(false);
            }

            if (!TryParseDisplay(
                    values: Display,
                    optionName: OptionNames.Display,
                    contentDisplayStyle: out ContentDisplayStyle? _,
                    pathDisplayStyle: out PathDisplayStyle? pathDisplayStyle,
                    lineDisplayOptions: out LineDisplayOptions lineDisplayOptions,
                    lineContext: out LineContext lineContext,
                    displayParts: out DisplayParts displayParts,
                    fileProperties: out ImmutableArray <FileProperty> fileProperties,
                    indent: out string?indent,
                    separator: out string?separator,
                    contentDisplayStyleProvider: OptionValueProviders.ContentDisplayStyleProvider,
                    pathDisplayStyleProvider: OptionValueProviders.PathDisplayStyleProvider_Rename))
            {
                return(false);
            }

            if (pathDisplayStyle == PathDisplayStyle.Relative &&
                options.Paths.Length > 1 &&
                options.SortOptions != null)
            {
                pathDisplayStyle = PathDisplayStyle.Full;
            }

            options.Format = new OutputDisplayFormat(
                contentDisplayStyle: ContentDisplayStyle.None,
                pathDisplayStyle: pathDisplayStyle ?? PathDisplayStyle.Full,
                lineOptions: lineDisplayOptions,
                lineContext: lineContext,
                displayParts: displayParts,
                fileProperties: fileProperties,
                indent: indent,
                separator: separator);

            options.HighlightOptions = highlightOptions;
            options.SearchTarget     = GetSearchTarget();
            options.ReplaceOptions   = replaceOptions;
            options.Ask                = Ask;
            options.DryRun             = DryRun;
            options.NameFilter         = nameFilter;
            options.NamePart           = namePart;
            options.ContentFilter      = contentFilter;
            options.MaxMatchingFiles   = MaxCount;
            options.ConflictResolution = conflictResolution;

            return(true);
        }