public override int Execute()
        {
            var toolPathOption = _parseResult.GetValueForOption(ToolListCommandParser.ToolPathOption);

            DirectoryPath?toolPath = null;

            if (!string.IsNullOrWhiteSpace(toolPathOption))
            {
                if (!Directory.Exists(toolPathOption))
                {
                    throw new GracefulException(
                              string.Format(
                                  LocalizableStrings.InvalidToolPathOption,
                                  toolPathOption));
                }

                toolPath = new DirectoryPath(toolPathOption);
            }

            var table = new PrintableTable <IToolPackage>();

            table.AddColumn(
                LocalizableStrings.PackageIdColumn,
                p => p.Id.ToString());
            table.AddColumn(
                LocalizableStrings.VersionColumn,
                p => p.Version.ToNormalizedString());
            table.AddColumn(
                LocalizableStrings.CommandsColumn,
                p => string.Join(CommandDelimiter, p.Commands.Select(c => c.Name)));

            table.PrintRows(GetPackages(toolPath), l => _reporter.WriteLine(l));
            return(0);
        }
Пример #2
0
        public void PrintRuntimeInfo()
        {
            _reporter.WriteLine(LocalizableStrings.RuntimeSectionHeader);

            var table = new PrintableTable <NetRuntimeInfo>();

            table.AddColumn(LocalizableStrings.NameColumnHeader, runtime => runtime.Name.ToString());
            table.AddColumn(LocalizableStrings.VersionColumnHeader, runtime => runtime.Version.ToString());
            table.AddColumn(LocalizableStrings.StatusColumnHeader, runtime => GetRuntimeStatusMessage(runtime));

            table.PrintRows(_runtimeInfo.OrderBy(sdk => sdk.Version), l => _reporter.WriteLine(l));

            _reporter.WriteLine();
        }
Пример #3
0
        public override int Execute()
        {
            var installedList = _workloadRecordRepo.GetInstalledWorkloads(_sdkFeatureBand);

            if (_machineReadableOption)
            {
                var updateAvailable = MockUpdateAvailable();
                var listOutput      = new ListOutput(Installed: installedList.Select(id => id.ToString()).ToArray(),
                                                     UpdateAvailable: updateAvailable);

                _reporter.WriteLine("==workloadListJsonOutputStart==");
                _reporter.WriteLine(
                    JsonSerializer.Serialize(listOutput,
                                             options: new JsonSerializerOptions {
                    PropertyNamingPolicy = JsonNamingPolicy.CamelCase
                }));
                _reporter.WriteLine("==workloadListJsonOutputEnd==");
            }
            else
            {
                var table = new PrintableTable <WorkloadId>();
                table.AddColumn(LocalizableStrings.WorkloadIdColumn, workloadId => workloadId.ToString());

                table.PrintRows(installedList, l => _reporter.WriteLine(l));

                _reporter.WriteLine();
            }

            return(0);
        }
Пример #4
0
        public void PrintSdkInfo()
        {
            _reporter.WriteLine(LocalizableStrings.SdkSectionHeader);

            var table = new PrintableTable <NetSdkInfo>();

            table.AddColumn(LocalizableStrings.VersionColumnHeader, sdk => sdk.Version.ToString());
            table.AddColumn(LocalizableStrings.StatusColumnHeader, sdk => GetSdkStatusMessage(sdk));

            table.PrintRows(_sdkInfo.OrderBy(sdk => sdk.Version), l => _reporter.WriteLine(l));

            if (NewFeatureBandAvaliable())
            {
                _reporter.WriteLine();
                _reporter.WriteLine(string.Format(LocalizableStrings.NewFeatureBandMessage, NewestFeatureBandAvaliable()));
            }
        }
