Skip to main content

Overview

The get command retrieves the value associated with a specific key from the vault. If the key doesn’t exist, it returns “Key not found”.

Syntax

vault get <key>

Parameters

key
string
required
The key whose value you want to retrieve.

Examples

Basic Usage

vault get api_key

Expected Output

When key exists:
sk-1234567890abcdef
When key doesn’t exist:
Key not found

Complete Workflow Example

# Add a key
vault add database_url "postgresql://localhost:5432/mydb"

# Retrieve it
vault get database_url
# Output: postgresql://localhost:5432/mydb

# Try to get a non-existent key
vault get nonexistent
# Output: Key not found

Implementation Details

Under the Hood

The get command executes the following SQL query (KVSTORE.cs:94-97):
SELECT value FROM store
WHERE key = $key
The implementation reads the result and outputs either the value or “Key not found” (KVSTORE.cs:91-107):
public int Get(string key)
{
    using var command = connection.CreateCommand();
    command.CommandText = """
        SELECT value FROM store
        WHERE key = $key
    """;
    command.Parameters.AddWithValue("$key", key);
    using var reader = command.ExecuteReader();
    string? value = null;
    while (reader.Read())
    {
        value = reader.GetString(0);
    }
    Console.WriteLine($"{value ?? "Key not found"}");
    return 0;
}

Validation

The command validates that exactly 1 argument is provided (KVSTORE.cs:181-185):
case "get":
    if (args.Length == 1)
    {
        return Command.GET;
    }

Error Cases

Key Not FoundIf the specified key doesn’t exist in the vault, the command outputs:
Key not found
This is not an error condition - the command exits successfully (return code 0).
Invalid ArgumentsProviding the wrong number of arguments will result in:
Please enter a valid command, could not execute

Use Cases

  • Retrieve API keys, tokens, or credentials stored in the vault
  • Check if a key exists before updating or removing it
  • Verify values after adding or updating entries
  • Integrate with shell scripts to fetch configuration values
  • add - Add a new key-value pair
  • update - Update an existing key’s value
  • list - List all keys to see what’s available
  • remove - Delete a key-value pair