示例#1
0
        internal string Parse()
        {
            var options = new StringBuilder();

            #region Set Options

            if (OnlyCopyArchiveFiles)
            {
                options.Append(ONLY_COPY_ARCHIVE_FILES);
            }
            if (OnlyCopyArchiveFilesAndResetArchiveFlag)
            {
                options.Append(ONLY_COPY_ARCHIVE_FILES_AND_RESET_ARCHIVE_FLAG);
            }
            if (!IncludeAttributes.IsNullOrWhiteSpace())
            {
                options.Append(string.Format(INCLUDE_ATTRIBUTES, IncludeAttributes.CleanOptionInput()));
            }
            if (!ExcludeAttributes.IsNullOrWhiteSpace())
            {
                options.Append(string.Format(EXCLUDE_ATTRIBUTES, ExcludeAttributes.CleanOptionInput()));
            }
            if (!ExcludeFiles.IsNullOrWhiteSpace())
            {
                options.Append(string.Format(EXCLUDE_FILES, ExcludeFiles));
            }
            if (!ExcludeDirectories.IsNullOrWhiteSpace())
            {
                options.Append(string.Format(EXCLUDE_DIRECTORIES, ExcludeDirectories));
            }
            if (ExcludeChanged)
            {
                options.Append(EXCLUDE_CHANGED);
            }
            if (ExcludeNewer)
            {
                options.Append(EXCLUDE_NEWER);
            }
            if (ExcludeOlder)
            {
                options.Append(EXCLUDE_OLDER);
            }
            if (ExcludeExtra)
            {
                options.Append(EXCLUDE_EXTRA);
            }
            if (ExcludeLonely)
            {
                options.Append(EXCLUDE_LONELY);
            }
            if (IncludeSame)
            {
                options.Append(INCLUDE_SAME);
            }
            if (IncludeTweaked)
            {
                options.Append(INCLUDE_TWEAKED);
            }
            if (MaxFileSize > 0)
            {
                options.Append(string.Format(MAX_FILE_SIZE, MaxFileSize));
            }
            if (MinFileSize > 0)
            {
                options.Append(string.Format(MIN_FILE_SIZE, MinFileSize));
            }
            if (!MaxFileAge.IsNullOrWhiteSpace())
            {
                options.Append(string.Format(MAX_FILE_AGE, MaxFileAge.CleanOptionInput()));
            }
            if (!MinFileAge.IsNullOrWhiteSpace())
            {
                options.Append(string.Format(MIN_FILE_AGE, MinFileAge.CleanOptionInput()));
            }
            if (!MaxLastAccessDate.IsNullOrWhiteSpace())
            {
                options.Append(string.Format(MAX_LAST_ACCESS_DATE, MaxLastAccessDate.CleanOptionInput()));
            }
            if (!MinLastAccessDate.IsNullOrWhiteSpace())
            {
                options.Append(string.Format(MIN_LAST_ACCESS_DATE, MinLastAccessDate.CleanOptionInput()));
            }
            if (ExcludeJunctionPoints)
            {
                options.Append(EXCLUDE_JUNCTION_POINTS);
            }
            if (ExcludeJunctionPointsForDirectories)
            {
                options.Append(EXCLUDE_JUNCTION_POINTS_FOR_DIRECTORIES);
            }
            if (ExcludeJunctionPointsForFiles)
            {
                options.Append(EXCLUDE_JUNCTION_POINTS_FOR_FILES);
            }
            if (UseFatFileTimes)
            {
                options.Append(USE_FAT_FILE_TIMES);
            }
            if (CompensateForDstDifference)
            {
                options.Append(COMPENSATE_FOR_DST_DIFFERENCE);
            }

            #endregion Set Options

            return(options.ToString());
        }
