improvements

This commit is contained in:
crapStone 2022-07-16 01:01:48 +02:00
parent 114e567826
commit 3a8ebca75e
No known key found for this signature in database
GPG key ID: 4CAA9E39EEDEB1F0
4 changed files with 59 additions and 56 deletions

View file

@ -3,26 +3,38 @@
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.
use std::{path::PathBuf, io::Error};
use std::{
fs,
io::{self, Error},
path::PathBuf,
};
use clap_complete::{generate_to, shells, Generator};
include!("src/cli.rs");
const OUTDIR: &str = "completions";
fn main() -> Result<(), Error> {
let outdir = "completions";
let mut cmd = build_cli();
let path = generate_completions(shells::Bash, &mut cmd, outdir)?;
println!("cargo:debug=completion file is generated: {:?}", path);
let path = generate_completions(shells::Zsh, &mut cmd, outdir)?;
println!("cargo:debug=completion file is generated: {:?}", path);
let path = generate_completions(shells::Fish, &mut cmd, outdir)?;
println!("cargo:debug=completion file is generated: {:?}", path);
if let Err(why) = fs::create_dir(OUTDIR) {
if why.kind() != io::ErrorKind::AlreadyExists {
eprintln!("cargo:error=could not create directory: {OUTDIR}");
return Err(why);
}
}
let path = generate_completions(shells::Bash, &mut cmd)?;
println!("cargo:debug=completion file is generated: {path:?}");
let path = generate_completions(shells::Zsh, &mut cmd)?;
println!("cargo:debug=completion file is generated: {path:?}");
let path = generate_completions(shells::Fish, &mut cmd)?;
println!("cargo:debug=completion file is generated: {path:?}");
Ok(())
}
fn generate_completions<G: Generator>(shell: G, cmd: &mut clap::Command, outdir: &str) -> Result<PathBuf, Error> {
generate_to(shell, cmd, "lamp", outdir)
fn generate_completions<G: Generator>(shell: G, cmd: &mut clap::Command) -> Result<PathBuf, Error> {
generate_to(shell, cmd, env!("CARGO_PKG_NAME"), OUTDIR)
}