MCPcopy Create free account
hub / github.com/NVIDIA/OpenShell / auto_create_provider

Function auto_create_provider

crates/openshell-cli/src/run.rs:3817–3972  ·  view source on GitHub ↗

Prompt for (or auto-confirm) creation of a provider from local credentials. When `preferred_name` is `Some`, the provider is created with that exact name (used for explicit `--provider ` values). When `None`, the name defaults to the type and retries with suffixes on conflict (used for inferred provider types).

(
    client: &mut crate::tls::GrpcClient,
    provider_type: &str,
    preferred_name: Option<&str>,
    auto_providers_override: Option<bool>,
    seen_names: &mut HashSet<String>,
    configured_na

Source from the content-addressed store, hash-verified

3815/// defaults to the type and retries with suffixes on conflict (used for
3816/// inferred provider types).
3817async fn auto_create_provider(
3818 client: &mut crate::tls::GrpcClient,
3819 provider_type: &str,
3820 preferred_name: Option<&str>,
3821 auto_providers_override: Option<bool>,
3822 seen_names: &mut HashSet<String>,
3823 configured_names: &mut Vec<String>,
3824) -> Result<()> {
3825 eprintln!("Missing provider: {provider_type}");
3826
3827 // --no-auto-providers: skip silently.
3828 if auto_providers_override == Some(false) {
3829 eprintln!(
3830 "{} Skipping provider '{provider_type}' (--no-auto-providers)",
3831 "!".yellow(),
3832 );
3833 eprintln!();
3834 return Ok(());
3835 }
3836
3837 // No override and non-interactive: error.
3838 if auto_providers_override.is_none() && !std::io::stdin().is_terminal() {
3839 return Err(miette::miette!(
3840 "missing required provider '{provider_type}'. Create it first with \
3841 `openshell provider create --type {provider_type} --name {provider_type} --from-existing`, \
3842 pass --auto-providers to auto-create, or set it up manually from inside the sandbox"
3843 ));
3844 }
3845
3846 // --auto-providers: auto-confirm; otherwise prompt.
3847 let should_create = if auto_providers_override == Some(true) {
3848 true
3849 } else {
3850 Confirm::new()
3851 .with_prompt("Create from local credentials?")
3852 .default(true)
3853 .interact()
3854 .into_diagnostic()?
3855 };
3856
3857 if !should_create {
3858 eprintln!("{} Skipping provider '{provider_type}'", "!".yellow());
3859 eprintln!();
3860 return Ok(());
3861 }
3862
3863 let discovered = discover_existing_provider_data(client, provider_type)
3864 .await
3865 .map_err(|err| miette::miette!("failed to discover provider '{provider_type}': {err}"))?;
3866 let Some(discovered) = discovered else {
3867 eprintln!(
3868 "{} No existing local credentials/config found for '{}'. You can configure it from inside the sandbox.",
3869 "!".yellow(),
3870 provider_type
3871 );
3872 eprintln!();
3873 return Ok(());
3874 };

Callers 1

Calls 6

object_nameMethod · 0.80
pushMethod · 0.80
codeMethod · 0.80
defaultMethod · 0.45
create_providerMethod · 0.45

Tested by

no test coverage detected