Пример #5
0
        public override int Execute()
        {
            var global         = _options.ValueOrDefault <bool>("global");
            var toolPathOption = _options.ValueOrDefault <string>("tool-path");

            DirectoryPath?toolPath = null;

            if (!string.IsNullOrWhiteSpace(toolPathOption))
            {
                if (!Directory.Exists(toolPathOption))
                {
                    throw new GracefulException(
                              string.Format(
                                  LocalizableStrings.InvalidToolPathOption,
                                  toolPathOption));
                }

                toolPath = new DirectoryPath(toolPathOption);
            }

            if (toolPath == null && !global)
            {
                throw new GracefulException(LocalizableStrings.NeedGlobalOrToolPath);
            }

            if (toolPath != null && global)
            {
                throw new GracefulException(LocalizableStrings.GlobalAndToolPathConflict);
            }

            var table = new PrintableTable <IToolPackage>();

            table.AddColumn(
                LocalizableStrings.PackageIdColumn,
                p => p.Id.ToString());
            table.AddColumn(
                LocalizableStrings.VersionColumn,
                p => p.Version.ToNormalizedString());
            table.AddColumn(
                LocalizableStrings.CommandsColumn,
                p => string.Join(CommandDelimiter, p.Commands.Select(c => c.Name)));

            table.PrintRows(GetPackages(toolPath), l => _reporter.WriteLine(l));
            return(0);
        }
Пример #6
0
        public override int Execute()
        {
            IEnumerable <WorkloadResolver.WorkloadInfo> availableWorkloads = _workloadResolver.GetAvailableWorkloads()
                                                                             .OrderBy(workload => workload.Id);

            if (!string.IsNullOrEmpty(_workloadIdStub))
            {
                availableWorkloads = availableWorkloads.Where(workload => workload.Id.ToString().Contains(_workloadIdStub, StringComparison.OrdinalIgnoreCase));
            }

            var table = new PrintableTable <WorkloadResolver.WorkloadInfo>();

            table.AddColumn(LocalizableStrings.WorkloadIdColumnName, workload => workload.Id.ToString());
            table.AddColumn(LocalizableStrings.DescriptionColumnName, workload => workload.Description);

            _reporter.WriteLine();
            table.PrintRows(availableWorkloads, l => _reporter.WriteLine(l));
            _reporter.WriteLine();

            return(0);
        }
Пример #7
0
        public override int Execute()
        {
            if (!_options.ValueOrDefault <bool>("global"))
            {
                throw new GracefulException(LocalizableStrings.ListToolCommandOnlySupportsGlobal);
            }

            var table = new PrintableTable <IToolPackage>();

            table.AddColumn(
                LocalizableStrings.PackageIdColumn,
                p => p.Id.ToString());
            table.AddColumn(
                LocalizableStrings.VersionColumn,
                p => p.Version.ToNormalizedString());
            table.AddColumn(
                LocalizableStrings.CommandsColumn,
                p => string.Join(CommandDelimiter, p.Commands.Select(c => c.Name)));

            table.PrintRows(GetPackages(), l => _reporter.WriteLine(l));
            return(0);
        }
Пример #8
0
        public override int Execute()
        {
            var avaliableWorkloads = _workloadResolver.GetAvaliableWorkloads();

            if (!string.IsNullOrEmpty(_workloadIdStub))
            {
                avaliableWorkloads = avaliableWorkloads.Where(workload => workload.Id.ToString().Contains(_workloadIdStub, StringComparison.OrdinalIgnoreCase));
            }

            var table = new PrintableTable <WorkloadDefinition>();

            table.AddColumn(LocalizableStrings.WorkloadIdColumnName, workload => workload.Id.ToString());
            table.AddColumn(LocalizableStrings.DescriptionColumnName, workload => workload.Description);
            if (_verbosity.VerbosityIsDetailedOrDiagnostic())
            {
                table.AddColumn(LocalizableStrings.PlatformColumnName, workload => workload.Platforms == null ? string.Empty : string.Join(" ", workload.Platforms));
            }

            _reporter.WriteLine();
            table.PrintRows(avaliableWorkloads, l => _reporter.WriteLine(l));
            _reporter.WriteLine();

            return(0);
        }
Пример #9
0
        private void RunTest(TestData data)
        {
            var table = new PrintableTable <string[]>();

            int index = 0;

            foreach (var column in data.Columns)
            {
                var i = index;
                table.AddColumn(
                    column,
                    r => r[i],
                    data.ColumnWidths?[i] ?? int.MaxValue);
                ++index;
            }

            var lines = new List <string>();

            table.PrintRows(data.Rows, l => lines.Add(l));

            lines.Should().Equal(data.ExpectedLines);
            table.CalculateWidth(data.Rows).Should().Be(data.ExpectedTableWidth);
        }
