src/Keypear.CliClient/CliModel/MainCommand.cs
/// <summary>
/// Resolves a Record reference to a specific Record instance, or failing
/// that, will print an appropriate error message to console and return
/// <c>null</c>.
/// </summary>
Resolves a Record reference to a specific Record instance, or failing
that, will print an appropriate error message to console and return
null
Resolves a Record reference to a specific Record instance or failing that will print an appropriate error message to console and return null
public Record? GetRecord(KyprClient client, ref Vault? vault, string recordRef)
    {
        IEnumerable<Vault>? vaults;
        if (vault != null)
        {
            client.UnlockVault(vault);
            client.UnlockRecordSummaries(vault);
            vaults = new[] { vault };
        }
        else
        {
            client.UnlockVaults();
            vaults = client.ListVaults();
            foreach (var v in vaults)
            {
                client.UnlockRecordSummaries(v);
            }
        }
        var records = vaults
            .SelectMany(x => x.Records.Select(y => (vault: x, record: y)))
            .Where(x => x.record.Id.ToString()!.StartsWith(recordRef!, StringComparison.OrdinalIgnoreCase));
        if (records.Count() == 0)
        {
            records = vaults
                .SelectMany(x => x.Records.Select(y => (vault: x, record: y)))
                .Where(x => x.record.Summary!.Label!.StartsWith(recordRef!, StringComparison.OrdinalIgnoreCase));
        }
        if (records.Count() == 0)
        {
            _console.WriteError("no Records match the specified reference.");
            return null;
        }
        if (records.Count() > 1)
        {
            _console.WriteError("multiple Records match the specified reference.");
            return null;
        }
        var match = records.Single();
        vault = match.vault;
        return match.record;
    }
public Record ? GetRecord ( KyprClient client , ref Vault ? vault , string recordRef ) { IEnumerable < Vault > ? vaults ; if ( vault != null ) { client . UnlockVault ( vault ) ; client . UnlockRecordSummaries ( vault ) ; vaults = new [ ] { vault } ; } else { client . UnlockVaults ( ) ; vaults = client . ListVaults ( ) ; foreach ( var v in vaults ) { client . UnlockRecordSummaries ( v ) ; } } var records = vaults . SelectMany ( x => x . Records . Select ( y => ( vault : x , record : y ) ) ) . Where ( x => x . record . Id . ToString ( ) ! . StartsWith ( recordRef ! , StringComparison . OrdinalIgnoreCase ) ) ; if ( records . Count ( ) == 0 ) { records = vaults . SelectMany ( x => x . Records . Select ( y => ( vault : x , record : y ) ) ) . Where ( x => x . record . Summary ! . Label ! . StartsWith ( recordRef ! , StringComparison . OrdinalIgnoreCase ) ) ; } if ( records . Count ( ) == 0 ) { _console . WriteError ( " " ) ; return null ; } if ( records . Count ( ) > 1 ) { _console . WriteError ( " " ) ; return null ; } var match = records . Single ( ) ; vault = match . vault ; return match . record ; }
Resolves a Record reference to a specific Record instance, or failing
that, will print an appropriate error message to console and return
null
Resolves a Record reference to a specific Record instance or failing that will print an appropriate error message to console and return null
// Next try by label
client
KyprClient
Vault?
ref
recordRef
string