示例#2
0
        static void EvaluateArguments(string[] args)
        {
            // BucketName=nantokakantokabucket
            BucketName = args.Where(x => x.StartsWith(ArgumentType.BucketName.ToString(), StringComparison.InvariantCultureIgnoreCase))
                         .SelectMany(x => x.SplitEx("="))
                         .LastOrDefault()
                         ?? GetEnvValueString(ArgumentType.BucketName, EnvType.S3Sync_BucketName);

            // LocalRoot=c:\hogemoge
            LocalRoot = args.Where(x => x.StartsWith(ArgumentType.LocalRoot.ToString(), StringComparison.InvariantCultureIgnoreCase))
                        .SelectMany(x => x.SplitEx("="))
                        .LastOrDefault()
                        ?? GetEnvValueString(ArgumentType.LocalRoot, EnvType.S3Sync_LocalRoot);

            // KeyPrefix=image
            KeyPrefix = args.Where(x => x.StartsWith(ArgumentType.KeyPrefix.ToString(), StringComparison.InvariantCultureIgnoreCase))
                        .SelectMany(x => x.SplitEx("="))
                        .LastOrDefault()
                        ?.TrimEnd('/')
                        ?? GetEnvValueString(ArgumentType.KeyPrefix, EnvType.S3Sync_KeyPrefix);

            // IgnoreKeyPrefix=image
            IgnoreKeyPrefix = args.Where(x => x.StartsWith(ArgumentType.IgnoreKeyPrefix.ToString(), StringComparison.InvariantCultureIgnoreCase))
                              .SelectMany(x => x.SplitEx("="))
                              .LastOrDefault()
                              ?.TrimEnd('/')
                              ?? GetEnvValueString(ArgumentType.IgnoreKeyPrefix, EnvType.S3Sync_IgnoreKeyPrefix);

            // ExcludeFiles=hogemoge,fugafuga
            ExcludeFiles = args.Where(x => x.StartsWith(ArgumentType.ExcludeFiles.ToString(), StringComparison.InvariantCultureIgnoreCase))
                           .SelectMany(x => x.SplitEx("="))
                           .LastOrDefault()
                           ?.SplitEx(",")
                           .Select(x => x.Trim())
                           .ToArray()
                           ?? GetEnvValueString(ArgumentType.ExcludeFiles, EnvType.S3Sync_ExcludeFiles)
                           ?.SplitEx(",");

            // ExcludeDirectories=hogemoge,fugafuga
            ExcludeDirectories = args.Where(x => x.StartsWith(ArgumentType.ExcludeDirectories.ToString(), StringComparison.InvariantCultureIgnoreCase))
                                 .SelectMany(x => x.SplitEx("="))
                                 .LastOrDefault()
                                 ?.SplitEx(",")
                                 ?.Select(x => x.Trim())
                                 .ToArray()
                                 ?? GetEnvValueString(ArgumentType.ExcludeDirectories, EnvType.S3Sync_ExcludeDirectories)
                                 ?.SplitEx(",");

            // Silent=false
            Silent = bool.Parse(args.Where(x => x.StartsWith(ArgumentType.Silent.ToString(), StringComparison.InvariantCultureIgnoreCase))
                                .SelectMany(x => x.SplitEx("="))
                                .Where(x => string.Equals(x, "true", StringComparison.InvariantCultureIgnoreCase) || string.Equals(x, "false", StringComparison.InvariantCultureIgnoreCase))
                                .LastOrDefault()
                                ?.Trim()
                                ?? GetEnvValueString(ArgumentType.Silent, EnvType.S3Sync_Silent)
                                ?? "false");

            // CredentialProfile=ProfileName
            CredentialProfile = args.Where(x => x.StartsWith(ArgumentType.CredentialProfile.ToString(), StringComparison.InvariantCultureIgnoreCase))
                                .SelectMany(x => x.SplitEx("="))
                                .LastOrDefault()
                                ?.Trim()
                                ?? GetEnvValueString(ArgumentType.CredentialProfile, EnvType.S3Sync_CredentialProfile);

            // DryRun=true
            Option.DryRun = bool.Parse(args.Where(x => x.StartsWith(ArgumentType.DryRun.ToString(), StringComparison.InvariantCultureIgnoreCase))
                                       .SelectMany(x => x.SplitEx("="))
                                       .Where(x => string.Equals(x, "true", StringComparison.InvariantCultureIgnoreCase) || string.Equals(x, "false", StringComparison.InvariantCultureIgnoreCase))
                                       .LastOrDefault()
                                       ?.Trim()
                                       ?? GetEnvValueString(ArgumentType.DryRun, EnvType.S3Sync_DryRun)
                                       ?? "true");

            // ContentType=application/json
            Option.ContentType = args.Where(x => x.StartsWith(ArgumentType.ContentType.ToString(), StringComparison.InvariantCultureIgnoreCase))
                                 .SelectMany(x => x.SplitEx("="))
                                 .LastOrDefault()
                                 ?.TrimEnd('/')
                                 ?? GetEnvValueString(ArgumentType.ContentType, EnvType.S3Sync_ContentType);

            // Region=us-east-1
            Option.Region = args.Where(x => x.StartsWith(ArgumentType.Region.ToString(), StringComparison.InvariantCultureIgnoreCase))
                            .SelectMany(x => x.SplitEx("="))
                            .LastOrDefault()
                            ?.TrimEnd('/')
                            ?? GetEnvValueString(ArgumentType.Region, EnvType.S3Sync_Region);

            // Show Arguments
            Log($"{nameof(BucketName)} : {BucketName}");
            Log($"{nameof(LocalRoot)} : {LocalRoot}");
            Log($"{nameof(KeyPrefix)} : {KeyPrefix}");
            Log($"{nameof(IgnoreKeyPrefix)} : {IgnoreKeyPrefix}");
            Log($"{nameof(ExcludeFiles)} : {ExcludeFiles?.ToJoinedString(",")}");
            Log($"{nameof(ExcludeDirectories)} : {ExcludeDirectories?.ToJoinedString(",")}");
            Log($"{nameof(Silent)} : {Silent}");
            Log($"{nameof(CredentialProfile)} : {CredentialProfile}");
            Log($"{nameof(Option.DryRun)} : {Option.DryRun}");
            Log($"{nameof(Option.ContentType)} : {Option.ContentType}");
            Log($"{nameof(Option.Region)} : {Option.Region}");

            // Validate Required arguments
            if (string.IsNullOrWhiteSpace(BucketName))
            {
                Error("Please pass arguments. See detail followings.");
                PrintHelp();
                throw new NullReferenceException(nameof(BucketName));
            }

            if (string.IsNullOrWhiteSpace(LocalRoot))
            {
                Error("Please pass arguments. See detail followings.");
                PrintHelp();
                throw new NullReferenceException(nameof(LocalRoot));
            }
        }