Skip to content

Commit 946f7d2

Browse files
committed
feat(cli): change manpage calling method
1 parent 4ccab0d commit 946f7d2

File tree

3 files changed

+11
-19
lines changed

3 files changed

+11
-19
lines changed

Cargo.lock

Lines changed: 0 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,4 +102,3 @@ pretty_assertions.workspace = true
102102

103103
[target.'cfg(unix)'.dependencies]
104104
rustix = { version = "1.0.2", features = ["system", "fs"] }
105-
tempfile = "3.20.0"

src/cli.rs

Lines changed: 11 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use globwalk::FileType;
77
use odoo_lsp::config::{CompletionsConfig, Config, ModuleConfig, ReferencesConfig, SymbolsConfig};
88
use odoo_lsp::index::{_R, Index};
99
use odoo_lsp::utils::strict_canonicalize;
10-
use odoo_lsp::{GIT_VERSION, GITVER, NAME, VERSION, errloc, format_loc, loc};
10+
use odoo_lsp::{GIT_VERSION, GITVER, NAME, VERSION, errloc, format_loc, loc, ok};
1111
use self_update::{Status, backends::github};
1212
use serde_json::Value;
1313
use tracing::{debug, warn};
@@ -122,25 +122,19 @@ pub fn parse_args<'r>(mut args: &[&'r str]) -> Args<'r> {
122122
}
123123

124124
fn print_usage() -> anyhow::Result<()> {
125-
#[cfg(unix)]
126-
if let Ok(stat) = std::process::Command::new("man")
127-
.arg("-h")
128-
.stdout(std::process::Stdio::null())
129-
.stderr(std::process::Stdio::null())
130-
.status()
131-
&& stat.success()
125+
use std::io::Write;
126+
use std::process::{Command, Stdio};
127+
128+
const MANPAGE: &str = include_str!("../contrib/debian/usr/share/man/man1/odoo-lsp.1");
129+
130+
let mut man = Command::new("man").args(["-l", "-"]).stdin(Stdio::piped()).spawn()?;
132131
{
133-
use std::io::Write;
134-
const MANPAGE: &str = include_str!("../contrib/debian/usr/share/man/man1/odoo-lsp.1");
135-
136-
let manpage = tempfile::NamedTempFile::new()?;
137-
let mut file = std::fs::File::options().write(true).open(manpage.path())?;
138-
file.write_all(MANPAGE.as_bytes())?;
139-
std::process::Command::new("man").arg(manpage.path()).status()?;
140-
return Ok(());
132+
let mut stdin = ok!(man.stdin.take(), "failed to open man stdin");
133+
stdin.write_all(MANPAGE.as_bytes())?;
141134
}
135+
man.wait()?;
142136

143-
Err(anyhow::anyhow!("no manpage support"))
137+
Ok(())
144138
}
145139

146140
/// Returns true if a CLI handler has been invoked.

0 commit comments

Comments
 (0)