Repository: oumi-ai/oumi
File: src/oumi/cli/cli_utils.py (Python)

Code before:
    Optional[LogLevel],
    typer.Option(
        "--log-level",
        "-log",
        help="The logging level for the specified command.",
        show_default=False,
        show_choices=True,
        case_sensitive=False,
        callback=set_log_level,
    ),
]


def resolve_oumi_prefix(
    config_path: str, output_dir: Optional[Path] = None
) -> tuple[str, Path]:
    """Resolves oumi:// prefix and determines output directory.

    Args:
        config_path: Path that may contain oumi:// prefix
        output_dir: Optional output directory override

    Returns:
        tuple[str, Path]: (cleaned path, output directory)
    """
    config_path = config_path[7:]

    config_dir = output_dir or os.environ.get("OUMI_DIR") or "~/.oumi/configs"
    config_dir = Path(config_dir).expanduser()
    config_dir.mkdir(parents=True, exist_ok=True)

    return config_path, config_dir


def resolve_and_fetch_config(
    config_path: str, output_dir: Optional[Path] = None
) -> Path:
    """Resolve oumi:// prefix and fetch config if needed.

    Args:
        config_path: Original config path that may contain oumi:// prefix
        output_dir: Optional override for output directory

    Returns:
        Path: Local path to the config file
    """
    if not config_path.startswith("oumi://"):
        return Path(config_path)

    from oumi.cli.fetch import fetch


Review comment (suggestion):
```suggestion
    oumi_prefix = "oumi://"
    if config_path.lower().startswith(oumi_prefix):
        config_path = config_path[len(oumi_prefix):]
```

This allows users to use the `oumi://` prefix when fetching, but it's not required.

So they could call `oumi fetch /configs/recipes/some_config.yaml`
or 
`oumi fetch oumi://configs/recipes/some_config.yaml`

Code after:
    Optional[LogLevel],
    typer.Option(
        "--log-level",
        "-log",
        help="The logging level for the specified command.",
        show_default=False,
        show_choices=True,
        case_sensitive=False,
        callback=set_log_level,
    ),
]


def resolve_oumi_prefix(
    config_path: str, output_dir: Optional[Path] = None
) -> tuple[str, Path]:
    """Resolves oumi:// prefix and determines output directory.

    Args:
        config_path: Path that may contain oumi:// prefix
        output_dir: Optional output directory override

    Returns:
        tuple[str, Path]: (cleaned path, output directory)
    """
    oumi_prefix = "oumi://"
    if config_path.lower().startswith(oumi_prefix):
        config_path = config_path[len(oumi_prefix) :]

    config_dir = output_dir or os.environ.get("OUMI_DIR") or "~/.oumi/configs"
    config_dir = Path(config_dir).expanduser()
    config_dir.mkdir(parents=True, exist_ok=True)

    return config_path, config_dir


def resolve_and_fetch_config(
    config_path: str, output_dir: Optional[Path] = None
) -> Path:
    """Resolve oumi:// prefix and fetch config if needed.

    Args:
        config_path: Original config path that may contain oumi:// prefix
        output_dir: Optional override for output directory

    Returns:
        Path: Local path to the config file
    """
    if not config_path.lower().startswith("oumi://"):
        return Path(config_path)