1
0
mirror of https://github.com/pcvolkmer/osc-variant.git synced 2025-07-03 01:02:55 +00:00

feat: add command to generate completion (#33)

This commit is contained in:
2024-11-06 18:54:36 +01:00
committed by GitHub
parent 242d818f88
commit 1debbf25a4
6 changed files with 93 additions and 22 deletions

View File

@ -18,12 +18,8 @@
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
use clap::{Command, CommandFactory, Parser, Subcommand};
#[allow(dead_code)]
fn build_cli() -> Command {
Cli::command()
}
use clap::{Parser, Subcommand};
use clap_complete::Shell;
#[derive(Parser)]
#[command(author, version, about)]
@ -35,6 +31,12 @@ pub struct Cli {
#[derive(Subcommand)]
pub enum SubCommand {
#[command(
name = "completion",
about = "Erzeuge und gebe Command-Completion aus",
hide = true
)]
Completion { shell: Shell },
#[command(
name = "sha256sum",
about = "Berechne SHA256 Prüfsumme für die angegebene Datei"

View File

@ -18,6 +18,18 @@
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
use crate::checks::{check_file, print_checks, CheckNotice};
use crate::cli::{Cli, SubCommand};
use crate::file_io::{FileError, FileReader, InputFile};
use crate::model::onkostar_editor::OnkostarEditor;
use crate::profile::Profile;
use clap::CommandFactory;
use clap_complete::generate;
use console::style;
use dialoguer::Confirm;
use quick_xml::se::Serializer;
use serde::Serialize;
use sha256::digest;
use std::error::Error;
use std::fs;
use std::fs::OpenOptions;
@ -25,18 +37,6 @@ use std::io::Write;
use std::ops::Add;
use std::path::{Path, PathBuf};
use console::style;
use dialoguer::Confirm;
use quick_xml::se::Serializer;
use serde::Serialize;
use sha256::digest;
use crate::checks::{check_file, print_checks, CheckNotice};
use crate::cli::SubCommand;
use crate::file_io::{FileError, FileReader, InputFile};
use crate::model::onkostar_editor::OnkostarEditor;
use crate::profile::Profile;
fn write_outputfile(filename: String, content: &String) -> Result<(), FileError> {
OpenOptions::new()
.read(false)
@ -52,6 +52,15 @@ fn write_outputfile(filename: String, content: &String) -> Result<(), FileError>
pub fn handle(command: SubCommand) -> Result<(), Box<dyn Error>> {
match command {
SubCommand::Completion { shell } => {
let command = &mut Cli::command();
generate(
shell,
command,
command.get_name().to_string(),
&mut std::io::stdout(),
);
}
SubCommand::List {
inputfile,
sorted,