diff --git a/.rustfmt.toml b/.rustfmt.toml new file mode 100644 index 0000000..d5abb48 --- /dev/null +++ b/.rustfmt.toml @@ -0,0 +1,5 @@ +normalize_comments = true +reorder_imports = true +group_imports = "StdExternalCrate" +newline_style = "Unix" +imports_granularity = "Module" \ No newline at end of file diff --git a/src/account.rs b/src/account.rs index 6fb18b5..10d2bd9 100644 --- a/src/account.rs +++ b/src/account.rs @@ -1,10 +1,11 @@ +use async_trait::async_trait; +use clap::Subcommand; +use golem_client::model::AccountData; + use crate::clients::account::AccountClient; use crate::clients::grant::GrantClient; use crate::clients::CloudAuthentication; use crate::model::{AccountId, GolemError, GolemResult, Role}; -use async_trait::async_trait; -use clap::Subcommand; -use golem_client::model::AccountData; #[derive(Subcommand, Debug)] #[command()] diff --git a/src/auth.rs b/src/auth.rs index 67f1107..e8ba4a2 100644 --- a/src/auth.rs +++ b/src/auth.rs @@ -1,17 +1,19 @@ -use crate::clients::login::LoginClient; -use crate::clients::CloudAuthentication; -use crate::model::GolemError; +use std::fs::{create_dir_all, File, OpenOptions}; +use std::io::{BufReader, BufWriter}; +use std::path::{Path, PathBuf}; + use async_trait::async_trait; use chrono::{DateTime, Utc}; use golem_client::model::{OAuth2Data, Token, TokenSecret, UnsafeToken}; use indoc::printdoc; use serde::{Deserialize, Serialize}; -use std::fs::{create_dir_all, File, OpenOptions}; -use std::io::{BufReader, BufWriter}; -use std::path::{Path, PathBuf}; use tracing::info; use uuid::Uuid; +use crate::clients::login::LoginClient; +use crate::clients::CloudAuthentication; +use crate::model::GolemError; + #[async_trait] pub trait Auth { async fn authenticate( diff --git a/src/clients.rs b/src/clients.rs index c499d00..3782748 100644 --- a/src/clients.rs +++ b/src/clients.rs @@ -1,6 +1,7 @@ -use crate::model::{AccountId, ProjectAction}; use golem_client::model::{TokenSecret, UnsafeToken}; +use crate::model::{AccountId, ProjectAction}; + pub mod account; pub mod grant; pub mod login; diff --git a/src/clients/account.rs b/src/clients/account.rs index b32e79c..a06b79e 100644 --- a/src/clients/account.rs +++ b/src/clients/account.rs @@ -1,9 +1,10 @@ -use crate::clients::CloudAuthentication; -use crate::model::{AccountId, GolemError}; use async_trait::async_trait; use golem_client::model::{Account, AccountData, Plan}; use tracing::info; +use crate::clients::CloudAuthentication; +use crate::model::{AccountId, GolemError}; + #[async_trait] pub trait AccountClient { async fn get(&self, id: &AccountId, auth: &CloudAuthentication) -> Result; diff --git a/src/clients/grant.rs b/src/clients/grant.rs index 2a4ca10..f494862 100644 --- a/src/clients/grant.rs +++ b/src/clients/grant.rs @@ -1,9 +1,9 @@ -use crate::clients::CloudAuthentication; -use crate::model::Role; -use crate::model::{AccountId, GolemError}; use async_trait::async_trait; use tracing::info; +use crate::clients::CloudAuthentication; +use crate::model::{AccountId, GolemError, Role}; + #[async_trait] pub trait GrantClient { async fn get_all( diff --git a/src/clients/login.rs b/src/clients/login.rs index 3dbf9ca..a25babf 100644 --- a/src/clients/login.rs +++ b/src/clients/login.rs @@ -1,10 +1,11 @@ -use crate::clients::token_header; -use crate::model::GolemError; use async_trait::async_trait; use golem_client::login::Login; use golem_client::model::{OAuth2Data, Token, TokenSecret, UnsafeToken}; use tracing::info; +use crate::clients::token_header; +use crate::model::GolemError; + #[async_trait] pub trait LoginClient { async fn token_details(&self, manual_token: TokenSecret) -> Result; diff --git a/src/clients/policy.rs b/src/clients/policy.rs index a9f270a..b6d5bf3 100644 --- a/src/clients/policy.rs +++ b/src/clients/policy.rs @@ -1,10 +1,12 @@ -use crate::clients::{action_cli_to_api, CloudAuthentication}; -use crate::model::{GolemError, ProjectAction, ProjectPolicyId}; +use std::collections::HashSet; + use async_trait::async_trait; use golem_client::model::{ProjectActions, ProjectPolicy, ProjectPolicyData}; -use std::collections::HashSet; use tracing::info; +use crate::clients::{action_cli_to_api, CloudAuthentication}; +use crate::model::{GolemError, ProjectAction, ProjectPolicyId}; + #[async_trait] pub trait ProjectPolicyClient { async fn create( diff --git a/src/clients/project.rs b/src/clients/project.rs index 15bc2eb..5897b5a 100644 --- a/src/clients/project.rs +++ b/src/clients/project.rs @@ -1,10 +1,11 @@ -use crate::clients::CloudAuthentication; -use crate::model::{GolemError, ProjectId, ProjectRef}; use async_trait::async_trait; use golem_client::model::{Project, ProjectDataRequest}; use indoc::formatdoc; use tracing::info; +use crate::clients::CloudAuthentication; +use crate::model::{GolemError, ProjectId, ProjectRef}; + #[async_trait] pub trait ProjectClient { async fn create( diff --git a/src/clients/project_grant.rs b/src/clients/project_grant.rs index 6927db7..1c76337 100644 --- a/src/clients/project_grant.rs +++ b/src/clients/project_grant.rs @@ -1,11 +1,12 @@ -use crate::clients::{action_cli_to_api, CloudAuthentication}; -use crate::model::{AccountId, GolemError, ProjectAction, ProjectId, ProjectPolicyId}; use async_trait::async_trait; use golem_client::model::{ ProjectGrant, ProjectGrantDataRequest, ProjectGrantDataWithProjectActions, }; use tracing::info; +use crate::clients::{action_cli_to_api, CloudAuthentication}; +use crate::model::{AccountId, GolemError, ProjectAction, ProjectId, ProjectPolicyId}; + #[async_trait] pub trait ProjectGrantClient { async fn create( diff --git a/src/clients/template.rs b/src/clients/template.rs index 118a2cb..98bb9c7 100644 --- a/src/clients/template.rs +++ b/src/clients/template.rs @@ -1,15 +1,17 @@ -use crate::clients::CloudAuthentication; -use crate::model::{GolemError, TemplateName}; -use crate::{ProjectId, RawTemplateId}; +use std::path::PathBuf; + use async_trait::async_trait; use golem_client::model::{ Component, ComponentQuery, Export, FunctionParameter, FunctionResult, Type, }; use serde::Serialize; -use std::path::PathBuf; use tokio::fs::File; use tracing::info; +use crate::clients::CloudAuthentication; +use crate::model::{GolemError, TemplateName}; +use crate::{ProjectId, RawTemplateId}; + #[async_trait] pub trait TemplateClient { async fn find( diff --git a/src/clients/token.rs b/src/clients/token.rs index 9476325..cd8d7a4 100644 --- a/src/clients/token.rs +++ b/src/clients/token.rs @@ -1,5 +1,3 @@ -use crate::clients::CloudAuthentication; -use crate::model::{AccountId, GolemError, TokenId}; use async_trait::async_trait; use chrono::{DateTime, Utc}; use golem_client::model; @@ -7,6 +5,9 @@ use golem_client::model::{CreateTokenDTO, UnsafeToken}; use golem_client::token::Token; use tracing::info; +use crate::clients::CloudAuthentication; +use crate::model::{AccountId, GolemError, TokenId}; + #[async_trait] pub trait TokenClient { async fn get_all( diff --git a/src/clients/worker.rs b/src/clients/worker.rs index 254b4d7..6409c61 100644 --- a/src/clients/worker.rs +++ b/src/clients/worker.rs @@ -1,6 +1,6 @@ -use crate::clients::CloudAuthentication; -use crate::model::{GolemError, InvocationKey, RawTemplateId}; -use crate::WorkerName; +use std::fmt::{Display, Formatter}; +use std::time::Duration; + use async_trait::async_trait; use futures_util::{future, pin_mut, SinkExt, StreamExt}; use golem_client::model::{ @@ -9,15 +9,16 @@ use golem_client::model::{ use native_tls::TlsConnector; use reqwest::Url; use serde::Deserialize; -use std::fmt::{Display, Formatter}; -use std::time::Duration; use tokio::{task, time}; -use tokio_tungstenite::{ - connect_async_tls_with_config, tungstenite::client::IntoClientRequest, - tungstenite::protocol::Message, Connector, -}; +use tokio_tungstenite::tungstenite::client::IntoClientRequest; +use tokio_tungstenite::tungstenite::protocol::Message; +use tokio_tungstenite::{connect_async_tls_with_config, Connector}; use tracing::{debug, info}; +use crate::clients::CloudAuthentication; +use crate::model::{GolemError, InvocationKey, RawTemplateId}; +use crate::WorkerName; + #[async_trait] pub trait WorkerClient { async fn new_worker( diff --git a/src/examples.rs b/src/examples.rs index df31756..2a2d45a 100644 --- a/src/examples.rs +++ b/src/examples.rs @@ -1,10 +1,12 @@ -use crate::model::{ExampleDescription, GolemError}; -use crate::GolemResult; +use std::env; + use golem_examples::model::{ ExampleName, ExampleParameters, GuestLanguage, GuestLanguageTier, PackageName, TemplateName, }; use golem_examples::*; -use std::env; + +use crate::model::{ExampleDescription, GolemError}; +use crate::GolemResult; pub fn process_new( example_name: ExampleName, diff --git a/src/main.rs b/src/main.rs index 61718ee..7717852 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,5 +1,8 @@ extern crate derive_more; +use std::fmt::Debug; +use std::path::PathBuf; + use clap::builder::ValueParser; use clap::{Parser, Subcommand}; use clap_verbosity_flag::Verbosity; @@ -10,8 +13,10 @@ use golem_client::model::{ComponentInstance, InvokeParameters}; use golem_client::project::ProjectLive; use golem_client::project_grant::ProjectGrantLive; use golem_client::project_policy::ProjectPolicyLive; -use std::fmt::Debug; -use std::path::PathBuf; +use golem_examples::model::{ExampleName, GuestLanguage, GuestLanguageTier, PackageName}; +use model::*; +use reqwest::Url; +use serde::Serialize; use uuid::Uuid; use crate::account::{AccountHandler, AccountHandlerLive, AccountSubcommand}; @@ -33,10 +38,6 @@ use crate::project_grant::{ProjectGrantHandler, ProjectGrantHandlerLive}; use crate::template::{TemplateHandler, TemplateHandlerLive, TemplateSubcommand}; use crate::token::{TokenHandler, TokenHandlerLive, TokenSubcommand}; use crate::worker::{WorkerHandler, WorkerHandlerLive, WorkerSubcommand}; -use golem_examples::model::{ExampleName, GuestLanguage, GuestLanguageTier, PackageName}; -use model::*; -use reqwest::Url; -use serde::Serialize; mod account; mod auth; diff --git a/src/model.rs b/src/model.rs index 7dac810..890b041 100644 --- a/src/model.rs +++ b/src/model.rs @@ -1,5 +1,6 @@ use std::ffi::OsStr; use std::fmt::{Debug, Display, Formatter}; +use std::str::FromStr; use clap::builder::{StringValueParser, TypedValueParser}; use clap::error::{ContextKind, ContextValue, ErrorKind}; @@ -17,7 +18,6 @@ use golem_client::token::TokenError; use golem_examples::model::{Example, ExampleName, GuestLanguage, GuestLanguageTier}; use indoc::indoc; use serde::{Deserialize, Serialize}; -use std::str::FromStr; use strum::IntoEnumIterator; use strum_macros::EnumIter; use uuid::Uuid; diff --git a/src/policy.rs b/src/policy.rs index 4733bff..66754fe 100644 --- a/src/policy.rs +++ b/src/policy.rs @@ -1,8 +1,9 @@ +use async_trait::async_trait; +use clap::Subcommand; + use crate::clients::policy::ProjectPolicyClient; use crate::clients::CloudAuthentication; use crate::model::{GolemError, GolemResult, ProjectAction, ProjectPolicyId}; -use async_trait::async_trait; -use clap::Subcommand; #[derive(Subcommand, Debug)] #[command()] diff --git a/src/project.rs b/src/project.rs index f4aa9c4..3f107bb 100644 --- a/src/project.rs +++ b/src/project.rs @@ -1,8 +1,9 @@ +use async_trait::async_trait; +use clap::Subcommand; + use crate::clients::project::ProjectClient; use crate::clients::CloudAuthentication; use crate::model::{GolemError, GolemResult}; -use async_trait::async_trait; -use clap::Subcommand; #[derive(Subcommand, Debug)] #[command()] diff --git a/src/project_grant.rs b/src/project_grant.rs index 2a1a2c1..9d75188 100644 --- a/src/project_grant.rs +++ b/src/project_grant.rs @@ -1,10 +1,11 @@ +use async_trait::async_trait; + use crate::clients::project::ProjectClient; use crate::clients::project_grant::ProjectGrantClient; use crate::clients::CloudAuthentication; use crate::model::{ AccountId, GolemError, GolemResult, ProjectAction, ProjectId, ProjectPolicyId, ProjectRef, }; -use async_trait::async_trait; #[async_trait] pub trait ProjectGrantHandler { diff --git a/src/template.rs b/src/template.rs index 673749d..3a55ea9 100644 --- a/src/template.rs +++ b/src/template.rs @@ -1,15 +1,17 @@ +use std::path::PathBuf; + +use async_trait::async_trait; +use clap::Subcommand; +use indoc::formatdoc; +use itertools::Itertools; +use uuid::Uuid; + use crate::clients::project::ProjectClient; use crate::clients::template::{TemplateClient, TemplateView}; use crate::clients::CloudAuthentication; use crate::model::{ GolemError, GolemResult, ProjectId, ProjectRef, RawTemplateId, TemplateIdOrName, TemplateName, }; -use async_trait::async_trait; -use clap::Subcommand; -use indoc::formatdoc; -use itertools::Itertools; -use std::path::PathBuf; -use uuid::Uuid; #[derive(Subcommand, Debug)] #[command()] diff --git a/src/token.rs b/src/token.rs index 752c190..392ce54 100644 --- a/src/token.rs +++ b/src/token.rs @@ -1,10 +1,11 @@ -use crate::clients::token::TokenClient; -use crate::clients::CloudAuthentication; -use crate::model::{AccountId, GolemError, GolemResult, TokenId}; use async_trait::async_trait; use chrono::{DateTime, Utc}; use clap::Subcommand; +use crate::clients::token::TokenClient; +use crate::clients::CloudAuthentication; +use crate::model::{AccountId, GolemError, GolemResult, TokenId}; + fn parse_instant( s: &str, ) -> Result, Box> { diff --git a/src/worker.rs b/src/worker.rs index e6fe80c..ec9ff46 100644 --- a/src/worker.rs +++ b/src/worker.rs @@ -1,3 +1,8 @@ +use async_trait::async_trait; +use clap::builder::ValueParser; +use clap::Subcommand; +use golem_client::model::InvokeParameters; + use crate::clients::worker::WorkerClient; use crate::clients::CloudAuthentication; use crate::model::{ @@ -5,10 +10,6 @@ use crate::model::{ }; use crate::parse_key_val; use crate::template::TemplateHandler; -use async_trait::async_trait; -use clap::builder::ValueParser; -use clap::Subcommand; -use golem_client::model::InvokeParameters; #[derive(Subcommand, Debug)] #[command()]