Пример #10
0
        public void Print(bool isDetailed, IReadOnlyCollection <SearchResultPackage> searchResultPackages)
        {
            if (searchResultPackages.Count == 0)
            {
                _reporter.WriteLine(LocalizableStrings.NoResult);
                return;
            }

            if (!isDetailed)
            {
                var table = new PrintableTable <SearchResultPackage>();
                table.AddColumn(
                    LocalizableStrings.PackageId,
                    p => p.Id.ToString());
                table.AddColumn(
                    LocalizableStrings.LatestVersion,
                    p => p.LatestVersion);
                table.AddColumn(
                    LocalizableStrings.Authors,
                    p => p.Authors == null ? "" : string.Join(", ", p.Authors));
                table.AddColumn(
                    LocalizableStrings.Downloads,
                    p => p.TotalDownloads.ToString());
                table.AddColumn(
                    LocalizableStrings.Verified,
                    p => p.Verified ? "x" : "");

                table.PrintRows(searchResultPackages, l => _reporter.WriteLine(l));
            }
            else
            {
                foreach (var p in searchResultPackages)
                {
                    _reporter.WriteLine("----------------".Bold());
                    _reporter.WriteLine(p.Id.ToString());
                    _reporter.WriteLine($"{LocalizableStrings.LatestVersion}: ".Bold() + p.LatestVersion);
                    if (p.Authors != null)
                    {
                        _reporter.WriteLine($"{LocalizableStrings.Authors}: ".Bold() + string.Join(", ", p.Authors));
                    }

                    if (p.Tags != null)
                    {
                        _reporter.WriteLine($"{LocalizableStrings.Tags}: ".Bold() + string.Join(", ", p.Tags));
                    }

                    _reporter.WriteLine($"{LocalizableStrings.Downloads}: ".Bold() + p.TotalDownloads);


                    _reporter.WriteLine($"{LocalizableStrings.Verified}: ".Bold() + p.Verified.ToString());

                    if (!string.IsNullOrWhiteSpace(p.Summary))
                    {
                        _reporter.WriteLine($"{LocalizableStrings.Summary}: ".Bold() + p.Summary);
                    }

                    if (!string.IsNullOrWhiteSpace(p.Description))
                    {
                        _reporter.WriteLine($"{LocalizableStrings.Description}: ".Bold() + p.Description);
                    }

                    if (p.Versions.Count != 0)
                    {
                        _reporter.WriteLine($"{LocalizableStrings.Versions}: ".Bold());
                        foreach (SearchResultPackageVersion version in p.Versions)
                        {
                            _reporter.WriteLine(
                                $"\t{version.Version}" + $" {LocalizableStrings.Downloads}: ".Bold() + version.Downloads);
                        }
                    }

                    _reporter.WriteLine();
                }
            }
        }
