update export-svg to target-svg update usage example

This commit is contained in:
yggverse 2025-06-09 18:18:34 +03:00
parent 31e310fae7
commit 599435f1ab
3 changed files with 11 additions and 10 deletions

View file

@ -28,10 +28,11 @@ Export totals in multiple formats, such as JSON or SVG [badge](https://github.co
## Usage ## Usage
``` bash ``` bash
htcount --source /var/log/nginx/access.log\ htcount --source /var/log/nginx/access.log\
--export-json /path/to/totals.json\ --target-svg /path/to/badge.svg\
--export-svg /path/to/totals.svg --template-svg /path/to/counter/template.svg
``` ```
* see `default/counter.svg`
### Options ### Options
@ -50,10 +51,10 @@ htcount --source /var/log/nginx/access.log\
[default: nginx] [default: nginx]
--export-json <EXPORT_JSON> --target-json <TARGET_JSON>
Export results to JSON file (e.g. `/path/to/stats.json`) Export results to JSON file (e.g. `/path/to/stats.json`)
--export-svg <EXPORT_SVG> --target-svg <TARGET_SVG>
Export results to SVG file (e.g. `/path/to/badge.svg`) Export results to SVG file (e.g. `/path/to/badge.svg`)
* use `{hits}` / `{hosts}` pattern to replace parsed values * use `{hits}` / `{hosts}` pattern to replace parsed values
@ -101,7 +102,7 @@ Wants=network-online.target
[Service] [Service]
Type=simple Type=simple
ExecStart=/usr/local/bin/htcount --source /var/log/nginx/access.log\ ExecStart=/usr/local/bin/htcount --source /var/log/nginx/access.log\
--export-svg /var/www/htcount/visitors.svg\ --target-svg /var/www/htcount/visitors.svg\
--template-svg /path/to/default/template.svg\ --template-svg /path/to/default/template.svg\
--ignore-host 127.0.0.1\ --ignore-host 127.0.0.1\
--ignore-host 127.0.0.2\ --ignore-host 127.0.0.2\

View file

@ -18,13 +18,13 @@ pub struct Argument {
/// Export results to JSON file (e.g. `/path/to/stats.json`) /// Export results to JSON file (e.g. `/path/to/stats.json`)
#[arg(long)] #[arg(long)]
pub export_json: Option<String>, pub target_json: Option<String>,
/// Export results to SVG file (e.g. `/path/to/badge.svg`) /// Export results to SVG file (e.g. `/path/to/badge.svg`)
/// ///
/// * use `{hits}` / `{hosts}` pattern to replace parsed values /// * use `{hits}` / `{hosts}` pattern to replace parsed values
#[arg(long)] #[arg(long)]
pub export_svg: Option<String>, pub target_svg: Option<String>,
/// Use custom SVG file template with `{hits}` / `{hosts}` placeholders /// Use custom SVG file template with `{hits}` / `{hosts}` placeholders
#[arg(long, default_value_t = String::from("default/counter.svg"))] #[arg(long, default_value_t = String::from("default/counter.svg"))]

View file

@ -90,12 +90,12 @@ fn main() -> anyhow::Result<()> {
)); ));
} }
if let Some(ref p) = argument.export_json { if let Some(ref p) = argument.target_json {
let mut f = File::create(p)?; let mut f = File::create(p)?;
f.write_all(format!("{{\"hosts\":{hosts},\"hits\":{hits}}}").as_bytes())?; f.write_all(format!("{{\"hosts\":{hosts},\"hits\":{hits}}}").as_bytes())?;
} }
if let Some(ref p) = argument.export_svg { if let Some(ref p) = argument.target_svg {
let t = std::fs::read_to_string(&argument.template_svg)?; let t = std::fs::read_to_string(&argument.template_svg)?;
let mut f = File::create(p)?; let mut f = File::create(p)?;
f.write_all( f.write_all(