dre-cli 0.0.1-alpha-14

The dre command-line interface
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
//! Terminal output: right-aligned coloured status verbs, a live progress bar, log levels,
//! JSON lines for machines, and a full debug log in `logs/dre.log`: every event, and the full
//! text of every SQL statement sent to a database. The log rotates every 10,000 lines
//! (`DRE_LOG_MAX_LINES` overrides), keeping `dre.log.1` (newest) to `dre.log.5`.
//!
//! Lines go to stdout. The progress bar goes to stderr and only appears when stderr is a
//! terminal. Colour follows `--color`, `NO_COLOR` and whether stdout is a terminal.

use std::fs::File;
use std::io::{IsTerminal, Write};
use std::path::{Path, PathBuf};
use std::sync::{Arc, Mutex};
use std::time::{Duration, Instant};

use anstyle::{AnsiColor, Effects, Style};
use dre_core::run::{BindingOutcome, Level, Status, Ui};
use dre_protocol::host::LogSink;
use indicatif::{ProgressBar, ProgressDrawTarget, ProgressStyle};
use serde_json::json;

#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, clap::ValueEnum)]
pub enum Verbosity {
    /// Errors and the final summary only.
    Quiet,
    /// One line per Binding, plus warnings (the default).
    Info,
    /// Every step: rendering, each statement, formatting, delivery, plugin logs.
    Debug,
}

#[derive(Debug, Clone, Copy, PartialEq, Eq, clap::ValueEnum)]
pub enum LogFormat {
    Text,
    /// One JSON object per line, for CI and tooling.
    Json,
}

#[derive(Debug, Clone, Copy, PartialEq, Eq, clap::ValueEnum)]
pub enum ColorChoice {
    Auto,
    Always,
    Never,
}

#[derive(Clone, Copy)]
pub enum Tone {
    Good,
    Bad,
    Warn,
    Step,
    Note,
}

fn style(t: Tone) -> Style {
    let c = match t {
        Tone::Good => AnsiColor::Green,
        Tone::Bad => AnsiColor::Red,
        Tone::Warn => AnsiColor::Yellow,
        Tone::Step => AnsiColor::Cyan,
        Tone::Note => AnsiColor::Blue,
    };
    Style::new().fg_color(Some(c.into())).effects(Effects::BOLD)
}

const DIM: Style = Style::new().effects(Effects::DIMMED);

struct Inner {
    verbosity: Verbosity,
    format: LogFormat,
    color: bool,
    bar: Option<ProgressBar>,
    log: Option<LogFile>,
    current: String,
    started: Instant,
    succeeded: usize,
    failed: usize,
}

/// Renders run events. Cheap to clone; clones share state (plugin log lines arrive on threads).
#[derive(Clone)]
pub struct Printer {
    inner: Arc<Mutex<Inner>>,
}

impl Printer {
    pub fn new(verbosity: Verbosity, format: LogFormat, color: ColorChoice) -> Printer {
        let color = match color {
            ColorChoice::Always => true,
            ColorChoice::Never => false,
            ColorChoice::Auto => {
                std::env::var_os("NO_COLOR").is_none_or(|v| v.is_empty()) && std::io::stdout().is_terminal()
            }
        } && format == LogFormat::Text;
        Printer {
            inner: Arc::new(Mutex::new(Inner {
                verbosity,
                format,
                color,
                bar: None,
                log: None,
                current: String::new(),
                started: Instant::now(),
                succeeded: 0,
                failed: 0,
            })),
        }
    }

    /// Also write every event, at debug level, to `<project>/logs/dre.log`.
    pub fn log_to(&self, project: &Path) {
        let max_lines = std::env::var("DRE_LOG_MAX_LINES")
            .ok()
            .and_then(|v| v.parse().ok())
            .filter(|n| *n > 0)
            .unwrap_or(LOG_MAX_LINES);
        if let Some(l) = LogFile::open(&project.join(LOGS_DIR).join("dre.log"), max_lines) {
            self.inner.lock().unwrap().log = Some(l);
        }
    }

    /// Colour a diagnostic's `error[...]`/`warning[...]` prefix.
    pub fn diagnostic(&self, d: &dre_core::Diagnostic) -> String {
        let i = self.inner.lock().unwrap();
        let text = dre_core::secrets::mask(&d.to_string()).into_owned();
        let (tone, prefix) = match d.severity {
            dre_core::Severity::Error => (Tone::Bad, "error"),
            dre_core::Severity::Warning => (Tone::Warn, "warning"),
        };
        match text.find("]: ") {
            Some(end) if i.color => format!("{}{}", i.paint(style(tone), &text[..end + 1]), &text[end + 1..]),
            _ => {
                let _ = prefix;
                text
            }
        }
    }

