Skip to content

Commit

Permalink
chore(tui): main refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
wolf4ood committed Sep 23, 2024
1 parent 5b6cbe9 commit 3c15ecb
Showing 1 changed file with 26 additions and 18 deletions.
44 changes: 26 additions & 18 deletions edc-connector-tui/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,24 +19,7 @@ async fn main() -> anyhow::Result<()> {

let app = match cli.mode {
Some(Commands::Connector { url, name, token }) => {
let auth = token.map(Auth::api_token).unwrap_or_else(|| Auth::NoAuth);
let client = EdcConnectorClient::builder()
.management_url(url.clone())
.with_auth(auth)
.build()
.unwrap();

let cfg = ConnectorConfig::new(
name.unwrap_or_else(|| url.clone()),
url,
config::AuthKind::Token {
token_alias: "unknown".to_string(),
},
);

let connector = Connector::new(cfg, client, ConnectorStatus::Connected);

App::init_with_connectors(vec![connector])
init_app_single_connector(url, name, token).await
}
None => {
let config = Config::parse(&cli.config.map(Ok).unwrap_or_else(default_file)?)?;
Expand All @@ -49,6 +32,31 @@ async fn main() -> anyhow::Result<()> {
Ok(())
}

async fn init_app_single_connector(
url: String,
name: Option<String>,
token: Option<String>,
) -> App {
let auth = token.map(Auth::api_token).unwrap_or_else(|| Auth::NoAuth);
let client = EdcConnectorClient::builder()
.management_url(url.clone())
.with_auth(auth)
.build()
.unwrap();

let cfg = ConnectorConfig::new(
name.unwrap_or_else(|| url.clone()),
url,
config::AuthKind::Token {
token_alias: "unknown".to_string(),
},
);

let connector = Connector::new(cfg, client, ConnectorStatus::Connected);

App::init_with_connectors(vec![connector])
}

mod tui {
use crossterm::{
terminal::{disable_raw_mode, enable_raw_mode, EnterAlternateScreen, LeaveAlternateScreen},
Expand Down

0 comments on commit 3c15ecb

Please sign in to comment.