Skip to content

Commit a33b689

Browse files
Add render-logins Subcommand (#6)
* add render-logins subcommand * fix
1 parent 6607a73 commit a33b689

File tree

4 files changed

+69
-2
lines changed

4 files changed

+69
-2
lines changed

Cargo.lock

Lines changed: 11 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ edition = "2021"
66
[dependencies]
77
anyhow = "1.0.95"
88
clap = { version = "4.5.27", features = ["derive"] }
9-
bedrock = { git = "http://github.com/basalt-rs/bedrock.git", rev = "52ff607", features = ["tokio"] }
9+
bedrock = { git = "http://github.com/basalt-rs/bedrock.git", rev = "90122c8", features = ["tokio"] }
1010
tokio = { version = "1.43.0", features = ["full"] }
1111
lazy_static = "1.5.0"
1212
tera = "1.20.0"

src/cli.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,20 @@ pub enum SubCmd {
3434
/// The configuration file to build
3535
config_file: PathBuf,
3636
},
37+
/// Render the logins into a printable packet PDF
38+
RenderLogins {
39+
/// Output file for the PDF (`.pdf` is optional). If not specified, will get name from the
40+
/// config file used
41+
#[arg(short, long)]
42+
output: Option<PathBuf>,
43+
/// Path to a template to use, if not specified uses the default template. Most of the
44+
/// time, this is not necessary.
45+
#[arg(short, long)]
46+
template: Option<PathBuf>,
47+
/// Config file from which to generate the PDF
48+
#[arg(default_value = default_config())]
49+
config_file: PathBuf,
50+
},
3751
/// Render the configuration into a printable packet PDF
3852
Render {
3953
/// Output file for the PDF (`.pdf` is optional). If not specified, will get name from the

src/main.rs

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,49 @@ async fn main() -> anyhow::Result<()> {
9292
.with_context(|| format!("saving pdf to {}", output.display()))?;
9393
println!("Rendered PDF to {}", output.display());
9494
}
95+
cli::SubCmd::RenderLogins {
96+
output,
97+
config_file,
98+
template,
99+
} => {
100+
let mut file = File::open(&config_file)
101+
.await
102+
.context("opening config file")?;
103+
let config = bedrock::Config::read_async(
104+
&mut file,
105+
config_file.file_name().and_then(OsStr::to_str),
106+
)
107+
.await
108+
.context("loading config")?;
109+
let template = if let Some(template) = template {
110+
Some(
111+
tokio::fs::read_to_string(template)
112+
.await
113+
.context("reading config file")?,
114+
)
115+
} else {
116+
None
117+
};
118+
119+
let output = output
120+
.unwrap_or(
121+
format!(
122+
"{}-logins",
123+
config_file
124+
.with_extension("")
125+
.file_name()
126+
.expect("This would have failed when opening the file")
127+
.to_string_lossy()
128+
)
129+
.into(),
130+
)
131+
.with_extension("pdf");
132+
let pdf = config.render_login_pdf(template).context("creating pdf")?;
133+
tokio::fs::write(&output, pdf)
134+
.await
135+
.with_context(|| format!("saving pdf to {}", output.display()))?;
136+
println!("Rendered PDF to {}", output.display());
137+
}
95138
cli::SubCmd::GameCode { config, ip, port } => {
96139
let ip = if let Some(ip) = ip {
97140
ip

0 commit comments

Comments
 (0)