    /// Print a diagnostic: a line of text, or with `--log-format json` a `diagnostic` event, so
    /// warnings never break the JSON stream.
    pub fn diag(&self, d: &dre_core::Diagnostic) {
        let i = self.inner.lock().unwrap();
        if i.format == LogFormat::Json {
            let message = dre_core::secrets::mask(&d.message).into_owned();
            i.json(
                json!({"event": "diagnostic", "severity": d.severity, "code": d.code,
                "file": d.file, "line": d.line, "message": message}),
            );
            return;
        }
        drop(i);
        println!("{}", self.diagnostic(d));
    }

    /// `     Verb  text`, the verb right-aligned in a 10-column gutter.
    pub fn line(&self, tone: Tone, verb: &str, text: &str) {
        self.inner.lock().unwrap().line(tone, verb, text, Level::Info);
    }

    /// Like [`Printer::line`], shown only with `-v`, and only as text: JSON events carry the
    /// same facts in their own fields.
    pub fn detail(&self, tone: Tone, verb: &str, text: &str) {
        let mut i = self.inner.lock().unwrap();
        if i.format == LogFormat::Json {
            i.file_log("DEBUG", &format!("{verb} {text}"));
            return;
        }
        i.line(tone, verb, text, Level::Debug);
    }

    pub fn error(&self, msg: &str) {
        let mut i = self.inner.lock().unwrap();
        i.file_log("ERROR", msg);
        if i.format == LogFormat::Json {
            i.json(json!({"event": "error", "message": msg}));
        } else {
            i.print(Tone::Bad, "Error", msg);
        }
    }

    /// Record the run's parameters in the log file (and as a JSON event).
    pub fn log_params(&self, params: &serde_json::Value) {
        let mut i = self.inner.lock().unwrap();
        i.file_log("INFO", &format!("Parameters {params}"));
        if i.format == LogFormat::Json {
            i.json(json!({"event": "run_parameters", "parameters": params}));
        }
    }

    /// Where a compiled Binding's output would go: source, output file, each destination and
    /// its target (non-dev targets stand out), and the schedules that run it.
    pub fn plan(&self, p: &dre_core::run::BindingPlan) {
        let i = self.inner.lock().unwrap();
        let non_dev = |t: &str| t != "dev";
        i.print(Tone::Step, "Binding", &label(&p.report, p.set.as_deref()));
        for f in &p.compiled {
            i.print(Tone::Good, "Compiled", &f.display().to_string());
        }
        let source = format!("{} ({}), target {}", p.profile, p.source_type, p.target);
        i.print(
            if non_dev(&p.target) {
                Tone::Warn
            } else {
                Tone::Note
            },
            "Source",
            &source,
        );
        i.print(
            Tone::Note,
            "Output",
            &format!("{} ({})", p.output.display(), p.format),
        );
        for d in &p.destinations {
            let target = d.target.clone().unwrap_or_default();
            let what = match (&d.kind, &d.path) {
                (Some(k), Some(path)) => format!("{} ({k}), target {target} → {path}", d.profile),
                (Some(k), None) => format!("{} ({k}), target {target}", d.profile),
                (None, _) => format!("{}: no `{target}` target, so nothing is delivered", d.profile),
            };
            let tone = if d.delivers && non_dev(&target) {
                Tone::Warn
            } else {
                Tone::Note
            };
            i.print(tone, if d.delivers { "Delivers" } else { "Keeps" }, &what);
        }
        if !p.schedules.is_empty() {
            i.print(Tone::Note, "Schedules", &p.schedules.join(", "));
        }
    }

    /// Final line of a run.
    pub fn finish(&self, what: &str) {
        let mut i = self.inner.lock().unwrap();
        if let Some(b) = i.bar.take() {
            b.finish_and_clear();
        }
        let (ok, failed) = (i.succeeded, i.failed);
        let secs = i.started.elapsed().as_secs_f64();
        let text = format!("'{what}' in {} · {ok} succeeded, {failed} failed", fmt_secs(secs));
        i.file_log("INFO", &format!("Finished {text}"));
        if i.format == LogFormat::Json {
            i.json(json!({"event": "finished", "command": what, "succeeded": ok, "failed": failed, "elapsed_ms": (secs * 1000.0) as u64}));
        } else {
            i.print(if failed > 0 { Tone::Bad } else { Tone::Good }, "Finished", &text);
        }
    }
}

