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:
14
src/cli.rs
14
src/cli.rs
@ -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"
|
||||
|
@ -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,
|
||||
|
Reference in New Issue
Block a user