<commit_before>﻿using Handyman.Tools.Outdated.Model;
using McMaster.Extensions.CommandLineUtils;
using System.Collections.Generic;
using System.Linq;

namespace Handyman.Tools.Outdated.Analyze
{
    [Command("analyze")]
    public class AnalyzeCommand
    {
        private readonly IConsole _console;
        private readonly ProjectLocator _projectLocator;
        private readonly ProjectUtil _projectUtil;
        private readonly ProjectAnalyzer _projectAnalyzer;
        private readonly IEnumerable<IFileWriter> _fileWriters;

        public AnalyzeCommand(IConsole console, ProjectLocator projectLocator, ProjectUtil projectUtil, ProjectAnalyzer projectAnalyzer, IEnumerable<IFileWriter> fileWriters)
        {
            _console = console;
            _projectLocator = projectLocator;
            _projectUtil = projectUtil;
            _projectAnalyzer = projectAnalyzer;
            _fileWriters = fileWriters;
        }

        [Argument(0, "path", Description = "Path to folder or project")]
        public string Path { get; set; }

        [Option(ShortName = "", Description = "Output file(s), supported format is .md")]
        public IEnumerable<string> OutputFile { get; set; }

        [Option(ShortName = "", Description = "Tags filter, start with ! to exclude")]
        public IEnumerable<string> Tags { get; set; }

        [Option(CommandOptionType.NoValue, ShortName = "", Description = "Skip dotnet restore")]
        public bool NoRestore { get; set; }

        [Option]
        public Verbosity Verbosity { get; set; }

        public int OnExecute()
        {
            var projects = _projectLocator.GetProjects(Path, (Tags ?? new string[] { }).ToList());

            if (ShouldWriteToConsole(Verbosity.Minimal))
            {
                _console.WriteLine();
                _console.WriteLine($"Discovered {projects.Count} projects.");
                _console.WriteLine();
            }

            if (projects.Count == 0)
            {
                return 0;
            }

            foreach (var project in projects)
            {
                if (ShouldWriteToConsole(Analyze.Verbosity.Minimal))
                    _console.WriteLine($"Analyzing {project.RelativePath}");

                if (NoRestore == false)
                    _projectUtil.Restore(project);

                _projectAnalyzer.Analyze(project);
            }<commit_msg>clarified progress in console output from handyman-outdated<commit_after>﻿using Handyman.Tools.Outdated.Model;
using McMaster.Extensions.CommandLineUtils;
using System.Collections.Generic;
using System.Linq;

namespace Handyman.Tools.Outdated.Analyze
{
    [Command("analyze")]
    public class AnalyzeCommand
    {
        private readonly IConsole _console;
        private readonly ProjectLocator _projectLocator;
        private readonly ProjectUtil _projectUtil;
        private readonly ProjectAnalyzer _projectAnalyzer;
        private readonly IEnumerable<IFileWriter> _fileWriters;

        public AnalyzeCommand(IConsole console, ProjectLocator projectLocator, ProjectUtil projectUtil, ProjectAnalyzer projectAnalyzer, IEnumerable<IFileWriter> fileWriters)
        {
            _console = console;
            _projectLocator = projectLocator;
            _projectUtil = projectUtil;
            _projectAnalyzer = projectAnalyzer;
            _fileWriters = fileWriters;
        }

        [Argument(0, "path", Description = "Path to folder or project")]
        public string Path { get; set; }

        [Option(ShortName = "", Description = "Output file(s), supported format is .md")]
        public IEnumerable<string> OutputFile { get; set; }

        [Option(ShortName = "", Description = "Tags filter, start with ! to exclude")]
        public IEnumerable<string> Tags { get; set; }

        [Option(CommandOptionType.NoValue, ShortName = "", Description = "Skip dotnet restore")]
        public bool NoRestore { get; set; }

        [Option]
        public Verbosity Verbosity { get; set; }

        public int OnExecute()
        {
            var projects = _projectLocator.GetProjects(Path, (Tags ?? new string[] { }).ToList());

            if (ShouldWriteToConsole(Verbosity.Minimal))
            {
                _console.WriteLine();
                _console.WriteLine($"Discovered {projects.Count} projects.");
                _console.WriteLine();
            }

            if (projects.Count == 0)
            {
                return 0;
            }

            var counter = 1;
            foreach (var project in projects)
            {
                if (ShouldWriteToConsole(Analyze.Verbosity.Minimal))
                    _console.WriteLine($"Analyzing {project.RelativePath} ({counter++} of {projects.Count})");

                if (NoRestore == false)
                    _projectUtil.Restore(project);

                _projectAnalyzer.Analyze(project);
            }
{'fraction_non_alphanumeric': 0.09122378334351455, 'fraction_numerical': 0.0014253716147424149, 'mean_word_length': 2.287817938420348, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3105812', 'n_tokens_mistral': 1263, 'n_tokens_neox': 1212, 'n_words': 306}