Jump to content

Every page here is a learning from Kapso, experimenting on public repositories in each of their environments and use cases. Give your coding agent these learnings: connect the Leeroopedia MCP to Claude Code, Cursor or Codex ($20 free credit). Powered by Leeroo · founders@leeroo.com

Implementation:AI Northstar Tech Vector io Set Arg From Input

From Leeroopedia
Knowledge Sources
Domains CLI, Credentials, User_Interaction
Last Updated 2026-10-15 00:00 GMT

Overview

Concrete utility functions for interactively collecting CLI arguments and credentials from user input or environment variables, provided by the vector-io library.

Description

The set_arg_from_input and set_arg_from_password functions are shared utilities used by all DB-specific export and import modules to collect required arguments interactively. They check if a value is already present in the args dict; if not, they prompt the user (via input() or getpass()), with support for environment variable fallback, default values, and choice validation.

set_arg_from_input handles general argument prompting with type coercion, default values, choices validation, and environment variable fallback. It strips surrounding quotes from user input and supports comma-separated multi-choice selection.

set_arg_from_password handles sensitive credential collection using getpass to hide input. It first checks the environment variable, then prompts only if the value is not already set.

Usage

Import these functions when building CLI subparsers for DB-specific export/import modules that need to collect credentials or configuration from the user interactively.

Code Reference

Source Location

  • Repository: vector-io
  • File: src/vdf_io/util.py

Signature

def set_arg_from_input(
    args: dict,
    arg_name: str,
    prompt: str,
    type_name: type = str,
    default_value: Any = None,
    choices: list = None,
    env_var: str = None,
) -> None:
    """
    Set an argument value from user input if not already present in args dict.

    Checks environment variable first (if env_var is set and default_value is None).
    Prompts the user via input(). Strips surrounding quotes. Validates against
    choices if provided. Coerces to type_name. Falls back to default_value on empty input.

    Args:
        args: Mutable args dict to populate
        arg_name: Key to set in args dict
        prompt: User-facing prompt text
        type_name: Type to coerce the input value to (default: str)
        default_value: Default value if user enters empty string
        choices: List of valid choices (supports comma-separated multi-select)
        env_var: Environment variable name for fallback
    """

def set_arg_from_password(
    args: dict,
    arg_name: str,
    prompt: str,
    env_var_name: str,
) -> None:
    """
    Set a password/credential value from environment variable or secure prompt.

    Checks env_var_name first. If not set, prompts via getpass() (hidden input).
    Only prompts if arg_name is not already in args or is None.

    Args:
        args: Mutable args dict to populate
        arg_name: Key to set in args dict
        prompt: User-facing prompt text
        env_var_name: Environment variable name for fallback
    """

Import

from vdf_io.util import set_arg_from_input, set_arg_from_password

I/O Contract

Inputs

Name Type Required Description
args dict Yes Mutable args dict to populate
arg_name str Yes Key to set in args dict
prompt str Yes User-facing prompt text
type_name type No Type coercion (default: str)
default_value Any No Default if user enters empty input
choices list No Valid choices for validation
env_var str No (set_arg_from_input) Environment variable fallback
env_var_name str Yes (set_arg_from_password) Environment variable name

Outputs

Name Type Description
args[arg_name] Any Mutated args dict with the collected value

Usage Examples

Collecting API Key

from vdf_io.util import set_arg_from_input, set_arg_from_password

# Prompt for API key, with env var fallback PINECONE_API_KEY
set_arg_from_password(
    args,
    "pinecone_api_key",
    "Enter your Pinecone API key: ",
    "PINECONE_API_KEY",
)

Collecting Index Name with Choices

# Prompt for environment, with validation against choices
set_arg_from_input(
    args,
    "environment",
    "Select your Pinecone environment: ",
    choices=["us-east-1-aws", "us-west-2-aws", "europe-west1-gcp"],
)

Collecting Numeric Value with Default

# Prompt for batch size, default 100, coerce to int
set_arg_from_input(
    args,
    "batch_size",
    "Enter batch size (default 100): ",
    type_name=int,
    default_value=100,
)

Related Pages

Implements Principle

Requires Environment

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment