Esempio n. 1
0
        /// <summary>
        /// Main entrypoint for the download program.
        /// </summary>
        /// <param name="args">parameters passed in from the user</param>
        static async Task Main(string[] args)
        {
            var downloadTool = new DownloadTool();

            Logger.Info($"Microsoft OSS Gadget - {TOOL_NAME} {VERSION}");

            downloadTool.ParseOptions(args);

            if (((IList <string>)downloadTool.Options["target"]).Count > 0)
            {
                foreach (var target in (IList <string>)downloadTool.Options["target"])
                {
                    try
                    {
                        var purl = new PackageURL(target);
                        foreach (var downloadPath in await downloadTool.Download(purl))
                        {
                            if (string.IsNullOrEmpty(downloadPath))
                            {
                                Logger.Error("Unable to download {0}.", purl.ToString());
                            }
                            else
                            {
                                Logger.Info("Downloaded {0} to {1}", purl.ToString(), downloadPath);
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                        Logger.Warn(ex, "Error processing {0}: {1}", target, ex.Message);
                        Logger.Warn(ex.StackTrace);
                    }
                }
            }
            else
            {
                Logger.Warn("No target provided; nothing to download.");
                DownloadTool.ShowUsage();
                Environment.Exit(1);
            }
        }
Esempio n. 2
0
        /// <summary>
        ///     Main entrypoint for the download program.
        /// </summary>
        /// <param name="args"> parameters passed in from the user </param>
        static async Task <int> Main(string[] args)
        {
            ShowToolBanner();

            DownloadTool?          downloadTool = new DownloadTool();
            ParserResult <Options>?opts         = downloadTool.ParseOptions <Options>(args);

            if (opts.Value is null)
            {
                if (opts.Errors.All(x => x.Tag == ErrorType.HelpRequestedError))
                {
                    return((int)ErrorCode.Ok);
                }
                else
                {
                    return((int)ErrorCode.ErrorParsingOptions);
                }
            }
            else
            {
                return((int)(await downloadTool.RunAsync(opts.Value)));
            }
        }
Esempio n. 3
0
 /// <summary>
 ///     Main entrypoint for the download program.
 /// </summary>
 /// <param name="args"> parameters passed in from the user </param>
 private static async Task Main(string[] args)
 {
     var downloadTool = new DownloadTool();
     await downloadTool.ParseOptions <Options>(args).WithParsedAsync(downloadTool.RunAsync);
 }