mirror of
https://github.com/mii443/wasmer.git
synced 2025-12-13 13:58:38 +00:00
Fix formatting issues
This commit is contained in:
committed by
Christoph Herzog
parent
011e494e29
commit
52b04d5806
@@ -11,9 +11,9 @@ use url::Url;
|
||||
use crate::{
|
||||
types::{
|
||||
self, CreateNamespaceVars, DeployApp, DeployAppConnection, DeployAppVersion,
|
||||
DeployAppVersionConnection, GetCurrentUserWithAppsVars, GetDeployAppAndVersion,
|
||||
DeployAppVersionConnection, DnsDomain, GetCurrentUserWithAppsVars, GetDeployAppAndVersion,
|
||||
GetDeployAppVersionsVars, GetNamespaceAppsVars, Log, LogStream, PackageVersionConnection,
|
||||
PublishDeployAppVars, UpsertDomainFromZoneFileVars, DnsDomain,
|
||||
PublishDeployAppVars, UpsertDomainFromZoneFileVars,
|
||||
},
|
||||
GraphQLApiFailure, WasmerClient,
|
||||
};
|
||||
@@ -850,7 +850,6 @@ pub async fn get_domain_zone_file(
|
||||
Ok(opt)
|
||||
}
|
||||
|
||||
|
||||
/// Retrieve a domain by its name, along with all it's records.
|
||||
pub async fn get_domain_with_records(
|
||||
client: &WasmerClient,
|
||||
@@ -892,7 +891,6 @@ pub async fn get_all_domains(
|
||||
.map(|x| x.get_all_domains)
|
||||
}
|
||||
|
||||
|
||||
/// Retrieve a domain by its name.
|
||||
///
|
||||
/// Specify with_records to also retrieve all records for the domain.
|
||||
|
||||
@@ -1225,7 +1225,6 @@ mod queries {
|
||||
pub zone_file: String,
|
||||
}
|
||||
|
||||
|
||||
#[derive(cynic::QueryFragment, Debug, Clone, Serialize)]
|
||||
#[cynic(graphql_type = "DNSDomain")]
|
||||
pub struct DnsDomainWithRecords {
|
||||
@@ -1235,7 +1234,6 @@ mod queries {
|
||||
pub records: Option<Vec<Option<DnsRecord>>>,
|
||||
}
|
||||
|
||||
|
||||
#[derive(cynic::Scalar, Debug, Clone)]
|
||||
pub struct BigInt(pub u64);
|
||||
|
||||
|
||||
@@ -21,7 +21,8 @@ impl AsyncCliCommand for CmdDomainGet {
|
||||
|
||||
async fn run_async(self) -> Result<(), anyhow::Error> {
|
||||
let client = self.api.client()?;
|
||||
if let Some(domain) = wasmer_api::query::get_domain_with_records(&client, self.name).await? {
|
||||
if let Some(domain) = wasmer_api::query::get_domain_with_records(&client, self.name).await?
|
||||
{
|
||||
println!("{}", self.fmt.format.render(&domain));
|
||||
} else {
|
||||
println!("Domain not found");
|
||||
|
||||
@@ -23,13 +23,23 @@ impl AsyncCliCommand for CmdDomainList {
|
||||
|
||||
async fn run_async(self) -> Result<(), anyhow::Error> {
|
||||
let client = self.api.client()?;
|
||||
let domains_connection = wasmer_api::query::get_all_domains(&client, GetAllDomainsVariables {
|
||||
first: None, after: None, namespace: self.namespace,
|
||||
}).await?;
|
||||
let domains_connection = wasmer_api::query::get_all_domains(
|
||||
&client,
|
||||
GetAllDomainsVariables {
|
||||
first: None,
|
||||
after: None,
|
||||
namespace: self.namespace,
|
||||
},
|
||||
)
|
||||
.await?;
|
||||
let domains = domains_connection
|
||||
.edges
|
||||
.into_iter()
|
||||
.map(|edge| edge.expect("domain not found").node.expect("domain not found"))
|
||||
.map(|edge| {
|
||||
edge.expect("domain not found")
|
||||
.node
|
||||
.expect("domain not found")
|
||||
})
|
||||
.collect::<Vec<_>>();
|
||||
println!("{}", self.fmt.format.render(&domains));
|
||||
Ok(())
|
||||
|
||||
@@ -1,10 +1,9 @@
|
||||
pub mod list;
|
||||
pub mod get;
|
||||
pub mod list;
|
||||
pub mod zonefile;
|
||||
|
||||
use crate::commands::AsyncCliCommand;
|
||||
|
||||
|
||||
/// Manage DNS records
|
||||
#[derive(clap::Subcommand, Debug)]
|
||||
pub enum CmdDomain {
|
||||
@@ -19,7 +18,6 @@ pub enum CmdDomain {
|
||||
|
||||
/// Sync local zone file with remotex
|
||||
SyncZoneFile(self::zonefile::CmdZoneFileSync),
|
||||
|
||||
}
|
||||
|
||||
#[async_trait::async_trait]
|
||||
|
||||
@@ -16,7 +16,7 @@ pub struct CmdZoneFileGet {
|
||||
domain_name: String,
|
||||
|
||||
/// output file name to store zone file
|
||||
#[clap(short='o', long="output", required = false)]
|
||||
#[clap(short = 'o', long = "output", required = false)]
|
||||
zone_file_path: Option<String>,
|
||||
}
|
||||
|
||||
@@ -30,34 +30,37 @@ pub struct CmdZoneFileSync {
|
||||
zone_file_path: String,
|
||||
|
||||
/// Do not delete records that are not present in the zone file
|
||||
#[clap(short='n', long="no-delete-missing-records", required = false, default_value = "false")]
|
||||
#[clap(
|
||||
short = 'n',
|
||||
long = "no-delete-missing-records",
|
||||
required = false,
|
||||
default_value = "false"
|
||||
)]
|
||||
no_delete_missing_records: bool,
|
||||
}
|
||||
|
||||
|
||||
#[async_trait::async_trait]
|
||||
impl AsyncCliCommand for CmdZoneFileGet {
|
||||
type Output = ();
|
||||
|
||||
async fn run_async(self) -> Result<(), anyhow::Error> {
|
||||
let client = self.api.client()?;
|
||||
if let Some(domain) = wasmer_api::query::get_domain_zone_file(&client, self.domain_name).await? {
|
||||
if let Some(domain) =
|
||||
wasmer_api::query::get_domain_zone_file(&client, self.domain_name).await?
|
||||
{
|
||||
let zone_file_contents = domain.zone_file;
|
||||
if let Some(zone_file_path) = self.zone_file_path {
|
||||
std::fs::write(zone_file_path, zone_file_contents).expect("Unable to write file");
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
println!("{}", zone_file_contents);
|
||||
}
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
println!("Domain not found");
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#[async_trait::async_trait]
|
||||
impl AsyncCliCommand for CmdZoneFileSync {
|
||||
type Output = ();
|
||||
@@ -65,7 +68,12 @@ impl AsyncCliCommand for CmdZoneFileSync {
|
||||
async fn run_async(self) -> Result<(), anyhow::Error> {
|
||||
let data = std::fs::read(&self.zone_file_path).expect("Unable to read file");
|
||||
let zone_file_contents = String::from_utf8(data).expect("Not a valid UTF-8 sequence");
|
||||
let domain = wasmer_api::query::upsert_domain_from_zone_file(&self.api.client()?, zone_file_contents, !self.no_delete_missing_records,).await?;
|
||||
let domain = wasmer_api::query::upsert_domain_from_zone_file(
|
||||
&self.api.client()?,
|
||||
zone_file_contents,
|
||||
!self.no_delete_missing_records,
|
||||
)
|
||||
.await?;
|
||||
println!("Successfully synced domain: {}", domain.name);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
@@ -14,6 +14,7 @@ mod create_exe;
|
||||
#[cfg(feature = "static-artifact-create")]
|
||||
mod create_obj;
|
||||
pub(crate) mod deploy;
|
||||
pub(crate) mod domain;
|
||||
#[cfg(feature = "static-artifact-create")]
|
||||
mod gen_c_header;
|
||||
mod init;
|
||||
@@ -22,7 +23,6 @@ mod inspect;
|
||||
mod journal;
|
||||
mod login;
|
||||
pub(crate) mod namespace;
|
||||
pub(crate) mod domain;
|
||||
mod package;
|
||||
mod publish;
|
||||
mod run;
|
||||
|
||||
@@ -108,7 +108,6 @@ pub struct ItemTableFormatOpts {
|
||||
pub format: crate::utils::render::ItemFormat,
|
||||
}
|
||||
|
||||
|
||||
/// Formatting options for a list of items.
|
||||
#[derive(clap::Parser, Debug)]
|
||||
pub struct ListFormatOpts {
|
||||
|
||||
@@ -1,14 +1,12 @@
|
||||
use comfy_table::Table;
|
||||
use wasmer_api::types::{DeployApp, DeployAppVersion, Namespace, DnsDomain, DnsDomainWithRecords};
|
||||
use wasmer_api::types::{DeployApp, DeployAppVersion, DnsDomain, DnsDomainWithRecords, Namespace};
|
||||
|
||||
use crate::utils::render::CliRender;
|
||||
|
||||
impl CliRender for DnsDomain {
|
||||
fn render_item_table(&self) -> String {
|
||||
let mut table = Table::new();
|
||||
table.add_rows([
|
||||
vec!["Domain".to_string(), self.name.clone()],
|
||||
]);
|
||||
table.add_rows([vec!["Domain".to_string(), self.name.clone()]]);
|
||||
table.to_string()
|
||||
}
|
||||
|
||||
@@ -25,14 +23,14 @@ impl CliRender for DnsDomain {
|
||||
);
|
||||
table.to_string()
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
impl CliRender for DnsDomainWithRecords {
|
||||
fn render_item_table(&self) -> String {
|
||||
let mut output = String::new();
|
||||
let mut table = Table::new();
|
||||
table.load_preset(comfy_table::presets::UTF8_FULL_CONDENSED)
|
||||
table
|
||||
.load_preset(comfy_table::presets::UTF8_FULL_CONDENSED)
|
||||
.set_header(vec![
|
||||
"Type".to_string(),
|
||||
"Name".to_string(),
|
||||
@@ -41,16 +39,17 @@ impl CliRender for DnsDomainWithRecords {
|
||||
]);
|
||||
let mut rows: Vec<Vec<String>> = vec![];
|
||||
if let Some(ref records) = self.records {
|
||||
for record in records {
|
||||
if let Some(ref record) = record {
|
||||
records.iter().flatten().for_each(|record| {
|
||||
rows.push(vec![
|
||||
record.record_type().to_string(),
|
||||
record.name().expect("Expected record name").to_string(),
|
||||
record.ttl().expect("expected a TTL value for record").to_string(),
|
||||
record
|
||||
.ttl()
|
||||
.expect("expected a TTL value for record")
|
||||
.to_string(),
|
||||
record.text().to_string(),
|
||||
]);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
table.add_rows(rows);
|
||||
@@ -64,14 +63,9 @@ impl CliRender for DnsDomainWithRecords {
|
||||
}
|
||||
let mut table = Table::new();
|
||||
table.set_header(vec!["Domain".to_string()]);
|
||||
table.add_rows(
|
||||
items
|
||||
.iter()
|
||||
.map(|ns| vec![ns.name.clone()]),
|
||||
);
|
||||
table.add_rows(items.iter().map(|ns| vec![ns.name.clone()]));
|
||||
table.to_string()
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
impl CliRender for Namespace {
|
||||
|
||||
Reference in New Issue
Block a user