Пример #11
0
        protected override int Execute()
        {
            var baseResult = base.Execute();

            if (baseResult != 0)
            {
                return(baseResult);
            }

            var metadata = new GenymanMetadata();
            var version  = GetVersion();

            Log.Information($"Executing doc command for {metadata.PackageId} - Version {version}");

            var markdown    = new List <string>();
            var useMarkdown = MarkdownOption.HasValue();

            if (useMarkdown)
            {
                markdown.Add($"# {metadata.PackageId}");
                markdown.Add(metadata.Description);
                markdown.Add("## Getting Started");
                markdown.Add($"{metadata.PackageId} is a **[genyman](http://genyman.net)** code generator. If you haven't installed **genyman** run following command:");
                markdown.Add($"```");
                markdown.Add($"dotnet tool install -g genyman");
                markdown.Add($"```");
                markdown.Add($"_Genyman is a .NET Core Global tool and thereby you need .NET Core version 2.1 installed._");

                markdown.Add("## New Configuration file ");
                markdown.Add($"```");
                if (metadata.Identifier == "Genyman")
                {
                    markdown.Add($"genyman new");
                }
                else
                {
                    markdown.Add($"genyman new {metadata.PackageId}");
                }
                markdown.Add($"```");

                markdown.Add("## Sample Configuration file ");

                var configuration = new GenymanConfiguration <TConfiguration>
                {
                    Genyman       = metadata,
                    Configuration = new TTemplate(),
                };
                var output = configuration.ToJsonString();
                markdown.Add($"```");
                markdown.Add(output);
                markdown.Add($"```");

                markdown.Add("## Documentation ");
            }

            var types = typeof(TConfiguration).Assembly.GetExportedTypes();

            foreach (var type in types)
            {
                var documentation = type.GetCustomAttribute <DocumentationAttribute>();
                if (documentation == null)
                {
                    continue;
                }

                if (type.IsClass)
                {
                    var output = new List <PropertyList>();

                    var properties = type.GetProperties();
                    foreach (var property in properties)
                    {
                        var ignoreAttribute = property.GetCustomAttribute <IgnoreAttribute>();
                        if (ignoreAttribute != null)
                        {
                            continue;
                        }

                        var descriptionAttribute = property.GetCustomAttribute <DescriptionAttribute>();
                        var requiredAttribute    = property.GetCustomAttribute <RequiredAttribute>();

                        var typeName = property.PropertyType.Name;
                        if (property.PropertyType.IsEnum)
                        {
                            typeName += " (Enum)";
                        }
                        else if (property.PropertyType.IsGenericType && typeName.Contains("List"))
                        {
                            typeName = $"{property.PropertyType.GenericTypeArguments[0].Name}[]";
                        }


                        output.Add(new PropertyList()
                        {
                            Name        = property.Name,
                            Type        = typeName,
                            Required    = requiredAttribute != null ? "*" : "",
                            Description = descriptionAttribute?.Description
                        });
                    }

                    WriteHeader(type);

                    var table = new PrintableTable <PropertyList>();
                    table.AddColumn("Name", p => p.Name);
                    table.AddColumn("Type", p => p.Type);
                    table.AddColumn("Req", p => p.Required);
                    table.AddColumn("Description", p => p.Description);
                    table.PrintRows(output, Console.WriteLine);

                    if (useMarkdown)
                    {
                        markdown.Add($"### Class {type.Name}");
                        if (!string.IsNullOrEmpty(documentation.Remarks))
                        {
                            markdown.Add(documentation.Remarks);
                        }

                        markdown.Add($"| Name | Type | Req | Description |");
                        markdown.Add($"| --- | --- | :---: | --- |");
                        foreach (var p in output)
                        {
                            markdown.Add($"| {p.Name} | {p.Type} | {p.Required} | {p.Description} |");
                        }
                    }
                }
                else if (type.IsEnum)
                {
                    var output = new List <EnumList>();

                    var fields = type.GetFields();
                    foreach (var fieldInfo in fields)
                    {
                        if (fieldInfo.IsSpecialName)
                        {
                            continue;
                        }
                        var descriptionAttribute = fieldInfo.GetCustomAttribute <DescriptionAttribute>();
                        output.Add(new EnumList()
                        {
                            Name        = fieldInfo.Name,
                            Description = descriptionAttribute?.Description
                        });
                    }

                    WriteHeader(type);

                    var table = new PrintableTable <EnumList>();
                    table.AddColumn("Name", p => p.Name);
                    table.AddColumn("Description", p => p.Description);
                    table.PrintRows(output, Console.WriteLine);

                    if (useMarkdown)
                    {
                        markdown.Add($"### Enum {type.Name}");
                        if (!string.IsNullOrEmpty(documentation.Remarks))
                        {
                            markdown.Add(documentation.Remarks);
                        }

                        markdown.Add($"| Name | Description |");
                        markdown.Add($"| --- | --- |");
                        foreach (var p in output)
                        {
                            markdown.Add($"| {p.Name} | {p.Description} |");
                        }
                    }
                }
            }

            if (useMarkdown)
            {
                var target = Path.Combine(WorkingDirectory, MarkdownOption.ParsedValue);
                target.EnsureFolderExists();
                File.WriteAllLines(target, markdown);
            }

            return(0);
        }