Example #1
0
        async Task<int> main(string[] args)
        {
            using (var logger = new SetupLogLogger(false) { Level = Splat.LogLevel.Info })
            {
                Splat.Locator.CurrentMutable.Register(() => logger, typeof(Splat.ILogger));

                var releaseDir = default(string);
                var repoUrl = default(string);
                var token = default(string);

                opts = new OptionSet() {
                    "Usage: SyncReleases.exe command [OPTS]",
                    "Builds a Releases directory from releases on GitHub",
                    "",
                    "Options:",
                    { "h|?|help", "Display Help and exit", _ => {} },
                    { "r=|releaseDir=", "Path to a release directory to download to", v => releaseDir = v},
                    { "u=|url=", "When pointing to GitHub, use the URL to the repository root page, else point to an existing remote Releases folder", v => repoUrl = v},
                    { "t=|token=", "The OAuth token to use as login credentials", v => token = v},
                };

                opts.Parse(args);

                if (repoUrl == null || repoUrl.StartsWith("http", true, CultureInfo.InvariantCulture) == false)
                {
                    ShowHelp();
                    return -1;
                }

                var releaseDirectoryInfo = new DirectoryInfo(releaseDir ?? Path.Combine(".", "Releases"));
                if (!releaseDirectoryInfo.Exists) releaseDirectoryInfo.Create();

                var githubException = default(Exception);
                try
                {
                    Console.Out.WriteLine("Attemping to sync URL as github-releases");
                    await SyncImplementations.SyncFromGitHub(repoUrl, token, releaseDirectoryInfo);
                    return 0;
                }
                catch (Exception ex)
                {
                    Console.Out.WriteLine("Failed to sync URL as github-releases");
                    githubException = ex;
                }

                try
                {
                    Console.Out.WriteLine("Attemping to sync URL as remote RELEASES folder");
                    await SyncImplementations.SyncRemoteReleases(new Uri(repoUrl), releaseDirectoryInfo);
                    return 0;
                }
                catch (Exception)
                {

                    Console.Error.WriteLine("Failed to sync URL as remote RELEASES folder: " + githubException.Message);
                    throw;
                }
            }
        }
        async Task <int> main(string[] args)
        {
            using (var logger = new SetupLogLogger(false)
            {
                Level = Squirrel.SimpleSplat.LogLevel.Info
            }) {
                Squirrel.SimpleSplat.Locator.CurrentMutable.Register(() => logger, typeof(Squirrel.SimpleSplat.ILogger));

                var releaseDir = default(string);
                var repoUrl    = default(string);
                var token      = default(string);

                opts = new OptionSet()
                {
                    "Usage: SyncReleases.exe command [OPTS]",
                    "Builds a Releases directory from releases on GitHub",
                    "",
                    "Options:",
                    { "h|?|help", "Display Help and exit", _ => {} },
                    { "r=|releaseDir=", "Path to a release directory to download to", v => releaseDir = v },
                    { "u=|url=", "When pointing to GitHub, use the URL to the repository root page, else point to an existing remote Releases folder", v => repoUrl = v },
                    { "t=|token=", "The OAuth token to use as login credentials", v => token = v },
                };

                opts.Parse(args);

                if (repoUrl == null || repoUrl.StartsWith("http", true, CultureInfo.InvariantCulture) == false)
                {
                    ShowHelp();
                    return(-1);
                }

                var releaseDirectoryInfo = new DirectoryInfo(releaseDir ?? Path.Combine(".", "Releases"));
                if (!releaseDirectoryInfo.Exists)
                {
                    releaseDirectoryInfo.Create();
                }

                var githubException = default(Exception);
                try {
                    await SyncImplementations.SyncFromGitHub(repoUrl, token, releaseDirectoryInfo);

                    return(0);
                } catch (Exception ex) {
                    githubException = ex;
                    Console.Error.WriteLine("Attempting to sync URL as remote RELEASES folder");
                }

                try {
                    await SyncImplementations.SyncRemoteReleases(new Uri(repoUrl), releaseDirectoryInfo);
                } catch (Exception) {
                    Console.Error.WriteLine("Failed to sync URL as GitHub repo: " + githubException.Message);
                    throw;
                }
            }

            return(0);
        }