public int Proj(IAnsiConsole console, CancellationToken cancellationToken, TableFormatModel tableFormatModel, [Option('k', Description = "regex to match key. Prefix with $! for NOT matching.")] Regex?keyPattern, [Option('n', Description = "regex to match name. Prefix with $! for NOT matching.")] Regex?namePattern, [Option('d', Description = "regex to match description. Prefix with $! for NOT matching.")] Regex?descPattern, [Option('o', null, Description = "output only keys")] bool outputKeys = false) { var projects = _bbService .GetProjects() .WhereMatches(p => p.Key, keyPattern) .WhereMatches(p => p.Name, namePattern) .WhereMatches(p => p.Description, descPattern) .OrderBy(p => p.Name) .ToCollection(); if (outputKeys) { projects .Select(p => p.Key) .ForEach(console.WriteLine); } else { var localRepos = _gitService.GetLocalRepos(); var remoteRepos = _bbService .GetRepos(projects.Select(p => p.Name).ToCollection()); var repoPairs = localRepos.PairRepos(remoteRepos, mustHaveRemote: true).Values; var remoteRepoCounts = repoPairs .Where(p => p.Remote is not null) .GroupBy(p => p.Remote !.ProjectKey) .ToDictionary( g => g.Key, g => new { remote = g.Count(), local = g.Count(r => r.Local is not null) });
public void Repo( IAnsiConsole console, CancellationToken cancellationToken, TableFormatModel tableFormatModel, ProjOrRepoKeys projOrRepoKeys, [Option('n', Description = "regex to match name. Prefix with $! for NOT matching.")] Regex?namePattern, [Option("branch", Description = "return only with the branch name. Prefix with $! for NOT matching.")] Regex?branchPattern, [Option('o', null, Description = "output only repo names")] bool outputNames = false, [Option("opk", Description = "output only project keys")] bool outputProjectKeys = false, [Option('l', Description = "where local branch is checked out")] bool isInLocalBranch = false, [Option('b', Description = "with local branches")] bool withLocalBranches = false, [Option('c', Description = "with changes: staged or unstaged")] bool withLocalChanges = false, [Option('s', Description = "with stashes")] bool withLocalStashes = false, [Option("or", Description = "treat options:b,w,s as `OR` instead of `AND`")] bool orLocalChecks = false, [Option('d', Description = "has no remote repo")] bool noRemote = false, [Option(Description = "inverts the filter")] bool not = false) { using var localRepos = _gitService.GetLocalRepos(projOrRepoKeys); var repos = localRepos.AsEnumerable(); repos = repos.WhereMatches(r => r.Name, namePattern) .WhereMatches(r => r.CurrentBranchName, branchPattern) .WhereIf(noRemote, r => r.RemoteRepo is null) .WhereIf(isInLocalBranch, r => r.IsInLocalBranch); if (withLocalBranches || withLocalChanges || withLocalStashes) { repos = orLocalChecks ? repos.Where(r => (!withLocalBranches || r.LocalBranchCount > 0) || (!withLocalChanges || r.LocalChangesCount > 0) || (!withLocalStashes || r.StashCount > 0) ) : repos.Where(r => (!withLocalBranches || r.LocalBranchCount > 0) && (!withLocalChanges || r.LocalChangesCount > 0) && (!withLocalStashes || r.StashCount > 0) ); } if (not) { var reposToHide = repos.Select(r => r.Name).ToHashSet(); repos = localRepos.Where(r => !reposToHide.Contains(r.Name)); } if (outputNames || Console.IsOutputRedirected) { repos .Select(r => r.Name) .ForEach(console.WriteLine); } else if (outputProjectKeys) { repos .Select(r => r.RemoteRepo?.ProjectKey) .Where(k => k is not null) .Distinct() .OrderBy(k => k) .ForEach(console.WriteLine !); } else { PrintReposTable(console, repos, tableFormatModel.GetTheme()); } }