public override void Setup(CommandLineApplication command)
        {
            base.Setup(command);

            var optionReportJsonPath = command.Option <string>(
                "-rp|--jsonReportPath",
                "path to where the json report should be written",
                CommandOptionType.SingleValue);

            var optionCacheFolderPath = command.Option <string>(
                "-cf|--cacheFolderPath",
                $"directory path to where the local cache will be. Default path: '{_remoteFile.CacheFolderpath}'",
                CommandOptionType.SingleValue);

            //default: 'template','templates', 'ServiceStack.Core.Templates', 'BlackFox.DotnetNew.FSharpTemplates','libyear','libyear',
            //'angular-cli.dotnet','Carna.ProjectTemplates','SerialSeb.Templates.ClassLibrary','Pioneer.Console.Boilerplate'
            var optionSearchTerms = command.Option <string>(
                "-st|--searchTerm",
                "term to search on nuget. This option may be provided multiple times. If not provided the default set of values will be used.",
                CommandOptionType.MultipleValue);

            // optionSearchTerms.IsRequired(allowEmptyStrings: false, errorMessage: "you must specify a search term with -st|--searchTerm");

            OnExecute = () => {
                EnableVerboseOption = OptionVerbose.HasValue();

                var report = new TemplateReport(_nugetHelper, _httpClient, _nugetPkgDownloader, _remoteFile);

                var searchTerms = GetDefaultSearchTerms();
                if (optionSearchTerms.HasValue())
                {
                    searchTerms = optionSearchTerms.Values.ToArray();
                }

                var templateReportPath = Path.Combine(Directory.GetCurrentDirectory(), "template-report.json");
                if (optionReportJsonPath.HasValue())
                {
                    templateReportPath = optionReportJsonPath.Value();
                }

                report.GenerateTemplateJsonReportAsync(searchTerms, templateReportPath).Wait();

                return(1);
            };
        }
        public override void Setup(CommandLineApplication command)
        {
            base.Setup(command);

            var optionTemplateReportJsonPath = command.Option <string>(
                "-trp|--templateReportPath",
                "the path to the template-report.json file",
                CommandOptionType.SingleValue);

            optionTemplateReportJsonPath.IsRequired();

            //var optionAnalysisResultFilePath = command.Option<string>(
            //    "-arp|--analysisResultPath",
            //    "path to where the results will be written to",
            //    CommandOptionType.SingleValue);

            var optionOutputDir = command.Option <string>(
                "-od|--output-dir",
                "folder path where files will be written",
                CommandOptionType.SingleValue);

            OnExecute = () => {
                EnableVerboseOption = OptionVerbose.HasValue();

                var templateReportJsonPath = optionTemplateReportJsonPath.Value();
                if (!File.Exists(templateReportJsonPath))
                {
                    throw new FileNotFoundException($"template-report.json file not found at {templateReportJsonPath}");
                }

                var           templatePacks = TemplatePack.CreateFromFile(templateReportJsonPath);
                List <string> createdFiles  = new List <string>();

                string outdir = optionOutputDir.HasValue() ? optionOutputDir.Value() : Directory.GetCurrentDirectory();

                string templatePackFile = Path.Combine(outdir, "template-pack-analysis.csv");
                CreateTemplatePackFile(templatePacks, templateReportJsonPath, templatePackFile);
                createdFiles.Add(templatePackFile);

                // create the json file that contains all the templates
                var allTemplates     = new List <Template>();
                var allTemplateInfos = new List <TemplateReportSummaryInfo>();
                var allHostFiles     = new List <TemplateHostFile>();
                foreach (var tp in templatePacks)
                {
                    var extractFolderPath = Path.Combine(_remoteFile.CacheFolderpath, "extracted", ($"{tp.Package}.{tp.Version}.nupkg").ToLowerInvariant());

                    // populate the HostFiles property of the template pack
                    var templates = TemplatePack.GetTemplateFilesUnder(extractFolderPath);
                    foreach (var template in templates)
                    {
                        var templateObj = Template.CreateFromFile(template);
                        templateObj.TemplatePackId = tp.Package;
                        templateObj.InitHostFilesFrom(Path.GetDirectoryName(template), templateObj.TemplatePackId, templateObj.Name);

                        allTemplates.Add(templateObj);
                        allTemplateInfos.Add(new TemplateReportSummaryInfo {
                            Template = templateObj
                        });
                        if (templateObj.HostFiles != null && templateObj.HostFiles.Count > 0)
                        {
                            allHostFiles.AddRange(templateObj.HostFiles);
                        }
                    }
                }

                var allTemplatesJsonPath = Path.Combine(outdir, "template-all.json");
                CreateAllTemplatesJsonFile(allTemplates, allTemplatesJsonPath);
                createdFiles.Add(allTemplatesJsonPath);

                // create the template-details.csv file now
                var templateDetailsCsvPath = Path.Combine(outdir, "template-details.csv");
                CreateTemplateDetailsCsvFile(allTemplateInfos, templateDetailsCsvPath);
                createdFiles.Add(templateDetailsCsvPath);

                var hostFileDetailsCsvPath = Path.Combine(outdir, "template-host-files.csv");
                CreateHostFilesDetailsCsvFile(allHostFiles, hostFileDetailsCsvPath);
                createdFiles.Add(hostFileDetailsCsvPath);

                Console.WriteLine("Created files:");
                foreach (var cf in createdFiles)
                {
                    Console.WriteLine($"    {cf}");
                }

                return(1);
            };
        }