impl Inner {
    fn paint(&self, s: Style, text: &str) -> String {
        if self.color {
            format!("{s}{text}{s:#}")
        } else {
            text.to_string()
        }
    }

    fn print(&self, tone: Tone, verb: &str, text: &str) {
        let verb = self.paint(style(tone), &format!("{verb:>10}"));
        // Continuation lines line up under the text; blank ones stay blank.
        let text = text
            .lines()
            .enumerate()
            .map(|(n, l)| {
                if n == 0 || l.trim().is_empty() {
                    l.trim_end().to_string()
                } else {
                    format!("{:>10}  {l}", "")
                }
            })
            .collect::<Vec<_>>()
            .join("\n");
        let out = format!("{verb}  {text}");
        match &self.bar {
            Some(b) => b.suspend(|| println_stdout(&out)),
            None => println_stdout(&out),
        }
    }

    fn line(&mut self, tone: Tone, verb: &str, text: &str, level: Level) {
        self.file_log(
            if level == Level::Debug { "DEBUG" } else { "INFO" },
            &format!("{verb} {text}"),
        );
        if !self.shows(level) {
            return;
        }
        if self.format == LogFormat::Json {
            self.json(json!({"event": "line", "verb": verb, "message": text}));
        } else {
            self.print(tone, verb, text);
        }
    }

    fn shows(&self, level: Level) -> bool {
        match self.verbosity {
            Verbosity::Quiet => false,
            Verbosity::Info => level == Level::Info,
            Verbosity::Debug => true,
        }
    }

    fn json(&self, mut v: serde_json::Value) {
        v["ts"] = json!(chrono::Utc::now().to_rfc3339_opts(chrono::SecondsFormat::Millis, true));
        let line = v.to_string();
        match &self.bar {
            Some(b) => b.suspend(|| println_stdout(&line)),
            None => println_stdout(&line),
        }
    }

    fn file_log(&mut self, level: &str, msg: &str) {
        if let Some(f) = self.log.as_mut() {
            let ts = chrono::Utc::now().to_rfc3339_opts(chrono::SecondsFormat::Millis, true);
            let ctx = if self.current.is_empty() {
                String::new()
            } else {
                format!(" [{}]", self.current)
            };
            f.write(&dre_core::secrets::mask(&format!("{ts} {level:<5}{ctx} {msg}\n")));
        }
    }
}

pub use dre_core::project::LOGS_DIR;
const LOG_MAX_LINES: usize = 10_000;
/// Rotated files kept: `dre.log.1` (newest) to `dre.log.5`.
const LOG_KEEP: usize = 5;

/// An append-only log that rotates once it reaches `max_lines`.
struct LogFile {
    path: PathBuf,
    file: File,
    lines: usize,
    max_lines: usize,
}

impl LogFile {
    fn open(path: &Path, max_lines: usize) -> Option<LogFile> {
        std::fs::create_dir_all(path.parent()?).ok()?;
        let lines = std::fs::read(path).map_or(0, |b| b.iter().filter(|c| **c == b'\n').count());
        let file = std::fs::OpenOptions::new()
            .create(true)
            .append(true)
            .open(path)
            .ok()?;
        let mut l = LogFile {
            path: path.to_path_buf(),
            file,
            lines,
            max_lines,
        };
        if l.lines >= l.max_lines {
            l.rotate();
        }
        Some(l)
    }

    /// Entries are never split across files; a file can end a few lines over the limit.
    fn write(&mut self, entry: &str) {
        let _ = self.file.write_all(entry.as_bytes());
        self.lines += entry.matches('\n').count();
        if self.lines >= self.max_lines {
            self.rotate();
        }
    }

    fn rotate(&mut self) {
        let _ = self.file.flush();
        let name = |n: usize| PathBuf::from(format!("{}.{n}", self.path.display()));
        let _ = std::fs::remove_file(name(LOG_KEEP));
        for n in (1..LOG_KEEP).rev() {
            let _ = std::fs::rename(name(n), name(n + 1));
        }
        let _ = std::fs::rename(&self.path, name(1));
        if let Ok(f) = std::fs::OpenOptions::new()
            .create(true)
            .append(true)
            .open(&self.path)
        {
            self.file = f;
            self.lines = 0;
        }
    }
}

/// Everything printed goes through here, so `DRE_SECRET_*` values are masked on the console.
fn println_stdout(s: &str) {
    let mut out = std::io::stdout().lock();
    let _ = writeln!(out, "{}", dre_core::secrets::mask(s));
}

