Skip to content

Commit

Permalink
feat: Move manpages to main cli
Browse files Browse the repository at this point in the history
  • Loading branch information
Dustin Blackman committed Dec 31, 2023
1 parent 5c2359b commit f5aab04
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 34 deletions.
3 changes: 1 addition & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ description = "Terminal UI to chat with large language models (LLM) using differ
[features]
dev = []
dhat-heap = ["dep:dhat"]
manpages = ["dep:clap_mangen"]

[workspace]
members = ["tools/xtask"]
Expand All @@ -41,7 +40,7 @@ bincode = "=1.3.3"
chrono = { version = "=0.4.31", default-features = false, features = ["clock"] }
clap = { version = "=4.4.7", features = ["env", "string"] }
clap_complete = "=4.4.4"
clap_mangen = { version = "=0.2.15", optional = true }
clap_mangen = { version = "=0.2.15" }
crossterm = { version = "=0.27.0", features = ["bracketed-paste", "event-stream"] }
dashmap = "=5.5.3"
dhat = { version = "=0.3.2", optional = true }
Expand Down
31 changes: 5 additions & 26 deletions src/application/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,24 +82,6 @@ async fn print_sessions_list() -> Result<()> {
return Ok(());
}

async fn manpages() -> Result<()> {
#[cfg(feature = "manpages")]
{
let man = clap_mangen::Man::new(build());
let mut buffer: Vec<u8> = Default::default();
man.render(&mut buffer)?;

let mut file = fs::File::create("./manpages/oatmeal.1").await?;
file.write_all(&buffer).await?;

println!("Wrote manpages to ./manpages/oatmeal.1");

return Ok(());
}

bail!("Man pages feature not enabled.");
}

async fn create_config_file() -> Result<()> {
let config_file_path_str = Config::default(ConfigKey::ConfigFile);
let config_file_path = path::PathBuf::from(&config_file_path_str);
Expand Down Expand Up @@ -214,11 +196,6 @@ fn subcommand_debug() -> Command {
Command::new("enum-config").about("List all config keys as strings.")
);

#[cfg(feature = "manpages")]
{
cmd = cmd.subcommand(Command::new("manpages").about("Generates manpages"));
}

return cmd;
}

Expand Down Expand Up @@ -345,6 +322,7 @@ pub fn build() -> Command {
.subcommand(subcommand_completions())
.subcommand(subcommand_config())
.subcommand(subcommand_debug())
.subcommand(Command::new("manpages").about("Generates manpages and outputs to stdout."))
.subcommand(subcommand_sessions())
.arg(arg_backend())
.arg(arg_backend_health_check_timeout())
Expand Down Expand Up @@ -447,9 +425,6 @@ pub async fn parse() -> Result<bool> {
let res = ConfigKey::VARIANTS.join("\n");
println!("{}", res);
}
Some(("manpages", _)) => {
manpages().await?;
}
_ => {
subcommand_debug().print_long_help()?;
}
Expand Down Expand Up @@ -486,6 +461,10 @@ pub async fn parse() -> Result<bool> {
}
}
}
Some(("manpages", _)) => {
clap_mangen::Man::new(build()).render(&mut io::stdout())?;
return Ok(false);
}
Some(("sessions", subcmd_matches)) => {
match subcmd_matches.subcommand() {
Some(("dir", _)) => {
Expand Down
8 changes: 2 additions & 6 deletions tools/release.sh
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,9 @@ git commit -m "feat: Release v$OM_VERSION"
git tag -a "v$OM_VERSION" -m "v$OM_VERSION"

# Update readme, build completions, manpages.
cargo build --features manpages
cargo build
cargo cmd build-completions
rm -rf manpages
mkdir manpages
./target/debug/oatmeal debug manpages
cat manpages/oatmeal.1 | gzip -c -9 >manpages/oatmeal.1.gz
rm manpages/oatmeal.1
rm -rf manpages && mkdir manpages && ./target/debug/oatmeal manpages | gzip -c -9 >manpages/oatmeal.1.gz
cargo xtask update-readme
rm -f config.example.toml
./target/debug/oatmeal config default >config.example.toml
Expand Down

0 comments on commit f5aab04

Please sign in to comment.