1
0
mirror of https://github.com/pcvolkmer/osc-variant.git synced 2025-04-19 11:46:50 +00:00

Package deb package containing bash completion

This commit is contained in:
Paul-Christian Volkmer 2023-09-04 17:46:55 +02:00
parent e27d31a8bf
commit b3054f971e
6 changed files with 79 additions and 10 deletions

1
.gitignore vendored
View File

@ -1,4 +1,5 @@
.idea/*
/target
/completion
*.iml

10
Cargo.lock generated
View File

@ -99,6 +99,15 @@ dependencies = [
"clap_lex",
]
[[package]]
name = "clap_complete"
version = "4.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "586a385f7ef2f8b4d86bddaa0c094794e7ccbfe5ffef1f434fe928143fc783a5"
dependencies = [
"clap",
]
[[package]]
name = "clap_derive"
version = "4.4.2"
@ -262,6 +271,7 @@ name = "osc-variant"
version = "0.4.0"
dependencies = [
"clap",
"clap_complete",
"console",
"quick-xml",
"serde",

View File

@ -7,6 +7,8 @@ description = "Anwendung zum Anpassen einer OSC-Datei an einen Standort"
license = "MIT"
readme = "README.md"
build = "build.rs"
[dependencies]
clap = { version = "4.4", features = ["std", "help", "usage", "derive", "error-context"], default-features = false }
serde = { version = "1.0", features = ["derive"] }
@ -15,6 +17,10 @@ quick-xml = { version = "0.30", features = ["escape-html", "serialize"], default
console = "0.15"
sha256 = "1.4"
[build-dependencies]
clap = { version = "4.4", features = ["std", "help", "usage", "derive", "error-context"], default-features = false }
clap_complete = "4.4"
[profile.release]
opt-level = "s"
codegen-units = 1
@ -24,3 +30,6 @@ panic = "abort"
[package.metadata.deb]
copyright = "Copyright (c) 2023 Comprehensive Cancer Center Mainfranken"
assets = [
["completion/osc-variant.bash", "etc/bash_completion.d/", "644"]
]

44
build.rs Normal file
View File

@ -0,0 +1,44 @@
/*
* MIT License
*
* Copyright (c) 2023 Comprehensive Cancer Center Mainfranken
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
use std::fs;
use std::io::Error;
use clap_complete::generate_to;
use clap_complete::Shell::Bash;
include!("src/cli.rs");
fn main() -> Result<(), Error> {
let mut cmd = build_cli();
let package_name = std::env::var("CARGO_CRATE_NAME").unwrap_or("osc-variant".to_string());
fs::remove_dir_all("completion")?;
fs::create_dir("completion")?;
generate_to(Bash, &mut cmd, package_name.as_str(), "completion")?;
Ok(())
}

View File

@ -22,18 +22,23 @@
* SOFTWARE.
*/
use clap::{Parser, Subcommand};
use clap::{Command, CommandFactory, Parser, Subcommand};
#[allow(dead_code)]
fn build_cli() -> Command {
Cli::command()
}
#[derive(Parser)]
#[command(author, version, about, long_about = None)]
#[command(propagate_version = true, arg_required_else_help(true))]
pub struct Cli {
#[command(subcommand)]
pub command: Command,
pub cmd: SubCommand,
}
#[derive(Subcommand)]
pub enum Command {
pub enum SubCommand {
#[command(
name = "sha256sum",
about = "Berechne SHA256 Prüfsumme für die angegebene Datei"

View File

@ -37,7 +37,7 @@ use quick_xml::se::Serializer;
use serde::Serialize;
use sha256::digest;
use crate::cli::{Cli, Command};
use crate::cli::{Cli, SubCommand};
use crate::model::onkostar_editor::OnkostarEditor;
use crate::profile::Profile;
@ -111,8 +111,8 @@ fn read_profile(filename: String) -> Result<Profile, FileError> {
fn main() -> Result<(), Box<dyn Error>> {
let cli = Cli::parse();
match cli.command {
Command::List {
match cli.cmd {
SubCommand::List {
inputfile,
sorted,
filter,
@ -127,7 +127,7 @@ fn main() -> Result<(), Box<dyn Error>> {
}
data.print_list();
}
Command::Tree {
SubCommand::Tree {
inputfile,
sorted,
filter,
@ -142,7 +142,7 @@ fn main() -> Result<(), Box<dyn Error>> {
}
OnkostarEditor::print_tree(&data);
}
Command::Modify {
SubCommand::Modify {
inputfile,
profile,
outputfile,
@ -193,7 +193,7 @@ fn main() -> Result<(), Box<dyn Error>> {
}
}
}
Command::Diff {
SubCommand::Diff {
inputfile_a,
inputfile_b,
strict,
@ -209,7 +209,7 @@ fn main() -> Result<(), Box<dyn Error>> {
data_a.print_diff(data_b, strict);
}
Command::Sha256Sum { inputfile } => {
SubCommand::Sha256Sum { inputfile } => {
match fs::read_to_string(inputfile.clone()) {
Ok(content) => {
println!(