chore: moved StringOr into ext
This commit is contained in:
parent
b0b67fd1be
commit
2e520129a2
3 changed files with 16 additions and 16 deletions
12
src/ext.rs
12
src/ext.rs
|
@ -1,3 +1,15 @@
|
|||
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
|
||||
#[serde(untagged)]
|
||||
pub enum StringOr<T> {
|
||||
Str(String),
|
||||
T(T),
|
||||
}
|
||||
|
||||
impl<T: Default> Default for StringOr<T> {
|
||||
fn default() -> Self {
|
||||
Self::T(T::default())
|
||||
}
|
||||
}
|
||||
|
||||
pub fn stringify_toml(v: &toml::Value) -> String {
|
||||
match v {
|
||||
|
|
|
@ -6,7 +6,8 @@ use jaq_interpret::FilterT;
|
|||
|
||||
use crate::{PostWomanError, APP_USER_AGENT};
|
||||
|
||||
use super::{Extractor, PostWomanClient, StringOr};
|
||||
use crate::ext::{stringify_toml, stringify_json, StringOr};
|
||||
use super::{Extractor, PostWomanClient};
|
||||
|
||||
|
||||
#[derive(Debug, Default, Clone, serde::Serialize, serde::Deserialize)]
|
||||
|
@ -59,7 +60,7 @@ impl Endpoint {
|
|||
vars.insert("POSTWOMAN_TIMESTAMP".to_string(), chrono::Local::now().timestamp().to_string());
|
||||
|
||||
for (k, v) in env {
|
||||
vars.insert(k.to_string(), crate::ext::stringify_toml(v));
|
||||
vars.insert(k.to_string(), stringify_toml(v));
|
||||
}
|
||||
|
||||
for (k, v) in std::env::vars() {
|
||||
|
@ -173,7 +174,7 @@ impl Endpoint {
|
|||
let json: serde_json::Value = res.json().await?;
|
||||
let selection = jq(&query, json)?;
|
||||
if selection.len() == 1 {
|
||||
crate::ext::stringify_json(&selection[0]) + "\n"
|
||||
stringify_json(&selection[0]) + "\n"
|
||||
} else {
|
||||
serde_json::to_string_pretty(&selection)? + "\n"
|
||||
}
|
||||
|
|
|
@ -13,16 +13,3 @@ pub struct PostWomanConfig {
|
|||
// it's weird to name it singular but makes more sense in config
|
||||
pub route: indexmap::IndexMap<String, Endpoint>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
|
||||
#[serde(untagged)]
|
||||
pub enum StringOr<T> {
|
||||
Str(String),
|
||||
T(T),
|
||||
}
|
||||
|
||||
impl<T: Default> Default for StringOr<T> {
|
||||
fn default() -> Self {
|
||||
Self::T(T::default())
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue