-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
## Changes 1. Extract functions to their respective files
- Loading branch information
Showing
4 changed files
with
119 additions
and
109 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,65 @@ | ||
use clap::Subcommand; | ||
use clap::{Parser, Subcommand}; | ||
use serde::Deserialize; | ||
|
||
use super::subcommands::{ | ||
application_info::GetApplicationInfo, process_definition::ProcessDefinition, | ||
}; | ||
use crate::clients::client_factory::ClientFactory; | ||
|
||
use super::subcommands; | ||
|
||
const DUMMY_TOKEN: &str = "Bearer ZHVtbXlfdG9rZW4="; | ||
const ENGINE_URL: &str = "http://localhost:10560"; | ||
|
||
#[derive(Parser, Debug)] | ||
#[command(author, version, about, long_about = None)] | ||
pub struct Cli { | ||
#[command(subcommand)] | ||
client: Client, | ||
|
||
#[clap(short, long, default_value = DUMMY_TOKEN)] | ||
token: String, | ||
|
||
#[clap(short, long, default_value = ENGINE_URL)] | ||
engine_url: String, | ||
} | ||
|
||
#[derive(Clone, Debug, Deserialize, Subcommand)] | ||
#[serde(rename_all = "kebab-case")] | ||
pub enum Client { | ||
/// Get information about the application. | ||
ApplicationInfo { get: GetApplicationInfo }, | ||
ApplicationInfo { | ||
cmd: subcommands::application_info::ApplicationInfoCommands, | ||
}, | ||
/// Trigger events. | ||
Event, | ||
/// Get all flow node instances. | ||
FlowNodeInstance, | ||
/// Handle Process Definitions. | ||
ProcessDefinition { | ||
#[clap(subcommand)] | ||
cmd: ProcessDefinition, | ||
cmd: subcommands::process_definition::ProcessDefinitionCommands, | ||
}, | ||
/// Handle Process Models. | ||
ProcessModel, | ||
} | ||
|
||
#[tokio::main] | ||
pub async fn register_commands(cli: Cli) { | ||
let client_factory = ClientFactory::new(&cli.engine_url, &cli.token); | ||
|
||
match cli.client { | ||
Client::ApplicationInfo { cmd } => { | ||
subcommands::application_info::register_commands(client_factory, cmd).await | ||
} | ||
Client::Event => { | ||
println!("Event"); | ||
} | ||
Client::FlowNodeInstance => { | ||
println!("FlowNodeInstance"); | ||
} | ||
Client::ProcessDefinition { cmd } => { | ||
subcommands::process_definition::register_commands(client_factory, cmd).await | ||
} | ||
Client::ProcessModel => { | ||
println!("ProcessModel"); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,27 @@ | ||
use clap::ValueEnum; | ||
use serde::Deserialize; | ||
|
||
use crate::clients::client_factory::ClientFactory; | ||
|
||
#[derive(Clone, Debug, Deserialize, ValueEnum)] | ||
#[serde(rename_all = "kebab-case")] | ||
pub enum GetApplicationInfo { | ||
pub enum ApplicationInfoCommands { | ||
/// Gets some basic info about the host application. | ||
Info, | ||
GetInfo, | ||
/// Gets the address of the authority that the host application uses for claim checks. | ||
Authority, | ||
GetAuthority, | ||
} | ||
|
||
pub async fn register_commands(client_factory: ClientFactory, get: ApplicationInfoCommands) { | ||
let client = client_factory.create_application_info_client(); | ||
match get { | ||
ApplicationInfoCommands::GetInfo => match client.get_application_info().await { | ||
Ok(info) => println!("{:#?}", info), | ||
Err(e) => eprintln!("Error getting application info: {:#?}", e), | ||
}, | ||
ApplicationInfoCommands::GetAuthority => match client.get_authority_info().await { | ||
Ok(authority) => println!("{:#?}", authority), | ||
Err(e) => eprintln!("Error getting authority: {:#?}", e), | ||
}, | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,105 +1,8 @@ | ||
use clap::Parser; | ||
|
||
use processcube_engine_client::{ | ||
cli::{ | ||
client::Client, | ||
subcommands::{ | ||
application_info::GetApplicationInfo, process_definition::ProcessDefinition, | ||
}, | ||
}, | ||
clients::{ | ||
client_factory::ClientFactory, | ||
process_definition::process_definition::PersistProcessDefinitionPayload, | ||
}, | ||
}; | ||
|
||
const DUMMY_TOKEN: &str = "Bearer ZHVtbXlfdG9rZW4="; | ||
const ENGINE_URL: &str = "http://localhost:10560"; | ||
|
||
#[derive(Parser, Debug)] | ||
#[command(author, version, about, long_about = None)] | ||
struct Cli { | ||
#[command(subcommand)] | ||
client: Client, | ||
|
||
#[clap(short, long, default_value = DUMMY_TOKEN)] | ||
token: String, | ||
|
||
#[clap(short, long, default_value = ENGINE_URL)] | ||
engine_url: String, | ||
} | ||
use processcube_engine_client::cli::client::{register_commands, Cli}; | ||
|
||
#[tokio::main] | ||
async fn main() -> () { | ||
let cli = Cli::parse(); | ||
let client_factory = ClientFactory::new(&cli.engine_url, &cli.token); | ||
|
||
match cli.client { | ||
Client::ApplicationInfo { get } => { | ||
let client = client_factory.create_application_info_client(); | ||
match get { | ||
GetApplicationInfo::Info => match client.get_application_info().await { | ||
Ok(info) => println!("{:#?}", info), | ||
Err(e) => eprintln!("Error getting application info: {:#?}", e), | ||
}, | ||
GetApplicationInfo::Authority => match client.get_authority_info().await { | ||
Ok(authority) => println!("{:#?}", authority), | ||
Err(e) => eprintln!("Error getting authority: {:#?}", e), | ||
}, | ||
} | ||
} | ||
Client::Event => { | ||
println!("Event"); | ||
} | ||
Client::FlowNodeInstance => { | ||
println!("FlowNodeInstance"); | ||
} | ||
Client::ProcessDefinition { cmd } => { | ||
let client = client_factory.create_process_definition_client(); | ||
|
||
match cmd { | ||
ProcessDefinition::GetAll => { | ||
match client.get_process_definitions(None, None).await { | ||
Ok(process_definitions) => println!("{:#?}", process_definitions), | ||
Err(e) => eprintln!("Error getting process definitions: {:#?}", e), | ||
} | ||
} | ||
ProcessDefinition::GetById { id } => { | ||
match client.get_process_definition_by_id(&id).await { | ||
Ok(process_definition) => println!("{:#?}", process_definition), | ||
Err(e) => eprintln!("Error getting process definition: {:#?}", e), | ||
} | ||
} | ||
ProcessDefinition::Post { | ||
xml, | ||
overwrite_existing, | ||
} => { | ||
let request = PersistProcessDefinitionPayload { | ||
xml, | ||
overwrite_existing: match overwrite_existing { | ||
Some(overwrite_existing) => overwrite_existing, | ||
None => false, | ||
}, | ||
}; | ||
match client.upload_process_definition(request).await { | ||
Ok(_) => println!("Process definition uploaded"), | ||
Err(e) => eprintln!("Error uploading process definition: {:#?}", e), | ||
} | ||
} | ||
ProcessDefinition::Delete { | ||
id, | ||
delete_all_related_data, | ||
} => match client | ||
.delete_process_definition_by_id(&id, delete_all_related_data) | ||
.await | ||
{ | ||
Ok(_) => println!("Process definition deleted"), | ||
Err(e) => eprintln!("Error deleting process definition: {:#?}", e), | ||
}, | ||
} | ||
} | ||
Client::ProcessModel => { | ||
println!("ProcessModel"); | ||
} | ||
} | ||
register_commands(cli); | ||
} |