Skip to content

Commit 0feff54

Browse files
committed
Add file output option to token upgrade command
1 parent 046ed25 commit 0feff54

1 file changed

Lines changed: 13 additions & 2 deletions

File tree

core/src/bin/meta-ads-access.rs

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ use meta_ads_access::{
66
version::GraphApiVersion,
77
};
88
use scraper_trail::archive::entry::Entry;
9+
use std::io::Write;
910
use std::path::PathBuf;
1011

1112
#[derive(thiserror::Error, Debug)]
@@ -136,13 +137,20 @@ async fn main() -> Result<(), Error> {
136137
app_id,
137138
app_secret,
138139
token,
140+
output,
139141
} => {
140142
let response =
141143
meta_ads_access::token::upgrade_token(version, app_id, &app_secret, &token).await?;
142144

143145
::log::info!("Expires in {} seconds", response.expires_in);
144146

145-
println!("{}", toml::to_string(&response.creds(Utc::now()))?);
147+
let contents = toml::to_string(&response.creds(Utc::now()))?;
148+
149+
if let Some(output) = output {
150+
std::fs::write(output, format!("{contents}\n"))?;
151+
} else {
152+
writeln!(std::io::stdout(), "{contents}",)?;
153+
}
146154
}
147155
Command::SearchArchive {
148156
data,
@@ -287,7 +295,7 @@ enum Command {
287295
#[clap(long, default_value = "0")]
288296
delay: u64,
289297
},
290-
/// Upgrade a short-lived token to a long-lived one and print as TOML
298+
/// Upgrade a short-lived token to a long-lived one and save as TOML
291299
UpgradeToken {
292300
#[clap(long, default_value = "24.0")]
293301
version: GraphApiVersion,
@@ -298,6 +306,9 @@ enum Command {
298306
/// Active short-lived token
299307
#[clap(long)]
300308
token: String,
309+
/// File to save credentials to (optional; if absent will print to standard out)
310+
#[clap(long)]
311+
output: Option<PathBuf>,
301312
},
302313
/// Print ad IDs, page IDs, and page names as CSV for all archived exchanges
303314
SearchArchive {

0 commit comments

Comments
 (0)