Пример #3
0
        public override void Setup(CommandLineApplication command)
        {
            base.Setup(command);

            var optionSearchTerms = command.Option <string>(
                "-st|--searchTerm",
                "term to search on nuget. This option may be provided multiple times.",
                CommandOptionType.MultipleValue);

            optionSearchTerms.IsRequired(allowEmptyStrings: false, errorMessage: "you must specify a search term with -st|--searchTerm");

            var optionSaveFilePath = command.Option <string>(
                "-f|--savefilepath",
                "filepath where the results will be stored",
                CommandOptionType.SingleValue);

            var optionNoOutput = command.Option <string>(
                "--no-output",
                "when passed the results will not be displayed on the console. This is typically used with the -f|--savefilepath option.",
                CommandOptionType.NoValue);

            OnExecute = () => {
                var    verbose      = OptionVerbose.HasValue();
                var    searchTerms  = optionSearchTerms.ParsedValues.ToArray <string>();
                string filepath     = optionSaveFilePath.HasValue() ? optionSaveFilePath.Value() : null;
                bool   printResults = optionNoOutput.HasValue() ? true : false;

                void writeVerbose(string str)
                {
                    if (verbose)
                    {
                        Console.WriteLine(str);
                    }
                }

                void writeOutput(string str)
                {
                    if (printResults)
                    {
                        Console.WriteLine(str);
                    }
                }

                var found = _nugetHelper.QueryNuGetAsync(_httpClient, searchTerms, null).Result;

                writeOutput($"Num packages found: {found.Count}");

                if (!string.IsNullOrEmpty(filepath))
                {
                    writeVerbose($"saving to filepath: '{filepath}'");
                    // convert pkg list to a json string
                    var jsonStr = JsonConvert.SerializeObject(found);
                    // write to a temp file and then copy to the final destination
                    var tempfilepath = Path.GetTempFileName();
                    if (File.Exists(tempfilepath))
                    {
                        File.Delete(tempfilepath);
                    }
                    writeVerbose($"saving to tempfile at: '{tempfilepath}'");
                    File.WriteAllText(tempfilepath, jsonStr);
                    writeVerbose($"moving tempfile to destination '{tempfilepath}'->'{filepath}'");
                    File.Move(tempfilepath, filepath, true);
                }

                foreach (var pkg in found)
                {
                    writeOutput(pkg.ToString());
                }
                return(1);
            };
        }
Пример #4
0
        public override void Setup(CommandLineApplication command)
        {
            base.Setup(command);

            DateTime startTime = DateTime.Now;

            Console.WriteLine("Starting at {0}", startTime.ToString("MM.dd.yy-H.m.s.ffff"));
            var optionReportJsonPath = command.Option <string>(
                "-rp|--jsonReportPath",
                "path to where the json report should be written",
                CommandOptionType.SingleValue);

            var optionCacheFolderPath = command.Option <string>(
                "-cf|--cacheFolderPath",
                $"directory path to where the local cache will be. Default path: '{_remoteFile.CacheFolderpath}'",
                CommandOptionType.SingleValue);

            //default: 'template','templates', 'ServiceStack.Core.Templates', 'BlackFox.DotnetNew.FSharpTemplates','libyear','libyear',
            //'angular-cli.dotnet','Carna.ProjectTemplates','SerialSeb.Templates.ClassLibrary','Pioneer.Console.Boilerplate'
            var optionSearchTerms = command.Option <string>(
                "-st|--searchTerm",
                "term to search on nuget. This option may be provided multiple times. If not provided the default set of values will be used.",
                CommandOptionType.MultipleValue);

            var optionPreviousReportPath = command.Option <string>(
                "-lr|--lastReport",
                "path to the last template-report.json file",
                CommandOptionType.SingleValue);

            var optionSpecificPackagesToInclude = command.Option <string>(
                "-p|--packageToInclude",
                "list of specific packages that should be included.",
                CommandOptionType.MultipleValue);

            OnExecute = () => {
                EnableVerboseOption = OptionVerbose.HasValue();

                var report = new TemplateReport(_nugetHelper, _httpClient, _nugetPkgDownloader, _remoteFile, _reporter);

                var searchTerms = optionSearchTerms.HasValue() ? optionSearchTerms.Values.ToArray() : GetDefaultSearchTerms();

                var templateReportPath = optionReportJsonPath.HasValue() ?
                                         optionReportJsonPath.Value() :
                                         Path.Combine(Directory.GetCurrentDirectory(), "template-report.json");

                var specificPackages = new List <string>();
                if (optionSpecificPackagesToInclude.HasValue())
                {
                    specificPackages.AddRange(optionSpecificPackagesToInclude.Values.ToArray());
                }

                string previousReportPath = optionPreviousReportPath.HasValue() ? optionPreviousReportPath.Value() : null;

                report.GenerateTemplateJsonReportAsync(searchTerms, templateReportPath, specificPackages, previousReportPath).Wait();

                DateTime finishTime = DateTime.Now;
                TimeSpan timespent  = finishTime.Subtract(startTime);
                Console.WriteLine("Finished at {0}\nTime taken (sec):{1}", finishTime.ToString("MM.dd.yy-H.m.s.ffff"), timespent.TotalSeconds);

                return(1);
            };
        }