Overview
The add command stores a new key-value pair in the vault. Each key must be unique - attempting to add a duplicate key will result in an error.
Syntax
Parameters
The unique identifier for the stored value. Must not already exist in the vault.
The value to store. Can contain spaces and special characters (use quotes for values with spaces).
Examples
Basic Usage
vault add username john_doe
Expected Output
Adding key: api_key with the value: sk-1234567890abcdef to the vault
Implementation Details
Under the Hood
The add command executes the following SQL query (KVSTORE.cs:49-52):
INSERT INTO store (key, value)
VALUES ($key, $value)
The database schema ensures key uniqueness with a UNIQUE constraint on the key column.
Validation
The command validates that exactly 2 arguments are provided (KVSTORE.cs:164-167):
case "add":
if (args.Length == 2)
{
return Command.ADD;
}
If the wrong number of arguments is provided, the command fails with an error message.
Error Cases
Duplicate Key ErrorAttempting to add a key that already exists will fail due to the SQLite UNIQUE constraint:vault add mykey "value1"
vault add mykey "value2" # Error: UNIQUE constraint failed
Use the update command instead to modify existing keys.
Invalid ArgumentsProviding the wrong number of arguments will result in:Please enter a valid command, could not execute
get - Retrieve a value by key
update - Update an existing key’s value
list - List all keys in the vault
remove - Delete a key-value pair