Skip to content

Commit

Permalink
refactor: some progress... still unable to run tests at this point
Browse files Browse the repository at this point in the history
Signed-off-by: Ahmed Tadde <[email protected]>
  • Loading branch information
ahmedtadde committed Feb 4, 2025
1 parent f3f3fb3 commit a45be57
Show file tree
Hide file tree
Showing 140 changed files with 6,306 additions and 282 deletions.
40 changes: 20 additions & 20 deletions crates/wash/src/bin/wash.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,27 +3,27 @@ use std::fmt::{Display, Formatter};
use std::io::{stdout, BufWriter, Write};
use std::path::{Path, PathBuf};

use crate::lib::cli::capture::{CaptureCommand, CaptureSubcommand};
use crate::lib::cli::claims::ClaimsCliCommand;
use crate::lib::cli::get::GetCommand;
use crate::lib::cli::inspect::InspectCliCommand;
use crate::lib::cli::label::LabelHostCommand;
use crate::lib::cli::link::LinkCommand;
use crate::lib::cli::registry::{RegistryPullCommand, RegistryPushCommand};
use crate::lib::cli::scale::ScaleCommand;
use crate::lib::cli::spy::SpyCommand;
use crate::lib::cli::start::StartCommand;
use crate::lib::cli::stop::StopCommand;
use crate::lib::cli::update::UpdateCommand;
use crate::lib::cli::{CommandOutput, OutputKind};
use crate::lib::drain::Drain as DrainSelection;
use crate::lib::plugin::subcommand::{DirMapping, SubcommandRunner};
use anyhow::bail;
use clap::{self, Arg, Command, FromArgMatches, Parser, Subcommand};
use console::style;
use crossterm::style::Stylize;
use serde_json::json;
use tracing_subscriber::EnvFilter;
use wash_lib::cli::capture::{CaptureCommand, CaptureSubcommand};
use wash_lib::cli::claims::ClaimsCliCommand;
use wash_lib::cli::get::GetCommand;
use wash_lib::cli::inspect::InspectCliCommand;
use wash_lib::cli::label::LabelHostCommand;
use wash_lib::cli::link::LinkCommand;
use wash_lib::cli::registry::{RegistryPullCommand, RegistryPushCommand};
use wash_lib::cli::scale::ScaleCommand;
use wash_lib::cli::spy::SpyCommand;
use wash_lib::cli::start::StartCommand;
use wash_lib::cli::stop::StopCommand;
use wash_lib::cli::update::UpdateCommand;
use wash_lib::cli::{CommandOutput, OutputKind};
use wash_lib::drain::Drain as DrainSelection;
use wash_lib::plugin::subcommand::{DirMapping, SubcommandRunner};

