< Summary - ZhEaIsNsAaBn.Libraries coverage (affected: 23 packages)

Information
Class: ZhEaIsNsAaBn.DbSeeder.Tool.ToolOptions
Assembly: ZhEaIsNsAaBn.DbSeeder.Tool
File(s): /home/runner/work/ZhEaIsNsAaBn.Libraries.V1/ZhEaIsNsAaBn.Libraries.V1/src/DataBasePackages/ZhEaIsNsAaBn.DbSeeder.Tool/ToolOptions.cs
Line coverage
93%
Covered lines: 30
Uncovered lines: 2
Coverable lines: 32
Total lines: 100
Line coverage: 93.7%
Branch coverage
82%
Covered branches: 64
Total branches: 78
Branch coverage: 82%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
TryParse(...)82.05%797893.75%

File(s)

/home/runner/work/ZhEaIsNsAaBn.Libraries.V1/ZhEaIsNsAaBn.Libraries.V1/src/DataBasePackages/ZhEaIsNsAaBn.DbSeeder.Tool/ToolOptions.cs

#LineLine coverage
 1namespace ZhEaIsNsAaBn.DbSeeder.Tool;
 2
 3/// <summary>
 4/// <c>dbseeder [tool options] &lt;command&gt; [command options] [-- app args]</c>. Tool options come before the command
 5/// the command on goes to the DbSeeder commands unchanged, except what follows <c>--</c> (the app's entry point and fac
 6/// </summary>
 7internal sealed record ToolOptions
 8{
 9    public string? Project        { get; private init; }
 10    public string? StartupProject { get; private init; }
 11    public string? Context        { get; private init; }
 12    public string  Configuration  { get; private init; } = "Debug";
 13    public string? Framework      { get; private init; }
 14    public string? Environment    { get; private init; }
 15    public bool    NoBuild        { get; private init; }
 16    public bool    Verbose        { get; private init; }
 17    public bool    Help           { get; private init; }
 18    public bool    Version        { get; private init; }
 19
 20    public IReadOnlyList<string> Command { get; private init; } = [];
 21    public IReadOnlyList<string> AppArgs { get; private init; } = [];
 22
 23
 24    public const string Usage = """
 25                                Usage: dbseeder [options] <command> [command options] [-- app args]
 26
 27                                Options (before the command):
 28                                  -p|--project <path>          Project with .dbseeder/ and the migrations folders (defau
 29                                  -s|--startup-project <path>  Project the app runs from: host or IDesignTimeDbContextFa
 30                                  -c|--context <name>          DbContext (short or full name) when there is more than on
 31                                  -f|--framework <tfm>         Target framework, required when the startup project has s
 32                                  --configuration <name>       Build configuration (default: Debug)
 33                                  -e|--environment <name>      DOTNET_ENVIRONMENT / ASPNETCORE_ENVIRONMENT for the app (
 34                                  --no-build                   Use the last build
 35                                  -v|--verbose                 Show the build output and the commands run
 36                                  --version                    Show the tool version
 37                                  -h|--help                    Show this help
 38
 39                                Commands: profile, baseline, add, snapshot, validate, list, update, down, script.
 40                                Run "dbseeder <command> --help" for a command's options.
 41                                """;
 42
 43
 44    public static bool TryParse( IReadOnlyList<string> args, out ToolOptions options, out string error )
 45    {
 2446        options = new ToolOptions();
 2447        error   = "";
 48
 2449        var i = 0;
 50
 9651        for ( ; i < args.Count && args[ i ].StartsWith( '-' ) && args[ i ] != "--"; i++ )
 52        {
 4453            var name = args[ i ];
 54
 55            switch ( name )
 56            {
 857                case "--no-build":        options = options with { NoBuild = true }; continue;
 858                case "-v" or "--verbose": options = options with { Verbose = true }; continue;
 059                case "-h" or "--help":    options = options with { Help = true }; continue;
 060                case "--version":         options = options with { Version = true }; continue;
 61            }
 62
 3663            if ( name is not ("-p" or "--project" or "-s" or "--startup-project" or "-c" or "--context" or "-f" or "--fr
 3664                              or "--environment") )
 65            {
 466                error = $"Unknown option {name}. Tool options go before the command; see dbseeder --help.";
 67
 468                return false;
 69            }
 70
 3271            if ( i + 1 >= args.Count || args[ i + 1 ].StartsWith( '-' ) )
 72            {
 473                error = $"{name} needs a value.";
 74
 475                return false;
 76            }
 77
 2878            var value = args[ ++i ];
 79
 2880            options = name switch
 2881            {
 482                "-p" or "--project"         => options with { Project = value },
 483                "-s" or "--startup-project" => options with { StartupProject = value },
 484                "-c" or "--context"         => options with { Context = value },
 485                "-f" or "--framework"       => options with { Framework = value },
 886                "-e" or "--environment"     => options with { Environment = value },
 487                _                           => options with { Configuration = value }
 2888            };
 89        }
 90
 1691        var rest      = args.Skip( i ).ToList();
 1692        var separator = rest.IndexOf( "--" );
 93
 1694        options = separator < 0
 1695                      ? options with { Command = rest }
 1696                      : options with { Command = rest[ ..separator ], AppArgs = rest[ ( separator + 1 ).. ] };
 97
 1698        return true;
 99    }
 100}