1
0
Fork 0
mirror of https://codeberg.org/icewind/haze.git synced 2026-06-03 17:14:08 +02:00

edit command

This commit is contained in:
Robin Appelman 2025-09-03 18:37:33 +02:00
commit 43481a5960
5 changed files with 70 additions and 9 deletions

View file

@ -16,7 +16,7 @@ use crate::service::{RedisTls, Service};
use bollard::Docker;
use itertools::Itertools;
use miette::{IntoDiagnostic, Report, Result, WrapErr};
use std::env::vars;
use std::env::{var, vars};
use std::fs::{create_dir_all, write};
use std::io::stdout;
use std::os::unix::process::CommandExt;
@ -452,6 +452,17 @@ async fn main() -> Result<ExitCode> {
HazeArgs::Help { command } => {
help(command);
}
HazeArgs::Edit { filter, path } => {
let cloud = Cloud::get_by_filter(&docker, filter, &config).await?;
let path = cloud
.get_local_path(&config, &path)
.ok_or_else(|| Report::msg(format!("{path} not found on the instance")))?;
let editor = var("EDITOR").map_err(|_| Report::msg("$EDITOR not set"))?;
let err = Command::new(editor).arg(path).exec(); // this never exists without error
return Err(err)
.into_diagnostic()
.wrap_err("Failed to start $EDITOR");
}
};
Ok(ExitCode::SUCCESS)