Skip to content

Commit 139a95a

Browse files
committed
Fix duct stderr being printed
fix remove commented out line
1 parent 31fbf7c commit 139a95a

File tree

5 files changed

+38
-21
lines changed

5 files changed

+38
-21
lines changed

Cargo.lock

-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

-1
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,6 @@ signal-hook = "0.3.15"
5252
tokio-util = "0.7.8"
5353
zbus = { version = "4.1.2", default-features = false, features = ["tokio"] }
5454
itertools = "0.12.0"
55-
duct = "0.13.6"
5655
indexmap = "2.0.0"
5756
clipboard-anywhere = "0.2.2"
5857
chrono = { version = "0.4.31", default-features = false }

src/components/home.rs

+26-13
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
use crossterm::event::{KeyCode, KeyEvent, KeyModifiers};
2-
use duct::cmd;
32
use futures::Future;
43
use indexmap::IndexMap;
54
use itertools::Itertools;
@@ -18,7 +17,10 @@ use tokio_util::sync::CancellationToken;
1817
use tracing::{error, info, warn};
1918
use tui_input::{backend::crossterm::EventHandler, Input};
2019

21-
use std::{process::Stdio, time::Duration};
20+
use std::{
21+
process::{Command, Stdio},
22+
time::Duration,
23+
};
2224

2325
use super::{logger::Logger, Component, Frame};
2426
use crate::{
@@ -365,7 +367,11 @@ impl Component for Home {
365367
let _ = tx.send(Action::SetUnitFilePath { unit: unit.clone(), path });
366368
let _ = tx.send(Action::Render);
367369
},
368-
Err(e) => error!("Error getting unit file path for {}: {}", unit.name, e),
370+
Err(e) => {
371+
let _ = tx.send(Action::SetUnitFilePath { unit: unit.clone(), path: "(could not be determined)".into() });
372+
let _ = tx.send(Action::Render);
373+
error!("Error getting unit file path for {}: {}", unit.name, e);
374+
},
369375
}
370376

371377
// First, get the N lines in a batch
@@ -380,17 +386,24 @@ impl Component for Home {
380386
args.push("--user");
381387
}
382388

383-
match cmd("journalctl", args).read() {
384-
Ok(stdout) => {
385-
info!("Got logs for {} in {:?}", unit.name, start.elapsed());
386-
387-
let mut logs = stdout.split('\n').map(String::from).collect_vec();
388-
389-
if logs.is_empty() || logs[0].is_empty() {
390-
logs.push(String::from("No logs found/available. Maybe try relaunching with `sudo systemctl-tui`"));
389+
match Command::new("journalctl").args(&args).output() {
390+
Ok(output) => {
391+
if output.status.success() {
392+
info!("Got logs for {} in {:?}", unit.name, start.elapsed());
393+
if let Ok(stdout) = std::str::from_utf8(&output.stdout) {
394+
let mut logs = stdout.trim().split('\n').map(String::from).collect_vec();
395+
396+
if logs.is_empty() || logs[0].is_empty() {
397+
logs.push(String::from("No logs found/available. Maybe try relaunching with `sudo systemctl-tui`"));
398+
}
399+
let _ = tx.send(Action::SetLogs { unit: unit.clone(), logs });
400+
let _ = tx.send(Action::Render);
401+
} else {
402+
warn!("Error parsing stdout for {}", unit.name);
403+
}
404+
} else {
405+
warn!("Error getting logs for {}: {}", unit.name, String::from_utf8_lossy(&output.stderr));
391406
}
392-
let _ = tx.send(Action::SetLogs { unit: unit.clone(), logs });
393-
let _ = tx.send(Action::Render);
394407
},
395408
Err(e) => warn!("Error getting logs for {}: {}", unit.name, e),
396409
}

src/components/logger.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ impl Component for Logger {
2424

2525
fn render(&mut self, f: &mut Frame<'_>, rect: Rect) {
2626
let w = TuiLoggerWidget::default()
27-
.block(Block::default().title(" 📝 systemctl-tui logs").borders(Borders::ALL))
27+
.block(Block::default().title(" systemctl-tui logs ").borders(Borders::ALL))
2828
.style_error(Style::default().fg(Color::Red))
2929
.style_debug(Style::default().fg(Color::Green))
3030
.style_warn(Style::default().fg(Color::Yellow))

src/systemd.rs

+11-5
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
// File initially taken from https://github.com/servicer-labs/servicer/blob/master/src/utils/systemd.rs, since modified
22

3-
use anyhow::Result;
4-
use duct::cmd;
3+
use std::process::Command;
4+
5+
use anyhow::{bail, Result};
56
use log::error;
67
use tokio_util::sync::CancellationToken;
78
use tracing::info;
@@ -152,9 +153,14 @@ pub fn get_unit_file_location(service: &UnitId) -> Result<String> {
152153
args.insert(0, "--user");
153154
}
154155

155-
match cmd("systemctl", args).read() {
156-
Ok(output) => Ok(output.trim().to_string()),
157-
Err(e) => anyhow::bail!("Failed to get unit file location: {}", e),
156+
let output = Command::new("systemctl").args(&args).output()?;
157+
158+
if output.status.success() {
159+
let path = String::from_utf8(output.stdout)?;
160+
Ok(path.trim().to_string())
161+
} else {
162+
let stderr = String::from_utf8(output.stderr)?;
163+
bail!(stderr);
158164
}
159165
}
160166

0 commit comments

Comments
 (0)