use wash_cli::app::{self, AppCliCommand};
use wash_cli::build::{self, BuildCommand};
Expand Down Expand Up @@ -548,13 +548,13 @@ async fn main() {
if !cli.experimental {
experimental_error_message("capture")
} else if let Some(CaptureSubcommand::Replay(cmd)) = capture_cli.replay {
wash_lib::cli::capture::handle_replay_command(cmd).await
crate::lib::cli::capture::handle_replay_command(cmd).await
} else {
wash_lib::cli::capture::handle_command(capture_cli).await
crate::lib::cli::capture::handle_command(capture_cli).await
}
}
CliCommand::Claims(claims_cli) => {
wash_lib::cli::claims::handle_command(claims_cli, output_kind).await
crate::lib::cli::claims::handle_command(claims_cli, output_kind).await
}
CliCommand::Completions(completions_cli) => {
completions::handle_command(completions_cli, Cli::command())
Expand All @@ -566,7 +566,7 @@ async fn main() {
CliCommand::Drain(drain_cli) => drain::handle_command(drain_cli),
CliCommand::Get(get_cli) => common::get_cmd::handle_command(get_cli, output_kind).await,
CliCommand::Inspect(inspect_cli) => {
wash_lib::cli::inspect::handle_command(inspect_cli, output_kind).await
crate::lib::cli::inspect::handle_command(inspect_cli, output_kind).await
}
CliCommand::Keys(keys_cli) => keys::handle_command(keys_cli),
CliCommand::Link(link_cli) => link::invoke(link_cli, output_kind).await,
Expand All @@ -583,7 +583,7 @@ async fn main() {
if !cli.experimental {
experimental_error_message("spy")
} else {
wash_lib::cli::spy::handle_command(spy_cli).await
crate::lib::cli::spy::handle_command(spy_cli).await
}
}
CliCommand::Scale(scale_cli) => {
Expand Down
20 changes: 10 additions & 10 deletions crates/wash/src/cli/app/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,7 @@ async fn undeploy_model(cmd: UndeployCommand) -> Result<CommandOutput> {
vec![model_name]
}
// If no model name was specified, use command-specified filters to determine which models to act on
None if cmd.all => wash_lib::app::get_models(&client, lattice.clone())
None if cmd.all => crate::lib::app::get_models(&client, lattice.clone())
.await?
.into_iter()
.map(|m| m.name)
Expand All @@ -293,7 +293,7 @@ async fn undeploy_model(cmd: UndeployCommand) -> Result<CommandOutput> {

// Undeploy models
for model_name in models.iter() {
match wash_lib::app::undeploy_model(&client, lattice.clone(), model_name).await {
match crate::lib::app::undeploy_model(&client, lattice.clone(), model_name).await {
Ok(_) => undeployed.push(model_name),
Err(e) => eprintln!("failed to undeploy model [{model_name}]: {e}"),
}
Expand Down Expand Up @@ -338,7 +338,7 @@ async fn deploy_model(cmd: DeployCommand) -> Result<CommandOutput> {
app_manifest.version().map(ToString::to_string),
) {
if let Err(e) =
wash_lib::app::delete_model_version(&client, lattice.clone(), name, version).await
crate::lib::app::delete_model_version(&client, lattice.clone(), name, version).await
{
eprintln!("🟨 Failed to delete model during replace operation: {e}");
}
Expand All @@ -355,7 +355,7 @@ pub(crate) async fn deploy_model_from_manifest(
version: Option<String>,
) -> Result<CommandOutput> {
let (name, version) = match manifest {
AppManifest::SerializedModel(manifest) => wash_lib::app::put_and_deploy_model(
AppManifest::SerializedModel(manifest) => crate::lib::app::put_and_deploy_model(
client,
lattice,
serde_yaml::to_string(&manifest)
Expand All @@ -365,7 +365,7 @@ pub(crate) async fn deploy_model_from_manifest(
.await
.map(|(name, version)| (name, Some(version))),
AppManifest::ModelName(model_name) => {
wash_lib::app::deploy_model(client, lattice, &model_name, version.clone()).await
crate::lib::app::deploy_model(client, lattice, &model_name, version.clone()).await
}
}?;

Expand Down Expand Up @@ -393,7 +393,7 @@ async fn put_model(cmd: PutCommand) -> Result<CommandOutput> {
};

let (name, version) = match app_manifest {
AppManifest::SerializedModel(manifest) => wash_lib::app::put_model(
AppManifest::SerializedModel(manifest) => crate::lib::app::put_model(
&client,
lattice,
serde_yaml::to_string(&manifest)
Expand Down Expand Up @@ -424,7 +424,7 @@ async fn get_application_versions(cmd: HistoryCommand) -> Result<CommandOutput>

let client = connection_opts.into_nats_client().await?;

let versions = wash_lib::app::get_model_history(&client, lattice, &cmd.app_name).await?;
let versions = crate::lib::app::get_model_history(&client, lattice, &cmd.app_name).await?;
let mut map = HashMap::new();
map.insert("revisions".to_string(), json!(versions));
Ok(CommandOutput::new(
Expand All @@ -440,7 +440,7 @@ async fn get_model_status(cmd: StatusCommand) -> Result<CommandOutput> {

let client = connection_opts.into_nats_client().await?;

let status = wash_lib::app::get_model_status(&client, lattice, &cmd.app_name).await?;
let status = crate::lib::app::get_model_status(&client, lattice, &cmd.app_name).await?;

let mut map = HashMap::new();
map.insert("status".to_string(), json!(status));
Expand Down Expand Up @@ -502,7 +502,7 @@ async fn delete_application_version(cmd: DeleteCommand) -> Result<CommandOutput>
vec![(model_name, version)]
}
// If no model name was specified, use command-specified filters to determine which models to act on
None if cmd.all_undeployed => wash_lib::app::get_models(&client, lattice.clone())
None if cmd.all_undeployed => crate::lib::app::get_models(&client, lattice.clone())
.await?
.into_iter()
.filter_map(|m| match m.detailed_status.info.status_type {
Expand Down Expand Up @@ -578,7 +578,7 @@ async fn get_application_list(cmd: ListCommand, sp: &Spinner) -> Result<CommandO
HashMap::new(),
))
} else {
let models = wash_lib::app::get_models(&client, lattice).await?;
let models = crate::lib::app::get_models(&client, lattice).await?;
let mut map = HashMap::new();
map.insert("applications".to_string(), json!(models));
Ok(CommandOutput::new(output::list_models_table(models), map))
Expand Down
2 changes: 1 addition & 1 deletion crates/wash/src/cli/appearance/spinner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use std::borrow::Cow;

use anyhow::Result;
use indicatif::{ProgressBar, ProgressStyle};
use wash_lib::cli::OutputKind;
use crate::lib::cli::OutputKind;

// For more spinners check out the cli-spinners project:
// https://github.com/sindresorhus/cli-spinners/blob/master/spinners.json
Expand Down
6 changes: 3 additions & 3 deletions crates/wash/src/cli/cmd/config/delete.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
use std::collections::HashMap;

use crate::lib::cli::{CliConnectionOpts, CommandOutput, OutputKind};
use crate::lib::config::WashConnectionOptions;
use serde_json::json;
use wash_lib::cli::{CliConnectionOpts, CommandOutput, OutputKind};
use wash_lib::config::WashConnectionOptions;
use wasmcloud_secrets_types::SECRET_PREFIX;

use crate::appearance::spinner::Spinner;
use crate::errors::suggest_run_host_error;
use crate::cli::errors::suggest_run_host_error;
use crate::secrets::is_secret;

/// Invoke `wash config delete` (sub)command
Expand Down
4 changes: 2 additions & 2 deletions crates/wash/src/cli/cmd/config/get.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use crate::lib::cli::{CliConnectionOpts, CommandOutput, OutputKind};
use crate::lib::config::WashConnectionOptions;
use serde_json::json;
use tracing::error;
use wash_lib::cli::{CliConnectionOpts, CommandOutput, OutputKind};
use wash_lib::config::WashConnectionOptions;
use wasmcloud_secrets_types::SECRET_PREFIX;

use crate::appearance::spinner::Spinner;
Expand Down
2 changes: 1 addition & 1 deletion crates/wash/src/cli/cmd/config/mod.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
//! `wash config` related (sub)commands
use crate::lib::cli::{input_vec_to_hashmap, CliConnectionOpts, CommandOutput, OutputKind};
use clap::Subcommand;
use wash_lib::cli::{input_vec_to_hashmap, CliConnectionOpts, CommandOutput, OutputKind};

use crate::cmd;
use crate::secrets::ensure_not_secret;
Expand Down
4 changes: 2 additions & 2 deletions crates/wash/src/cli/cmd/config/put.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
use std::collections::HashMap;

use crate::lib::cli::{CliConnectionOpts, CommandOutput, OutputKind};
use crate::lib::config::WashConnectionOptions;
use serde_json::json;
use wash_lib::cli::{CliConnectionOpts, CommandOutput, OutputKind};
use wash_lib::config::WashConnectionOptions;
use wasmcloud_secrets_types::SECRET_PREFIX;

use crate::appearance::spinner::Spinner;
Expand Down
16 changes: 7 additions & 9 deletions crates/wash/src/cli/cmd/dev/deps.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@ use anyhow::{bail, Context as _, Result};
use semver::Version;
use tracing::{debug, trace};

use crate::lib::generate::emoji;
use crate::lib::parser::{
DevConfigSpec, DevSecretSpec, InterfaceComponentOverride, ProjectConfig, WitInterfaceSpec,
};
use wadm_types::{
CapabilityProperties, Component, ComponentProperties, ConfigProperty, LinkProperty, Manifest,
Metadata, Policy, Properties, SecretProperty, Specification, TargetConfig, TraitProperty,
};
use wash_lib::generate::emoji;
use wash_lib::parser::{
DevConfigSpec, DevSecretSpec, InterfaceComponentOverride, ProjectConfig, WitInterfaceSpec,
};
use wasmcloud_core::{parse_wit_package_name, LinkName, WitInterface, WitNamespace, WitPackage};

use super::manifest::config_name;
Expand Down Expand Up @@ -345,8 +345,7 @@ impl DependencySpec {
}))
}
// wasi:blobstore/blobstore -> blobstore-fs
(WIT_NS_WASI, Some(WIT_PKG_BLOBSTORE), Some(interface))
| (WIT_NS_WRPC, Some(WIT_PKG_BLOBSTORE), Some(interface))
(WIT_NS_WASI | WIT_NS_WRPC, Some(WIT_PKG_BLOBSTORE), Some(interface))
if matches!(interface, WIT_IFACE_BLOBSTORE) =>
{
Some(Self::Exports(DependencySpecInner {
Expand Down Expand Up @@ -1025,8 +1024,7 @@ impl ProjectDeps {
interfaces.as_ref(),
version,
) {
(WIT_NS_WASI, "blobstore", interfaces, _)
| (WIT_NS_WRPC, "blobstore", interfaces, _)
(WIT_NS_WASI | WIT_NS_WRPC, "blobstore", interfaces, _)
if interfaces.is_some_and(|interfaces| {
interfaces.iter().any(|i| i == "blobstore")
}) =>
Expand Down Expand Up @@ -1210,7 +1208,7 @@ impl ProjectDeps {
.context("failed to generate manifests")?
.into_iter()
{
wash_lib::app::delete_model_version(
crate::lib::app::delete_model_version(
client,
Some(lattice.into()),
&manifest.metadata.name,
Expand Down
20 changes: 10 additions & 10 deletions crates/wash/src/cli/cmd/dev/devloop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,20 @@ use std::collections::{BTreeSet, HashMap};
use std::path::PathBuf;

use crate::lib::app::AppManifest;
use crate::lib::cli::stop::stop_provider;
use crate::lib::component::{scale_component, ScaleComponentArgs};
use anyhow::{bail, ensure, Context as _, Result};
use console::style;
use tracing::{debug, warn};
use wash_lib::cli::stop::stop_provider;
use wash_lib::component::{scale_component, ScaleComponentArgs};
use wasmcloud_control_interface::Client as CtlClient;

use wadm_types::{ConfigProperty, Manifest, Properties, SecretProperty, SecretSourceProperty};
use wash_lib::build::{build_project, SignConfig};
use wash_lib::cli::{CommonPackageArgs, OutputKind};
use wash_lib::generate::emoji;
use wash_lib::parser::{
use crate::lib::build::{build_project, SignConfig};
use crate::lib::cli::{CommonPackageArgs, OutputKind};
use crate::lib::generate::emoji;
use crate::lib::parser::{
DevConfigSpec, DevManifestComponentTarget, DevSecretSpec, ProjectConfig, TypeConfig,
};
use wadm_types::{ConfigProperty, Manifest, Properties, SecretProperty, SecretSourceProperty};

use crate::app::deploy_model_from_manifest;
use crate::appearance::spinner::Spinner;
Expand Down Expand Up @@ -452,7 +452,7 @@ pub(crate) async fn run(state: &mut RunLoopState<'_>) -> Result<()> {
serde_json::to_string(&manifest).context("failed to convert manifest to JSON")?;

// Put the manifest
match wash_lib::app::put_model(
match crate::lib::app::put_model(
state.nats_client,
Some(state.lattice.to_string()),
&model_json,
Expand Down Expand Up @@ -522,7 +522,7 @@ async fn scale_down_component(
// Scale the WADM component (which can be either a component or provider) down,
// expecting that WADM should restore it (and trigger a reload)
match project_cfg.project_type {
wash_lib::parser::TypeConfig::Component(_) => {
crate::lib::parser::TypeConfig::Component(_) => {
scale_component(ScaleComponentArgs {
client,
host_id,
Expand All @@ -539,7 +539,7 @@ async fn scale_down_component(
format!("failed to scale down component [{component_id}] for reload")
})?;
}
wash_lib::parser::TypeConfig::Provider(_) => {
crate::lib::parser::TypeConfig::Provider(_) => {
if let Err(e) = stop_provider(
client,
Some(host_id),
Expand Down
10 changes: 5 additions & 5 deletions crates/wash/src/cli/cmd/dev/manifest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use wadm_types::{
SpreadScalerProperty, TraitProperty,
};

use wash_lib::{generate::emoji, parser::ProjectConfig};
use crate::lib::{generate::emoji, parser::ProjectConfig};

/// Generate the a configuration name for a dependency, given it's namespace and package
pub(crate) fn config_name(ns: &str, pkg: &str) -> String {
Expand Down Expand Up @@ -117,7 +117,7 @@ pub(crate) fn generate_component_from_project_cfg(
Ok(Component {
name: component_id.into(),
properties: match &cfg.project_type {
wash_lib::parser::TypeConfig::Component(_c) => Properties::Component {
crate::lib::parser::TypeConfig::Component(_c) => Properties::Component {
properties: ComponentProperties {
image: Some(image_ref.into()),
application: None,
Expand All @@ -126,7 +126,7 @@ pub(crate) fn generate_component_from_project_cfg(
secrets: Vec::with_capacity(0),
},
},
wash_lib::parser::TypeConfig::Provider(_p) => Properties::Capability {
crate::lib::parser::TypeConfig::Provider(_p) => Properties::Capability {
properties: CapabilityProperties {
image: Some(image_ref.into()),
application: None,
Expand All @@ -137,14 +137,14 @@ pub(crate) fn generate_component_from_project_cfg(
},
},
traits: match &cfg.project_type {
wash_lib::parser::TypeConfig::Component(_c) => Some(vec![wadm_types::Trait {
crate::lib::parser::TypeConfig::Component(_c) => Some(vec![wadm_types::Trait {
trait_type: "spreadscaler".into(),
properties: TraitProperty::SpreadScaler(SpreadScalerProperty {
instances: 100,
spread: Vec::new(),
}),
}]),
wash_lib::parser::TypeConfig::Provider(_p) => Some(vec![wadm_types::Trait {
crate::lib::parser::TypeConfig::Provider(_p) => Some(vec![wadm_types::Trait {
trait_type: "spreadscaler".into(),
properties: TraitProperty::SpreadScaler(SpreadScalerProperty {
instances: 1,
Expand Down
Loading

0 comments on commit a45be57

Please sign in to comment.