diff options
author | Matthias Beyer <mail@beyermatthias.de> | 2020-12-10 09:38:44 +0100 |
---|---|---|
committer | Matthias Beyer <mail@beyermatthias.de> | 2020-12-10 09:43:28 +0100 |
commit | 2e7acac7c6178a9be837752b19e3a46a5a1f4772 (patch) | |
tree | ea623799e579387d269a97a18e1950032e683691 /src/commands/db.rs | |
parent | 5e1b941300eb94b61b77b05488fca80ebc6b8bf7 (diff) |
Move script formatting to Script type definition
This patch moves the script formatting to the definition of the Script
type, where it belongs to.
This is not an optimal implementation code-cleanness wise, because we
could always improve the interface to be even more typesafe and
convenient to use, but I guess this is nice for now.
Signed-off-by: Matthias Beyer <mail@beyermatthias.de>
Diffstat (limited to 'src/commands/db.rs')
-rw-r--r-- | src/commands/db.rs | 7 |
1 files changed, 6 insertions, 1 deletions
diff --git a/src/commands/db.rs b/src/commands/db.rs index eb65425..fa52d8a 100644 --- a/src/commands/db.rs +++ b/src/commands/db.rs @@ -20,6 +20,7 @@ use crate::config::Configuration; use crate::db::DbConnectionConfig; use crate::db::models; use crate::log::LogItem; +use crate::package::Script; use crate::schema; pub fn db(db_connection_config: DbConnectionConfig, config: &Configuration, matches: &ArgMatches) -> Result<()> { @@ -387,7 +388,11 @@ fn job(conn_cfg: DbConnectionConfig, config: &Configuration, matches: &ArgMatche log_len = format!("{:<4}", data.0.log_text.lines().count()).cyan(), envs = env_vars.unwrap_or_else(|| String::from("<env vars hidden>")), script_text = if show_script { - crate::ui::script_to_printable(&data.0.script_text, script_highlight, configured_theme.as_ref(), script_line_numbers)? + let theme = configured_theme + .as_ref() + .ok_or_else(|| anyhow!("Highlighting for script enabled, but no theme configured"))?; + let script = Script::from(data.0.script_text); + crate::ui::script_to_printable(&script, script_highlight, theme, script_line_numbers)? } else { String::from("<script hidden>") }, |