Skip to content

Commit 9a6576d

Browse files
committed
refactor: Move command execution to run functions
1 parent ee47b74 commit 9a6576d

5 files changed

Lines changed: 188 additions & 161 deletions

File tree

src/command/component.rs

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,59 @@
11
use crate::FunctionMetadataVerbosity;
22
use crate::FunctionRepositoryClient;
3+
use crate::args;
4+
use crate::get_fn_repository_client;
5+
use crate::oci;
36
use anyhow::Context;
47
use concepts::ComponentType;
58
use concepts::{FunctionFqn, FunctionMetadata};
69
use grpc::grpc_gen;
710
use std::path::PathBuf;
811
use utils::wasm_tools::WasmComponent;
912

13+
impl args::Component {
14+
pub(crate) async fn run(self, api_url: &str) -> Result<(), anyhow::Error> {
15+
match self {
16+
args::Component::Inspect {
17+
path,
18+
component_type,
19+
imports,
20+
extensions,
21+
convert_core_module,
22+
} => {
23+
inspect(
24+
path,
25+
component_type,
26+
if imports {
27+
FunctionMetadataVerbosity::ExportsAndImports
28+
} else {
29+
FunctionMetadataVerbosity::ExportsOnly
30+
},
31+
extensions,
32+
convert_core_module,
33+
)
34+
.await
35+
}
36+
args::Component::List {
37+
imports,
38+
extensions,
39+
} => {
40+
let client = get_fn_repository_client(api_url).await?;
41+
list_components(
42+
client,
43+
if imports {
44+
FunctionMetadataVerbosity::ExportsAndImports
45+
} else {
46+
FunctionMetadataVerbosity::ExportsOnly
47+
},
48+
extensions,
49+
)
50+
.await
51+
}
52+
args::Component::Push { path, image_name } => oci::push(path, &image_name).await,
53+
}
54+
}
55+
}
56+
1057
pub(crate) async fn inspect(
1158
wasm_path: PathBuf,
1259
component_type: ComponentType,

src/command/execution.rs

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
use crate::ExecutionRepositoryClient;
2+
use crate::args;
3+
use crate::args::params::parse_params;
4+
use crate::get_execution_repository_client;
25
use crate::get_fn_repository_client;
36
use anyhow::bail;
47
use chrono::DateTime;
@@ -15,6 +18,54 @@ use serde_json::json;
1518
use std::time::Duration;
1619
use tracing::instrument;
1720

21+
impl args::Execution {
22+
pub(crate) async fn run(self, api_url: &str) -> Result<(), anyhow::Error> {
23+
match self {
24+
args::Execution::Submit {
25+
ffqn,
26+
params,
27+
follow,
28+
json,
29+
no_reconnect,
30+
} => {
31+
let client = get_execution_repository_client(api_url).await?;
32+
let opts = if json {
33+
SubmitOutputOpts::Json
34+
} else {
35+
SubmitOutputOpts::Plain { no_reconnect }
36+
};
37+
submit(client, ffqn, parse_params(params)?, follow, opts, api_url).await
38+
}
39+
args::Execution::Stub(args::Stub {
40+
execution_id,
41+
return_value,
42+
}) => {
43+
let client = get_execution_repository_client(api_url).await?;
44+
stub(client, execution_id, return_value).await
45+
}
46+
args::Execution::Get {
47+
execution_id,
48+
follow,
49+
no_reconnect,
50+
} => {
51+
let client = get_execution_repository_client(api_url).await?;
52+
let opts = GetStatusOptions {
53+
follow,
54+
no_reconnect,
55+
};
56+
get_status(client, execution_id, opts).await
57+
}
58+
args::Execution::GetJson {
59+
follow,
60+
execution_id,
61+
} => {
62+
let client = get_execution_repository_client(api_url).await?;
63+
get_status_json(client, execution_id, follow, false).await
64+
}
65+
}
66+
}
67+
}
68+
1869
#[derive(PartialEq)]
1970
pub(crate) enum SubmitOutputOpts {
2071
Json,

src/command/generate.rs

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
use crate::args::Generate;
12
use crate::{args::shadow::PKG_VERSION, config::toml::ConfigToml};
23
use anyhow::Context;
34
use concepts::ComponentType;
@@ -10,6 +11,30 @@ use std::{
1011
};
1112
use utils::{wasm_tools::WasmComponent, wit};
1213

14+
impl Generate {
15+
pub(crate) async fn run(self) -> Result<(), anyhow::Error> {
16+
match self {
17+
Generate::ConfigSchema { output } => generate_toml_schema(output),
18+
Generate::Extensions {
19+
component_type,
20+
input_wit_directory,
21+
output_directory,
22+
} => {
23+
generate_exported_extension_wits(
24+
input_wit_directory,
25+
output_directory,
26+
component_type,
27+
)
28+
.await
29+
}
30+
Generate::WitSupport {
31+
component_type,
32+
output_directory,
33+
} => generate_support_wits(component_type, output_directory).await,
34+
}
35+
}
36+
}
37+
1338
pub(crate) fn generate_toml_schema(output: Option<PathBuf>) -> Result<(), anyhow::Error> {
1439
let schema = schema_for!(ConfigToml);
1540
if let Some(output) = output {

src/command/server.rs

Lines changed: 52 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
use crate::args::Server;
12
use crate::config::ComponentConfig;
23
use crate::config::ComponentConfigImportable;
34
use crate::config::ComponentLocation;
@@ -26,6 +27,7 @@ use crate::config::toml::webhook::WebhookRoute;
2627
use crate::config::toml::webhook::WebhookRouteVerified;
2728
use crate::init;
2829
use crate::init::Guard;
30+
use crate::project_dirs;
2931
use anyhow::Context;
3032
use anyhow::bail;
3133
use chrono::DateTime;
@@ -144,6 +146,55 @@ const GET_STATUS_POLLING_SLEEP: Duration = Duration::from_secs(1);
144146

145147
type ComponentSourceMap = hashbrown::HashMap<ComponentId, MatchableSourceMap>;
146148

149+
impl Server {
150+
pub(crate) async fn run(self) -> Result<(), anyhow::Error> {
151+
match self {
152+
Server::Run {
153+
clean_sqlite_directory,
154+
clean_cache,
155+
clean_codegen_cache,
156+
config,
157+
} => {
158+
Box::pin(run(
159+
project_dirs(),
160+
BaseDirs::new(),
161+
config,
162+
RunParams {
163+
clean_sqlite_directory,
164+
clean_cache,
165+
clean_codegen_cache,
166+
},
167+
))
168+
.await
169+
}
170+
Server::GenerateConfig => {
171+
let obelisk_toml = PathBuf::from("obelisk.toml");
172+
ConfigHolder::generate_default_config(&obelisk_toml).await?;
173+
println!("Generated {obelisk_toml:?}");
174+
Ok(())
175+
}
176+
Server::Verify {
177+
clean_cache,
178+
clean_codegen_cache,
179+
config,
180+
ignore_missing_env_vars,
181+
} => {
182+
verify(
183+
project_dirs(),
184+
BaseDirs::new(),
185+
config,
186+
VerifyParams {
187+
clean_cache,
188+
clean_codegen_cache,
189+
ignore_missing_env_vars,
190+
},
191+
)
192+
.await
193+
}
194+
}
195+
}
196+
}
197+
147198
#[derive(derive_more::Debug)]
148199
struct GrpcServer {
149200
#[debug(skip)]
@@ -2543,8 +2594,8 @@ impl MatchableSourceMap {
25432594
#[cfg(test)]
25442595
mod tests {
25452596
use crate::{
2546-
ConfigHolder,
25472597
command::server::{ServerCompiledLinked, ServerVerified, VerifyParams},
2598+
config::config_holder::ConfigHolder,
25482599
};
25492600
use directories::BaseDirs;
25502601
use rstest::rstest;

0 commit comments

Comments
 (0)