add xtasks to generate man page and autocomplete files (#22)

* add xtasks to generate manpage and autocomplete files

* add alias for main pkg

* git ingore assets/gen
This commit is contained in:
Jimmy 2022-09-04 21:13:56 +08:00 committed by GitHub
parent 584e4e8ae9
commit d2daa965eb
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
19 changed files with 130 additions and 29 deletions

3
.cargo/config Normal file
View file

@ -0,0 +1,3 @@
[alias]
xtask = "run --package xtask --"
main = "run --package clock-tui --"

1
.gitignore vendored
View file

@ -1 +1,2 @@
/target
/assets/gen

35
Cargo.lock generated
View file

@ -116,6 +116,15 @@ dependencies = [
"textwrap",
]
[[package]]
name = "clap_complete"
version = "3.2.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e4179da71abd56c26b54dd0c248cc081c1f43b0a1a7e8448e28e57a29baa993d"
dependencies = [
"clap",
]
[[package]]
name = "clap_derive"
version = "3.2.7"
@ -138,6 +147,16 @@ dependencies = [
"os_str_bytes",
]
[[package]]
name = "clap_mangen"
version = "0.1.11"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "105180c05a72388d5f5e4e4f6c79eecb92497bda749fa8f963a16647c5d5377f"
dependencies = [
"clap",
"roff",
]
[[package]]
name = "clock-tui"
version = "0.4.0"
@ -478,6 +497,12 @@ version = "0.6.27"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a3f87b73ce11b1619a3c6332f45341e0047173771e8b8b73f87bfeefb7b56244"
[[package]]
name = "roff"
version = "0.2.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b833d8d034ea094b1ea68aa6d5c740e0d04bad9d16568d08ba6f76823a114316"
[[package]]
name = "scopeguard"
version = "1.1.0"
@ -760,3 +785,13 @@ name = "windows_x86_64_msvc"
version = "0.36.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c811ca4a8c853ef420abd8592ba53ddbbac90410fab6903b3e79972a631f7680"
[[package]]
name = "xtask"
version = "0.1.0"
dependencies = [
"clap",
"clap_complete",
"clap_mangen",
"clock-tui",
]

View file

@ -1,29 +1,5 @@
[package]
name = "clock-tui"
version = "0.4.0"
edition = "2021"
license = "MIT"
description = "A clock app in terminal"
homepage = "https://github.com/race604/clock-tui"
repository = "https://github.com/race604/clock-tui"
readme = "README.md"
authors = ["Race604 <race604@gmail.com>"]
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
tui = "0.18.0"
crossterm = "0.24"
chrono = "0.4"
clap = { version = "3.2.12", features = ["derive"] }
regex = "1.6.0"
chrono-tz = { version = "0.6.3", features = ["serde"] }
[lib]
name = "clock_tui"
path = "src/lib.rs"
[[bin]]
name = "tclock"
path = "src/bin/main.rs"
bench = false
[workspace]
members = [
"clock-tui",
"xtask",
]

1
clock-tui/.gitignore vendored Normal file
View file

@ -0,0 +1 @@
/target

29
clock-tui/Cargo.toml Normal file
View file

@ -0,0 +1,29 @@
[package]
name = "clock-tui"
version = "0.4.0"
edition = "2021"
license = "MIT"
description = "A clock app in terminal"
homepage = "https://github.com/race604/clock-tui"
repository = "https://github.com/race604/clock-tui"
readme = "README.md"
authors = ["Race604 <race604@gmail.com>"]
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
tui = "0.18.0"
crossterm = "0.24"
chrono = "0.4"
clap = { version = "3.2.12", features = ["derive"] }
regex = "1.6.0"
chrono-tz = { version = "0.6.3", features = ["serde"] }
[lib]
name = "clock_tui"
path = "src/lib.rs"
[[bin]]
name = "tclock"
path = "src/bin/main.rs"
bench = false

12
xtask/Cargo.toml Normal file
View file

@ -0,0 +1,12 @@
[package]
name = "xtask"
version = "0.1.0"
edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
clap = { version = "3.2.12", features = ["derive"] }
clap_mangen = "0.1"
clap_complete = "3.2.4"
clock-tui = { path = "../clock-tui" }

44
xtask/src/main.rs Normal file
View file

@ -0,0 +1,44 @@
use clap::{IntoApp, ArgEnum};
use clap_complete::{Shell, generate_to};
use clap_mangen::Man;
use clock_tui::app::App;
use std::fs::File;
use std::io::Result;
use std::path::{PathBuf, Path};
use std::{env, fs};
const BIN_NAME: &str = "tclock";
fn build_shell_completion(outdir: &Path) -> Result<()> {
let mut app = App::into_app();
let shells = Shell::value_variants();
for shell in shells {
generate_to(*shell, &mut app, BIN_NAME, &outdir)?;
}
Ok(())
}
fn build_manpages(outdir: &Path) -> Result<()> {
let app = App::into_app();
let file = Path::new(&outdir).join(format!("{}.1", BIN_NAME));
let mut file = File::create(&file)?;
Man::new(app).render(&mut file)?;
Ok(())
}
fn main() -> Result<()> {
let out_dir = env!("CARGO_MANIFEST_DIR");
let out_path = PathBuf::from(out_dir).join("../assets/gen");
fs::create_dir_all(&out_path).unwrap();
build_shell_completion(&out_path)?;
build_manpages(&out_path)?;
Ok(())
}