fn fmt_secs(s: f64) -> String {
    if s < 60.0 {
        format!("{s:.2}s")
    } else {
        format!("{}m {:02}s", (s / 60.0) as u64, (s % 60.0) as u64)
    }
}

fn timing(d: Duration) -> String {
    format!("[{:>6}]", fmt_secs(d.as_secs_f64()))
}

fn label(report: &str, set: Option<&str>) -> String {
    match set {
        Some(s) => format!("{report} [{s}]"),
        None => report.to_string(),
    }
}

impl Ui for Printer {
    fn plan(&mut self, bindings: usize) {
        let mut i = self.inner.lock().unwrap();
        i.started = Instant::now();
        let text = format!("{bindings} Binding{}", if bindings == 1 { "" } else { "s" });
        i.file_log("INFO", &format!("Running {text}"));
        if i.format == LogFormat::Json {
            i.json(json!({"event": "plan", "bindings": bindings}));
            return;
        }
        if i.verbosity != Verbosity::Quiet {
            i.print(Tone::Note, "Running", &text);
        }
        if i.verbosity != Verbosity::Quiet && std::io::stderr().is_terminal() && bindings > 0 {
            let bar = ProgressBar::with_draw_target(Some(bindings as u64), ProgressDrawTarget::stderr());
            bar.set_style(
                ProgressStyle::with_template("{spinner:.green} [{bar:28.green/dim}] {pos}/{len} {wide_msg}")
                    .unwrap()
                    .progress_chars("█▉░"),
            );
            bar.enable_steady_tick(Duration::from_millis(100));
            i.bar = Some(bar);
        }
    }

    fn binding_start(&mut self, report: &str, set: Option<&str>) {
        let mut i = self.inner.lock().unwrap();
        i.current = label(report, set);
        i.file_log("INFO", "Started");
        if let Some(b) = &i.bar {
            b.set_message(i.current.clone());
        }
        if i.format == LogFormat::Json {
            i.json(json!({"event": "binding_start", "report": report, "set": set}));
        } else if i.verbosity == Verbosity::Debug {
            let text = i.current.clone();
            i.print(Tone::Note, "Started", &text);
        }
    }

    fn step(&mut self, level: Level, verb: &str, detail: &str, elapsed: Option<Duration>) {
        let mut i = self.inner.lock().unwrap();
        if let Some(b) = &i.bar {
            b.set_message(format!("{} · {verb} {detail}", i.current));
        }
        let text = match elapsed {
            Some(d) => format!("{} {detail}", i.paint(DIM, &timing(d))),
            None => detail.to_string(),
        };
        if i.format == LogFormat::Json {
            i.file_log("DEBUG", &format!("{verb} {detail}"));
            if i.shows(level) {
                let ms = elapsed.map(|d| d.as_millis() as u64);
                i.json(json!({"event": "step", "binding": i.current, "verb": verb, "message": detail, "elapsed_ms": ms}));
            }
            return;
        }
        i.line(Tone::Step, verb, &text, level);
    }

    fn warn(&mut self, msg: &str) {
        let mut i = self.inner.lock().unwrap();
        i.file_log("WARN", msg);
        if i.format == LogFormat::Json {
            i.json(json!({"event": "warning", "binding": i.current, "message": msg}));
        } else if i.verbosity != Verbosity::Quiet {
            i.print(Tone::Warn, "Warning", msg);
        }
    }

    fn binding_vars(
        &mut self,
        schedule: Option<&str>,
        schedule_vars: Option<&serde_json::Map<String, serde_json::Value>>,
        vars: &serde_json::Map<String, serde_json::Value>,
    ) {
        let mut i = self.inner.lock().unwrap();
        if let Some(name) = schedule {
            let sv = serde_json::Value::Object(schedule_vars.cloned().unwrap_or_default());
            i.file_log("INFO", &format!("Schedule {name} vars {sv}"));
        }
        let v = serde_json::Value::Object(vars.clone());
        i.file_log("INFO", &format!("Vars {v}"));
        if i.format == LogFormat::Json {
            i.json(json!({"event": "binding_vars", "schedule": schedule, "schedule_vars": schedule_vars, "vars": vars}));
        } else if i.shows(Level::Debug) {
            let text = i.paint(DIM, &v.to_string());
            i.print(Tone::Note, "Vars", &text);
        }
    }

