1mod cache;
2mod command;
3mod providers;
4
5use cache::Cache;
6use nu_plugin::{EngineInterface, Plugin};
7use nu_protocol::{ShellError, Span, Spanned};
8use object_store::path::Path;
9use providers::NuObjectStore;
10use tokio::runtime::Runtime;
11use url::Url;
12
13pub struct CloudPlugin {
14 pub cache: cache::Cache,
15 pub rt: Runtime,
16}
17
18impl Default for CloudPlugin {
19 fn default() -> Self {
20 CloudPlugin {
21 cache: Cache::default(),
22 rt: Runtime::new().expect("Could not create tokio runtime"),
23 }
24 }
25}
26
27impl CloudPlugin {
28 pub async fn parse_url(
29 &self,
30 engine: &EngineInterface,
31 url: &Spanned<Url>,
32 span: Span,
33 ) -> Result<(NuObjectStore, Path), ShellError> {
34 providers::parse_url(engine, &self.cache, url, span).await
35 }
36}
37
38impl Plugin for CloudPlugin {
39 fn version(&self) -> String {
40 env!("CARGO_PKG_VERSION").into()
41 }
42
43 fn commands(&self) -> Vec<Box<dyn nu_plugin::PluginCommand<Plugin = Self>>> {
44 command::commands()
45 }
46}