    fn compiled(&mut self, p: &dre_core::run::BindingPlan) {
        let mut i = self.inner.lock().unwrap();
        for f in &p.compiled {
            i.file_log("INFO", &format!("Compiled {}", f.display()));
        }
        if i.format == LogFormat::Json {
            i.json(json!({"event": "compiled", "plan": p}));
        } else {
            for f in &p.compiled {
                i.print(Tone::Good, "Compiled", &f.display().to_string());
            }
        }
    }

    fn binding_end(&mut self, o: &BindingOutcome) {
        let mut i = self.inner.lock().unwrap();
        let name = label(&o.report, o.set.as_deref());
        let (tone, verb) = match o.status {
            Status::Error => (Tone::Bad, "Failed"),
            Status::Success => (Tone::Good, "Succeeded"),
            Status::DryRun => (Tone::Good, "Compiled"),
            Status::Checked => (Tone::Good, "Checked"),
        };
        if o.status == Status::Error {
            i.failed += 1;
        } else {
            i.succeeded += 1;
        }
        if let Some(b) = &i.bar {
            b.inc(1);
        }
        let detail = match &o.error {
            Some(e) => e.clone(),
            None => o.summary.clone(),
        };
        i.file_log(
            if o.error.is_some() { "ERROR" } else { "INFO" },
            &format!("{verb} in {} {detail}", fmt_secs(o.elapsed.as_secs_f64())),
        );
        i.current.clear();
        if i.format == LogFormat::Json {
            i.json(json!({
                "event": "binding_end", "report": o.report, "set": o.set, "status": o.status,
                "elapsed_ms": o.elapsed.as_millis() as u64, "error": o.error, "summary": o.summary,
                "files": o.files, "schedule": o.schedule, "schedule_vars": o.schedule_vars, "vars": o.vars,
                "timezone": o.timezone,
            }));
            return;
        }
        if i.verbosity == Verbosity::Quiet && o.status != Status::Error {
            return;
        }
        let name = i.paint(Style::new().effects(Effects::BOLD), &name);
        let text = format!("{} {name}  {detail}", i.paint(DIM, &timing(o.elapsed)));
        i.print(tone, verb, text.trim_end());
    }

    fn choose_set(&mut self, report: &str, sets: &[String]) -> Result<Option<String>, String> {
        let bar = self.inner.lock().unwrap().bar.clone();
        let ask = || -> Result<Option<String>, String> {
            eprintln!("Report `{report}` has several Sets:");
            for (i, s) in sets.iter().enumerate() {
                eprintln!("  {}) {s}", i + 1);
            }
            eprintln!("  a) all");
            loop {
                eprint!("Which one? ");
                let _ = std::io::stderr().flush();
                let mut line = String::new();
                if std::io::stdin().read_line(&mut line).map_err(|e| e.to_string())? == 0 {
                    return Err("no Set chosen".into());
                }
                let answer = line.trim();
                if answer == "a" || answer == "all" {
                    return Ok(None);
                }
                if let Ok(n) = answer.parse::<usize>()
                    && (1..=sets.len()).contains(&n)
                {
                    return Ok(Some(sets[n - 1].clone()));
                }
                if sets.iter().any(|s| s == answer) {
                    return Ok(Some(answer.to_string()));
                }
            }
        };
        match bar {
            Some(b) => b.suspend(ask),
            None => ask(),
        }
    }

    fn sql_log(&self) -> LogSink {
        let p = self.clone();
        Arc::new(move |label, sql| {
            let body: String = sql.trim_end().lines().map(|l| format!("\n    {l}")).collect();
            p.inner
                .lock()
                .unwrap()
                .file_log("DEBUG", &format!("SQL {label}:{body}"));
        })
    }

    fn plugin_log(&self) -> LogSink {
        let p = self.clone();
        Arc::new(move |plugin, line| {
            let mut i = p.inner.lock().unwrap();
            // `info: ...` lines are for the person (e.g. waiting for a warehouse to start).
            if let Some(msg) = line.strip_prefix("info: ") {
                i.line(Tone::Note, "Waiting", &format!("[{plugin}] {msg}"), Level::Info);
                return;
            }
            i.file_log("DEBUG", &format!("[{plugin}] {line}"));
            if !i.shows(Level::Debug) {
                return;
            }
            if i.format == LogFormat::Json {
                i.json(json!({"event": "plugin_log", "plugin": plugin, "message": line}));
            } else {
                let text = i.paint(DIM, &format!("[{plugin}] {line}"));
                i.print(Tone::Note, "Plugin", &text);
            }
        })
    }
}